Haha-Yes/event/listeners/guildMemberRemove.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

const { Listener } = require('discord-akairo');
2019-11-27 12:16:30 +01:00
const leaveChannel = require('../../models').leaveChannel;
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-11-27 12:16:30 +01:00
let byeMessage = leave.get('message');
2019-06-28 17:05:01 +02:00
byeMessage = byeMessage.replace(/\[member\]/, guild.user.username);
2019-12-16 16:36:50 +01:00
byeMessage = byeMessage.replace(/\[memberPing\]/, guild.user);
2019-06-28 17:05:01 +02:00
byeMessage = byeMessage.replace(/\[server\]/, guild.guild.name);
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-06-28 17:05:01 +02:00
byeMessage = byeMessage.replace(/(\[attach:.*?])/, '');
}
2019-06-28 17:05:01 +02:00
byeMessage = rand.random(byeMessage);
2019-06-28 17:05:01 +02:00
if (attach) {
return channel.send(byeMessage, {files: [attach]});
} else {
return channel.send(byeMessage);
}
}
}
}
module.exports = guildMemberRemoveListener;