2019-05-09 21:33:52 +02:00
|
|
|
const { Listener } = require('discord-akairo');
|
2019-11-27 12:16:30 +01:00
|
|
|
const joinChannel = require('../../models').joinChannel;
|
2019-05-09 21:33:52 +02:00
|
|
|
const rand = require('../../rand.js');
|
|
|
|
|
|
|
|
class guildMemberAddListener extends Listener {
|
|
|
|
constructor() {
|
|
|
|
super('guildMemberAdd', {
|
|
|
|
emitter: 'client',
|
|
|
|
event: 'guildMemberAdd'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:59:23 +01:00
|
|
|
async exec(member) {
|
|
|
|
if (member.guild.id == 240843640375607296) {
|
|
|
|
member.setNickname('fart piss');
|
2019-10-05 19:39:08 +02:00
|
|
|
}
|
|
|
|
|
2019-12-26 17:27:51 +01:00
|
|
|
|
2020-03-07 17:59:23 +01:00
|
|
|
const join = await joinChannel.findOne({where: {guildID: member.guild.id}});
|
2019-06-28 17:05:01 +02:00
|
|
|
|
2019-11-27 12:16:30 +01:00
|
|
|
if (join) {
|
2020-03-04 02:08:04 +01:00
|
|
|
const channel = this.client.channels.resolve(join.get('channelID'));
|
2019-11-27 12:16:30 +01:00
|
|
|
|
|
|
|
let welcomeMessage = join.get('message');
|
2019-06-28 17:05:01 +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:23 +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;
|
|
|
|
}
|
|
|
|
|
2020-03-07 17:59:23 +01:00
|
|
|
welcomeMessage = welcomeMessage.replace(/\[member\]/g, username);
|
|
|
|
welcomeMessage = welcomeMessage.replace(/\[memberPing\]/g, user);
|
|
|
|
welcomeMessage = welcomeMessage.replace(/\[server\]/g, member.guild.name);
|
|
|
|
|
|
|
|
// add attachment
|
2019-06-28 17:05:01 +02:00
|
|
|
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:.*?])/, '');
|
|
|
|
}
|
2020-03-07 17:59:23 +01:00
|
|
|
|
|
|
|
// Give a role
|
|
|
|
let role;
|
|
|
|
if (welcomeMessage.includes('[role:')) {
|
|
|
|
role = welcomeMessage.split(/(\[role:.*?])/);
|
|
|
|
for (let i = 0, l = role.length; i < l; i++) {
|
|
|
|
if (role[i].includes('[role:')) {
|
|
|
|
role = role[i].replace('[role:', '').slice(0, -1);
|
|
|
|
i = role.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const rank = member.guild.roles.cache.find(rank => rank.name === role);
|
|
|
|
member.roles.add(rank);
|
|
|
|
|
|
|
|
welcomeMessage = welcomeMessage.replace(/(\[role:.*?])/, '');
|
|
|
|
}
|
2019-06-28 17:05:01 +02:00
|
|
|
|
|
|
|
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;
|