Haha-Yes/commands/fun/fakebot.js

80 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-08-12 13:47:15 +02:00
const { Command } = require('discord-akairo');
class fakebotCommand extends Command {
constructor() {
super('fakebot', {
aliases: ['fakebot', 'fakeuser', 'fakemember'],
category: 'fun',
clientPermissions: ['MANAGE_WEBHOOKS'],
args: [
{
2019-11-29 21:50:22 +01:00
id: 'user',
2019-08-12 13:47:15 +02:00
type: 'user',
prompt: {
start: 'Who should i fake?',
2019-08-13 23:31:35 +02:00
retry: 'Didn\'t find any user named like that, please say the name again.'
2019-08-12 13:47:15 +02:00
}
},
{
id: 'message',
type: 'string',
prompt: {
2019-08-12 14:18:45 +02:00
start: 'What message should i send?',
2019-08-12 13:47:15 +02:00
},
match: 'rest',
}
],
description: {
content: 'Fake a bot/user with webhook',
2019-08-12 18:41:15 +02:00
usage: '[user] [message]',
examples: ['Supositware#1616 hello!']
2019-08-12 13:47:15 +02:00
}
});
}
async exec(message, args) {
2019-11-01 02:37:27 +01:00
let Attachment = (message.attachments).array();
let url;
2019-11-29 21:50:22 +01:00
let username = args.user.username;
let member = message.guild.members.resolve(args.user.id);
2019-11-01 02:37:27 +01:00
// Get attachment link
if (Attachment[0]) {
url = Attachment[0].url;
}
2019-11-29 21:50:22 +01:00
// Show nickname if user is in guild
2019-11-29 22:04:26 +01:00
if (member) {
if (member.nickname) {
username = member.nickname;
}
2019-11-29 21:50:22 +01:00
}
2019-11-01 02:37:27 +01:00
2019-11-29 21:50:22 +01:00
message.channel.createWebhook(username, {
avatar: args.user.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${message.author.username}`
})
2019-08-12 18:07:03 +02:00
.then(webhook => {
2019-08-12 18:46:33 +02:00
// Have to edit after creation otherwise the picture doesn't get applied
2019-08-12 18:07:03 +02:00
webhook.edit({
2019-11-29 21:50:22 +01:00
name: username,
avatar: args.user.displayAvatarURL(),
reason: `Fakebot/user command triggered by: ${message.author.username}`
2019-08-12 13:47:15 +02:00
});
2019-08-12 18:07:03 +02:00
this.client.fetchWebhook(webhook.id, webhook.token)
.then(webhook => {
message.delete();
2019-11-01 02:37:27 +01:00
if (url)
webhook.send(args.message, {files: [url]});
else
webhook.send(args.message);
2019-08-12 18:07:03 +02:00
setTimeout(() => {
2019-11-29 21:50:22 +01:00
webhook.delete({
reason: `Fakebot/user command triggered by: ${message.author.username}`
});
2019-08-12 18:07:03 +02:00
}, 3000);
2019-08-12 14:05:39 +02:00
});
2019-08-12 18:07:03 +02:00
});
2019-08-12 13:47:15 +02:00
}
}
module.exports = fakebotCommand;