2019-05-10 16:36:17 +02:00
|
|
|
const { Listener } = require('discord-akairo');
|
2019-11-27 12:16:30 +01:00
|
|
|
const leaveChannel = require('../../models').leaveChannel;
|
2019-05-10 16:36:17 +02:00
|
|
|
const rand = require('../../rand.js');
|
|
|
|
|
|
|
|
class guildMemberRemoveListener extends Listener {
|
|
|
|
constructor() {
|
|
|
|
super('guildMemberRemove', {
|
|
|
|
emitter: 'client',
|
|
|
|
event: 'guildMemberRemove'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async exec(guild) {
|
2019-12-06 16:54:37 +01:00
|
|
|
const leave = await leaveChannel.findOne({where: {guildID: guild.guild.id}});
|
2019-11-27 12:16:30 +01:00
|
|
|
if (leave) {
|
|
|
|
const channel = this.client.channels.get(leave.get('channelID'));
|
2019-05-10 16:36:17 +02:00
|
|
|
|
2019-11-27 12:16:30 +01:00
|
|
|
let byeMessage = leave.get('message');
|
2019-05-10 16:36:17 +02:00
|
|
|
|
2019-06-28 17:05:01 +02:00
|
|
|
byeMessage = byeMessage.replace(/\[member\]/, guild.user.username);
|
|
|
|
byeMessage = byeMessage.replace(/\[server\]/, guild.guild.name);
|
2019-05-10 16:36:17 +02:00
|
|
|
|
2019-06-28 17:05:01 +02:00
|
|
|
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;
|
|
|
|
}
|
2019-05-10 16:36:17 +02:00
|
|
|
}
|
2019-06-28 17:05:01 +02:00
|
|
|
byeMessage = byeMessage.replace(/(\[attach:.*?])/, '');
|
2019-05-10 16:36:17 +02:00
|
|
|
}
|
|
|
|
|
2019-06-28 17:05:01 +02:00
|
|
|
byeMessage = rand.random(byeMessage);
|
2019-05-10 16:36:17 +02:00
|
|
|
|
|
|
|
|
2019-06-28 17:05:01 +02:00
|
|
|
if (attach) {
|
|
|
|
return channel.send(byeMessage, {files: [attach]});
|
|
|
|
} else {
|
|
|
|
return channel.send(byeMessage);
|
|
|
|
}
|
2019-05-10 16:36:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = guildMemberRemoveListener;
|