Haha-Yes/commands/fun/fakeleave.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-08-11 19:54:41 +02:00
const { Command } = require('discord-akairo');
const fs = require('fs');
const rand = require('../../rand.js');
class fakeleaveCommand extends Command {
constructor() {
super('fakeleave', {
aliases: ['fakeleave'],
category: 'admin',
channelRestriction: 'guild',
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) {
if (fs.existsSync(`./bye/${message.guild.id}.json`)) {
let member;
if (args.member) {
2019-08-11 19:56:39 +02:00
member = args.member.username;
2019-08-11 19:54:41 +02:00
} else {
2019-08-11 19:56:39 +02:00
member = message.author.username;
2019-08-11 19:54:41 +02:00
}
let bye = require(`../../bye/${message.guild.id}.json`);
const channel = this.client.channels.get(bye['channel']);
let byeMessage = bye['message'];
byeMessage = byeMessage.replace(/\[member\]/, member);
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 {
return message.channel.send('The server need a leave message first!');
}
}
}
module.exports = fakeleaveCommand;