From ff0762916881f9dfbdc395278f087a0e2635cb59 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Mon, 12 Aug 2019 08:48:14 +0200 Subject: [PATCH] Fakejoin command --- commands/fun/fakejoin.js | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 commands/fun/fakejoin.js diff --git a/commands/fun/fakejoin.js b/commands/fun/fakejoin.js new file mode 100644 index 0000000..f2b0367 --- /dev/null +++ b/commands/fun/fakejoin.js @@ -0,0 +1,70 @@ +const { Command } = require('discord-akairo'); +const fs = require('fs'); +const rand = require('../../rand.js'); + +class fakejoinCommand extends Command { + constructor() { + super('fakejoin', { + aliases: ['fakejoin'], + category: 'admin', + channelRestriction: 'guild', + args: [ + { + id: 'member', + type: 'string', + match: 'rest' + } + ], + description: { + content: 'Fake join message', + usage: '[text]', + examples: ['Supositware'] + } + }); + } + + async exec(message, args) { + if (fs.existsSync(`./welcome/${message.guild.id}.json`)) { + let member; + if (args.member) { + member = args.member; + } else { + member = message.author.username; + } + + let welcome = require(`../../welcome/${message.guild.id}.json`); + + const channel = this.client.channels.get(welcome['channel']); + + let byeMessage = welcome['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); + + message.delete(); + if (attach) { + return channel.send(byeMessage, {files: [attach]}); + } else { + return channel.send(byeMessage); + } + } else { + return message.channel.send('The server need a join message first!'); + } + } +} + +module.exports = fakejoinCommand; \ No newline at end of file