forked from Supositware/Haha-Yes
Same as welcome but for people who leave
This commit is contained in:
parent
1be8d203dd
commit
d789318590
3 changed files with 115 additions and 0 deletions
39
commands/admin/bye.js
Normal file
39
commands/admin/bye.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const fs = require('fs');
|
||||
|
||||
class byeCommand extends Command {
|
||||
constructor() {
|
||||
super('bye', {
|
||||
aliases: ['bye'],
|
||||
category: 'admin',
|
||||
channelRestriction: 'guild',
|
||||
userPermissions: ['MANAGE_CHANNELS'],
|
||||
args: [
|
||||
{
|
||||
id: 'message',
|
||||
type: 'string',
|
||||
match: 'rest'
|
||||
}
|
||||
],
|
||||
description: {
|
||||
content: 'Set bye message when user leave/get kicked, can use [member] to get the name of the user joining and [server] to get the name of the server',
|
||||
usage: '[bye message]',
|
||||
examples: ['everyone bye [adjectives] [member] and bye on [server]']
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async exec(message, args) {
|
||||
let byeChannel = message.channel.id;
|
||||
|
||||
fs.writeFile(`./bye/${message.guild.id}.json`, `{"channel": "${byeChannel}", "message": "${args.message}"}`, function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
|
||||
return message.channel.send(`This channel will now be used to send message when user leave with the following message: ${args.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = byeCommand;
|
31
commands/admin/unbye.js
Normal file
31
commands/admin/unbye.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const fs = require('fs');
|
||||
|
||||
class unbyeCommand extends Command {
|
||||
constructor() {
|
||||
super('unbye', {
|
||||
aliases: ['unbye'],
|
||||
category: 'admin',
|
||||
channelRestriction: 'guild',
|
||||
userPermissions: ['MANAGE_CHANNELS'],
|
||||
description: {
|
||||
content: 'Delete leaving message',
|
||||
usage: '[]',
|
||||
examples: ['']
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async exec(message) {
|
||||
fs.unlink(`./bye/${message.guild.id}.json`, (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return message.channel.send('An error has occured, there is most likely no bye/leave message set!');
|
||||
} else {
|
||||
return message.channel.send('Disabled bye/leave message');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = unbyeCommand;
|
45
event/listeners/guildMemberRemove.js
Normal file
45
event/listeners/guildMemberRemove.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
const { Listener } = require('discord-akairo');
|
||||
const reload = require('auto-reload');
|
||||
const rand = require('../../rand.js');
|
||||
|
||||
class guildMemberRemoveListener extends Listener {
|
||||
constructor() {
|
||||
super('guildMemberRemove', {
|
||||
emitter: 'client',
|
||||
event: 'guildMemberRemove'
|
||||
});
|
||||
}
|
||||
|
||||
async exec(guild) {
|
||||
let bye = reload(`../../bye/${guild.guild.id}.json`);
|
||||
|
||||
const channel = this.client.channels.get(bye['channel']);
|
||||
|
||||
let byeMessage = bye['message'];
|
||||
|
||||
byeMessage = byeMessage.replace(/\[member\]/, guild.user.username);
|
||||
byeMessage = byeMessage.replace(/\[server\]/, guild.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);
|
||||
|
||||
|
||||
if (attach) {
|
||||
return channel.send(byeMessage, {files: [attach]});
|
||||
} else {
|
||||
return channel.send(byeMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = guildMemberRemoveListener;
|
Loading…
Reference in a new issue