Haha-Yes/commands/admin/banword.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-08-21 19:58:51 +02:00
const { Command } = require('discord-akairo');
const BannedWords = require('../../models').bannedWords;
class BannedWordsCommand extends Command {
constructor() {
super('BannedWords', {
aliases: ['bannedword', 'banword'],
category: 'admin',
userPermissions: ['MANAGE_MESSAGES'],
2019-11-09 12:04:01 +01:00
clientPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES'],
2019-08-21 19:58:51 +02:00
args: [
{
id: 'word',
type: 'string',
prompt: {
start: 'What word should be banned',
},
match: 'rest'
},
{
id: 'remove',
match: 'flag',
flag: '--remove'
}
],
channelRestriction: 'guild',
description: {
content: 'Ban word on the server. --remove to delete a banned word',
usage: '[word to ban]',
examples: ['owo']
}
});
}
async exec(message, args) {
2019-08-24 12:03:21 +02:00
args.word = args.word.replace(/[\u0250-\ue007]/g, '');
2019-08-21 20:03:29 +02:00
const bannedWords = await BannedWords.findOne({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
2019-08-21 19:58:51 +02:00
if (!bannedWords) {
2019-08-21 20:03:29 +02:00
const body = {word: args.word.toLowerCase(), serverID: message.guild.id};
2019-08-21 19:58:51 +02:00
await BannedWords.create(body);
2019-08-21 20:03:29 +02:00
return message.channel.send(`The word ${args.word.toLowerCase()} have been banned`);
2019-08-21 19:58:51 +02:00
} else if (args.remove && bannedWords) {
2019-08-21 20:03:29 +02:00
BannedWords.destroy({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
return message.channel.send(`The word ${args.word.toLowerCase()} is no longer banned`);
2019-08-21 19:58:51 +02:00
} else {
message.channel.send('This word is already banned');
}
}
}
module.exports = BannedWordsCommand;