From 325687a244483b380bc6548e9b1444d630401cae Mon Sep 17 00:00:00 2001 From: loicbersier Date: Mon, 16 Dec 2019 17:34:57 +0100 Subject: [PATCH] use emit to trigger add/remove event --- commands/fun/fakejoin.js | 45 ++++++++------------------------------- commands/fun/fakeleave.js | 41 ++++++----------------------------- 2 files changed, 16 insertions(+), 70 deletions(-) diff --git a/commands/fun/fakejoin.js b/commands/fun/fakejoin.js index 8ef07188..4f8d7ddd 100644 --- a/commands/fun/fakejoin.js +++ b/commands/fun/fakejoin.js @@ -1,6 +1,4 @@ const { Command } = require('discord-akairo'); -const joinChannel = require('../../models').joinChannel; -const rand = require('../../rand.js'); class fakejoinCommand extends Command { constructor() { @@ -11,8 +9,8 @@ class fakejoinCommand extends Command { clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'], args: [ { - id: 'member', - type: 'string', + id: 'user', + type: 'user', match: 'rest' } ], @@ -25,39 +23,14 @@ class fakejoinCommand extends Command { } async exec(message, args) { - const join = await joinChannel.findOne({where: {guildID: message.guild.id}}); + let member; + + if (args.user) + member = message.guild.members.get(args.user.id); + else + member = message.guild.members.get(message.author.id); - if (join) { - const channel = this.client.channels.get(join.get('channelID')); - - let welcomeMessage = join.get('message'); - - welcomeMessage = welcomeMessage.replace(/\[member\]/, args.member); - welcomeMessage = welcomeMessage.replace(/\[server\]/, message.guild.name); - - let attach; - if (welcomeMessage.includes('[attach:')) { - attach = welcomeMessage.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; - } - } - welcomeMessage = welcomeMessage.replace(/(\[attach:.*?])/, ''); - } - - welcomeMessage = rand.random(welcomeMessage); - - message.delete(); - if (attach) { - return channel.send(welcomeMessage, {files: [attach]}); - } else { - return channel.send(welcomeMessage); - } - } else { - return message.channel.send('Are you sure this server have a join message?'); - } + this.client.emit('guildMemberAdd', member); } } diff --git a/commands/fun/fakeleave.js b/commands/fun/fakeleave.js index 81654db3..a5973635 100644 --- a/commands/fun/fakeleave.js +++ b/commands/fun/fakeleave.js @@ -1,6 +1,4 @@ const { Command } = require('discord-akairo'); -const leaveChannel = require('../../models').leaveChannel; -const rand = require('../../rand.js'); class fakeleaveCommand extends Command { constructor() { @@ -11,7 +9,7 @@ class fakeleaveCommand extends Command { clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'], args: [ { - id: 'member', + id: 'user', type: 'user', match: 'rest' } @@ -25,38 +23,13 @@ class fakeleaveCommand extends Command { } async exec(message, args) { - const leave = await leaveChannel.findOne({where: {guildID: message.guild.id}}); - if (leave) { - const channel = this.client.channels.get(leave.get('channelID')); + let member; + if (args.user) + member = message.guild.members.get(args.user.id); + else + member = message.guild.members.get(message.author.id); - let byeMessage = leave.get('message'); - - byeMessage = byeMessage.replace(/\[member\]/, args.member.username); - 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('Are you sure this server have a leave message?'); - } + this.client.emit('guildMemberRemove', member); } }