From 34c3e0b1e150beb131ea18a3a4eff8933a3cff86 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 11 Aug 2019 19:54:41 +0200 Subject: [PATCH] Fake leave message --- commands/fun/fakeleave.js | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 commands/fun/fakeleave.js diff --git a/commands/fun/fakeleave.js b/commands/fun/fakeleave.js new file mode 100644 index 0000000..4254573 --- /dev/null +++ b/commands/fun/fakeleave.js @@ -0,0 +1,70 @@ +const { Command } = require('discord-akairo'); +const fs = require('fs'); +const rand = require('../../rand.js'); + +class fakeleaveCommand extends Command { + constructor() { + super('fakeleave', { + aliases: ['fakeleave'], + category: 'admin', + channelRestriction: 'guild', + args: [ + { + id: 'member', + type: 'member', + match: 'rest' + } + ], + description: { + content: 'Fake leave message', + usage: '[user]', + examples: ['Supositware'] + } + }); + } + + async exec(message, args) { + if (fs.existsSync(`./bye/${message.guild.id}.json`)) { + let member; + if (args.member) { + member = args.member; + } else { + member = message.author; + } + + let bye = require(`../../bye/${message.guild.id}.json`); + + const channel = this.client.channels.get(bye['channel']); + + let byeMessage = bye['message']; + + byeMessage = byeMessage.replace(/\[member\]/, member); + byeMessage = byeMessage.replace(/\[server\]/, message.guild.name); + + let attach; + if (byeMessage.includes('[attach:')) { + attach = byeMessage.split(/(\[attach:.*?])/); + for (let i = 0, l = attach.length; i < l; i++) { + if (attach[i].includes('[attach:')) { + attach = attach[i].replace('[attach:', '').slice(0, -1); + i = attach.length; + } + } + byeMessage = byeMessage.replace(/(\[attach:.*?])/, ''); + } + + byeMessage = rand.random(byeMessage); + + + if (attach) { + return channel.send(byeMessage, {files: [attach]}); + } else { + return channel.send(byeMessage); + } + } else { + return message.channel.send('The server need a leave message first!'); + } + } +} + +module.exports = fakeleaveCommand; \ No newline at end of file