Haha-Yes/commands/fun/fakeleave.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-08-11 19:54:41 +02:00
const { Command } = require('discord-akairo');
2019-11-27 12:16:30 +01:00
const leaveChannel = require('../../models').leaveChannel;
2019-08-11 19:54:41 +02:00
const rand = require('../../rand.js');
class fakeleaveCommand extends Command {
constructor() {
super('fakeleave', {
aliases: ['fakeleave'],
category: 'admin',
channelRestriction: 'guild',
2019-11-22 20:56:54 +01:00
clientPermissions: ['SEND_MESSAGES', 'ATTACH_FILES'],
2019-08-11 19:54:41 +02:00
args: [
{
id: 'member',
2019-08-11 19:59:46 +02:00
type: 'user',
2019-08-11 19:54:41 +02:00
match: 'rest'
}
],
description: {
content: 'Fake leave message',
usage: '[user]',
examples: ['Supositware']
}
});
}
async exec(message, args) {
2019-11-27 12:16:30 +01:00
const leave = await leaveChannel.findOne({where: {guildID: message.guild.id}});
if (leave) {
const channel = this.client.channels.get(leave.get('channelID'));
2019-08-11 19:54:41 +02:00
2019-11-27 12:16:30 +01:00
let byeMessage = leave.get('message');
2019-08-11 19:54:41 +02:00
2019-11-27 13:17:49 +01:00
byeMessage = byeMessage.replace(/\[member\]/, args.member.username);
2019-08-11 19:54:41 +02:00
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);
2019-08-11 19:55:29 +02:00
message.delete();
2019-08-11 19:54:41 +02:00
if (attach) {
return channel.send(byeMessage, {files: [attach]});
} else {
return channel.send(byeMessage);
}
} else {
2019-11-27 12:16:30 +01:00
return message.channel.send('Are you sure this server have a leave message?');
2019-08-11 19:54:41 +02:00
}
}
}
module.exports = fakeleaveCommand;