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'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:59:09 +01:00
|
|
|
async exec(member) {
|
|
|
|
const leave = await leaveChannel.findOne({where: {guildID: member.guild.id}});
|
2019-11-27 12:16:30 +01:00
|
|
|
if (leave) {
|
2020-03-04 02:08:04 +01:00
|
|
|
const channel = this.client.channels.resolve(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-12-26 17:27:51 +01:00
|
|
|
let invite = new RegExp(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g);
|
|
|
|
|
2020-03-07 17:59:09 +01:00
|
|
|
let username = member.user.username;
|
|
|
|
let user = member.user;
|
2019-12-26 17:29:22 +01:00
|
|
|
if (username.match(invite)) {
|
2019-12-26 17:27:51 +01:00
|
|
|
username = username.replace(/(https?:\/\/)?(www\.)?discord(?:app\.com|\.gg)[/invite/]?(?:(?!.*[Ii10OolL]).[a-zA-Z0-9]{5,6}|[a-zA-Z0-9-]{2,32})/g, '[REDACTED]');
|
|
|
|
user = username;
|
|
|
|
}
|
|
|
|
|
|
|
|
byeMessage = byeMessage.replace(/\[member\]/, username);
|
|
|
|
byeMessage = byeMessage.replace(/\[memberPing\]/, user);
|
2020-03-07 17:59:09 +01:00
|
|
|
byeMessage = byeMessage.replace(/\[server\]/, member.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;
|