Haha-Yes/commands/owner/blacklist.js

72 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-10-06 20:29:50 +02:00
const { Command } = require('discord-akairo');
const userBlacklist = require('../../models').userBlacklist;
2021-03-13 18:21:18 +01:00
const Blacklists = require('../../models').Blacklists;
2019-10-06 20:29:50 +02:00
class userBlacklistCommand extends Command {
2019-10-06 20:29:50 +02:00
constructor() {
super('userBlacklist', {
aliases: ['userblacklist', 'ublacklist'],
2019-10-06 20:29:50 +02:00
category: 'owner',
ownerOnly: 'true',
userPermissions: ['MANAGE_MESSAGES'],
args: [
2021-03-13 18:21:18 +01:00
{
id: 'command',
type: 'string',
prompt: {
start: 'Which command do you want to get a user blacklisted from?'
}
},
2019-10-06 20:29:50 +02:00
{
id: 'userID',
type: 'string',
prompt: {
start: 'Who do you want to blacklist?',
}
2021-03-13 18:21:18 +01:00
},
{
id: 'reason',
type: 'string',
match: 'rest',
default: 'No reason specified.'
2019-10-06 20:29:50 +02:00
}
],
2020-03-19 23:24:31 +01:00
channel: 'guild',
2019-10-06 20:29:50 +02:00
description: {
2019-10-06 20:38:06 +02:00
content: 'Blacklist user from the bot',
usage: '[userID]',
examples: ['']
2019-10-06 20:29:50 +02:00
}
});
}
async exec(message, args) {
2021-03-13 18:21:18 +01:00
const blacklist = await Blacklists.findOne({where: {type:args.command, uid:message.author.id}});
2019-10-06 20:29:50 +02:00
if (!blacklist) {
2021-03-13 18:21:18 +01:00
const body = {type:args.command, uid: args.userID, reason: args.reason};
Blacklists.create(body);
let user = this.client.users.resolve(args.userID);
return message.channel.send(`${user.tag} has been blacklisted from ${args.command} with the following reason ${args.reason}`);
2019-10-06 20:29:50 +02:00
} else {
message.channel.send('This user is already blacklisted, do you want to unblacklist him? y/n');
const filter = m => m.content && m.author.id === message.author.id;
2019-10-06 20:29:50 +02:00
message.channel.awaitMessages(filter, {time: 5000 * 1000, max: 1, errors: ['time'] })
.then(messages => {
console.log(messages);
2019-10-06 20:29:50 +02:00
let messageContent = messages.map(messages => messages.content);
console.log(messageContent);
if (messageContent[0] === 'y' || messageContent[0] === 'yes') {
2021-03-13 18:21:18 +01:00
Blacklists.destroy({where: {type:args.command, uid:args.userID}});
return message.channel.send(`The following ID have been unblacklisted from ${args.command}: ${args.userID}`);
2019-10-06 20:29:50 +02:00
}
})
.catch(err => {
console.error(err);
return message.channel.send('Took too long to answer. didin\'t unblacklist anyone.');
});
}
}
}
module.exports = userBlacklistCommand;