Haha-Yes/event/listeners/guildMemberRemove.js

56 lines
1.7 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.resolve(leave.get('channelID'));
2019-11-27 12:16:30 +01:00
let byeMessage = leave.get('message');
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);
let username = guild.user.username;
let user = guild.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);
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;