Haha-Yes/event/listeners/guildMemberAdd.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-05-09 21:33:52 +02:00
const { Listener } = require('discord-akairo');
2019-06-28 17:05:01 +02:00
const fs = require('fs');
2019-05-09 21:33:52 +02:00
const rand = require('../../rand.js');
class guildMemberAddListener extends Listener {
constructor() {
super('guildMemberAdd', {
emitter: 'client',
event: 'guildMemberAdd'
});
}
async exec(guild) {
2019-10-05 19:39:08 +02:00
if (guild.guild.id == 240843640375607296) {
guild.setNickname('fart piss');
}
2019-06-28 17:05:01 +02:00
if (fs.existsSync(`./welcome/${guild.guild.id}.json`)) {
let welcome = require(`../../welcome/${guild.guild.id}.json`);
const channel = this.client.channels.get(welcome['channel']);
let welcomeMessage = welcome['message'];
welcomeMessage = welcomeMessage.replace(/\[member\]/, guild.user.username);
welcomeMessage = welcomeMessage.replace(/\[server\]/, guild.guild.name);
let attach;
if (welcomeMessage.includes('[attach:')) {
attach = welcomeMessage.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-09 21:33:52 +02:00
}
2019-06-28 17:05:01 +02:00
welcomeMessage = welcomeMessage.replace(/(\[attach:.*?])/, '');
}
welcomeMessage = rand.random(welcomeMessage);
if (attach) {
return channel.send(welcomeMessage, {files: [attach]});
} else {
return channel.send(welcomeMessage);
2019-05-09 21:33:52 +02:00
}
}
}
}
module.exports = guildMemberAddListener;