Haha-Yes/event/listeners/guildMemberRemove.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

const { Listener } = require('discord-akairo');
2019-06-28 17:05:01 +02:00
const fs = require('fs');
const rand = require('../../rand.js');
class guildMemberRemoveListener extends Listener {
constructor() {
super('guildMemberRemove', {
emitter: 'client',
event: 'guildMemberRemove'
});
}
async exec(guild) {
2019-06-28 17:05:01 +02:00
if (fs.existsSync(`./bye/${guild.guild.id}.json`)) {
let bye = require(`../../bye/${guild.guild.id}.json`);
2019-06-28 17:05:01 +02:00
const channel = this.client.channels.get(bye['channel']);
2019-06-28 17:05:01 +02:00
let byeMessage = bye['message'];
2019-06-28 17:05:01 +02:00
byeMessage = byeMessage.replace(/\[member\]/, guild.user.username);
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;