Haha-Yes/commands/admin/banword.js

71 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2019-08-21 19:58:51 +02:00
const { Command } = require('discord-akairo');
2020-03-29 18:49:20 +02:00
const safe = require('safe-regex');
2019-08-21 19:58:51 +02:00
const BannedWords = require('../../models').bannedWords;
class BannedWordsCommand extends Command {
constructor() {
super('BannedWords', {
aliases: ['bannedword', 'banword', 'unbanword', 'censor', 'uncensor', 'blacklistword', 'blacklist', 'unblacklist'],
2019-08-21 19:58:51 +02:00
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',
match: 'rest'
},
{
id: 'remove',
match: 'flag',
flag: '--remove'
2020-01-30 12:02:27 +01:00
},
{
id: 'removeall',
match: 'flag',
flag: '--removeall'
2019-08-21 19:58:51 +02:00
}
],
2020-03-19 23:24:31 +01:00
channel: 'guild',
2019-08-21 19:58:51 +02:00
description: {
2020-02-18 18:59:38 +01:00
content: 'Ban word on the server. use the unbanword alias to delete a banned word, unbanword alias and --removeaall to remove every banned word',
2019-08-21 19:58:51 +02:00
usage: '[word to ban]',
examples: ['owo']
}
});
}
async exec(message, args) {
2020-03-29 18:49:20 +02:00
if (!safe(message.content)) return;
2020-03-29 18:31:15 +02:00
2020-02-18 18:59:38 +01:00
if (!args.word) args.word = '';
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 (message.util.parsed.alias == 'unbanword' || message.util.parsed.alias == 'uncensor' || message.util.parsed.alias == 'unblacklist' || args.remove || args.removeall) {
2020-02-18 18:59:38 +01:00
if (args.removeall) {
BannedWords.destroy({where: {serverID: message.guild.id}});
return message.channel.send('The banned words have been reset.');
}
if (bannedWords) {
BannedWords.destroy({where: {word: args.word.toLowerCase(), serverID: message.guild.id}});
return message.channel.send(`The word ${args.word.toLowerCase()} is no longer banned`);
} else {
return message.channel.send('There was no word to unban');
}
}
if (!args.word) return message.channel.send('Please specify a word to ban!');
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);
2020-02-02 18:37:57 +01:00
return message.channel.send(`The word ${args.word.toLowerCase()} has been banned`);
2019-08-21 19:58:51 +02:00
} else {
message.channel.send('This word is already banned');
}
}
}
module.exports = BannedWordsCommand;