forked from Supositware/Haha-Yes
use emit to trigger add/remove event
This commit is contained in:
parent
915bf38c07
commit
325687a244
2 changed files with 16 additions and 70 deletions
|
@ -1,6 +1,4 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const joinChannel = require('../../models').joinChannel;
|
||||
const rand = require('../../rand.js');
|
||||
|
||||
class fakejoinCommand extends Command {
|
||||
constructor() {
|
||||
|
@ -11,8 +9,8 @@ class fakejoinCommand extends Command {
|
|||
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
id: 'member',
|
||||
type: 'string',
|
||||
id: 'user',
|
||||
type: 'user',
|
||||
match: 'rest'
|
||||
}
|
||||
],
|
||||
|
@ -25,39 +23,14 @@ class fakejoinCommand extends Command {
|
|||
}
|
||||
|
||||
async exec(message, args) {
|
||||
const join = await joinChannel.findOne({where: {guildID: message.guild.id}});
|
||||
let member;
|
||||
|
||||
if (args.user)
|
||||
member = message.guild.members.get(args.user.id);
|
||||
else
|
||||
member = message.guild.members.get(message.author.id);
|
||||
|
||||
if (join) {
|
||||
const channel = this.client.channels.get(join.get('channelID'));
|
||||
|
||||
let welcomeMessage = join.get('message');
|
||||
|
||||
welcomeMessage = welcomeMessage.replace(/\[member\]/, args.member);
|
||||
welcomeMessage = welcomeMessage.replace(/\[server\]/, message.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;
|
||||
}
|
||||
}
|
||||
welcomeMessage = welcomeMessage.replace(/(\[attach:.*?])/, '');
|
||||
}
|
||||
|
||||
welcomeMessage = rand.random(welcomeMessage);
|
||||
|
||||
message.delete();
|
||||
if (attach) {
|
||||
return channel.send(welcomeMessage, {files: [attach]});
|
||||
} else {
|
||||
return channel.send(welcomeMessage);
|
||||
}
|
||||
} else {
|
||||
return message.channel.send('Are you sure this server have a join message?');
|
||||
}
|
||||
this.client.emit('guildMemberAdd', member);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const leaveChannel = require('../../models').leaveChannel;
|
||||
const rand = require('../../rand.js');
|
||||
|
||||
class fakeleaveCommand extends Command {
|
||||
constructor() {
|
||||
|
@ -11,7 +9,7 @@ class fakeleaveCommand extends Command {
|
|||
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
id: 'member',
|
||||
id: 'user',
|
||||
type: 'user',
|
||||
match: 'rest'
|
||||
}
|
||||
|
@ -25,38 +23,13 @@ class fakeleaveCommand extends Command {
|
|||
}
|
||||
|
||||
async exec(message, args) {
|
||||
const leave = await leaveChannel.findOne({where: {guildID: message.guild.id}});
|
||||
if (leave) {
|
||||
const channel = this.client.channels.get(leave.get('channelID'));
|
||||
let member;
|
||||
if (args.user)
|
||||
member = message.guild.members.get(args.user.id);
|
||||
else
|
||||
member = message.guild.members.get(message.author.id);
|
||||
|
||||
let byeMessage = leave.get('message');
|
||||
|
||||
byeMessage = byeMessage.replace(/\[member\]/, args.member.username);
|
||||
byeMessage = byeMessage.replace(/\[server\]/, message.guild.name);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
byeMessage = byeMessage.replace(/(\[attach:.*?])/, '');
|
||||
}
|
||||
|
||||
byeMessage = rand.random(byeMessage);
|
||||
|
||||
message.delete();
|
||||
if (attach) {
|
||||
return channel.send(byeMessage, {files: [attach]});
|
||||
} else {
|
||||
return channel.send(byeMessage);
|
||||
}
|
||||
} else {
|
||||
return message.channel.send('Are you sure this server have a leave message?');
|
||||
}
|
||||
this.client.emit('guildMemberRemove', member);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue