From 132a6a0a7c1d59ef62517ecd60101d390717909e Mon Sep 17 00:00:00 2001 From: loicbersier Date: Mon, 12 Aug 2019 13:47:15 +0200 Subject: [PATCH] fakebot/user --- commands/fun/fakebot.js | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 commands/fun/fakebot.js diff --git a/commands/fun/fakebot.js b/commands/fun/fakebot.js new file mode 100644 index 00000000..bca2df94 --- /dev/null +++ b/commands/fun/fakebot.js @@ -0,0 +1,63 @@ +const { Command } = require('discord-akairo'); +const fs = require('fs'); + +class fakebotCommand extends Command { + constructor() { + super('fakebot', { + aliases: ['fakebot', 'fakeuser', 'fakemember'], + category: 'fun', + clientPermissions: ['MANAGE_WEBHOOKS'], + args: [ + { + id: 'member', + type: 'user', + prompt: { + start: 'Who should i fake?', + } + }, + { + id: 'message', + type: 'string', + prompt: { + start: 'What message shoudl i send?', + }, + match: 'rest', + } + ], + description: { + content: 'Fake a bot/user with webhook', + usage: '', + examples: [''] + } + }); + } + + async exec(message, args) { + if (!fs.existsSync(`./webhook/${message.guild.id}.json`)) { + message.channel.createWebhook('fakebot') + .then(webhook => { + fs.writeFile(`./webhook/${message.guild.id}.json`, `{"id": "${webhook.id}", "token": "${webhook.token}"}`, function (err) { + if (err) { + console.log(err); + } + sendWebhook(this.client); + }); + }); + } else { + sendWebhook(this.client); + } + + function sendWebhook(client) { + let webhook = require(`../../webhook/${message.guild.id}.json`); + client.fetchWebhook(webhook.id, webhook.token) + .then(webhook => { + webhook.edit({ + name: args.member.username, + avatar: args.member.displayAvatarURL() + }); + return webhook.send(args.message); + }); + } + } +} +module.exports = fakebotCommand; \ No newline at end of file