Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
blacklist command
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Dec 31, 2017
1 parent 24eea41 commit 266d64b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/commands/Admin/blacklist.js
@@ -0,0 +1,36 @@
const { Command } = require('klasa');
const { Guild } = require('discord.js');

module.exports = class extends Command {

constructor(...args) {
super(...args, {
permLevel: 10,
description: (msg) => msg.language.get('COMMAND_BLACKLIST_DESCRIPTION'),
usage: '<User:user|Guild:guild> [...]',
usageDelim: ' '
});
}

async run(msg, usersAndGuilds) {
usersAndGuilds = new Set(usersAndGuilds);
const usersAdded = [];
const usersRemoved = [];
const guildsAdded = [];
const guildsRemoved = [];

for (const userOrGuild of usersAndGuilds) {
const type = userOrGuild instanceof Guild ? 'guild' : 'user';

await this.client.configs.update(`${type}Blacklist`, userOrGuild.id, msg.guild);

if (type === 'guild' && this.client.guildBlacklist.includes(userOrGuild.id)) guildsAdded.push(userOrGuild.name);
else if (type === 'guild') guildsRemoved.push(userOrGuild.name);
else if (type === 'user' && this.client.userBlacklist.includes(userOrGuild.id)) usersAdded.push(userOrGuild.username);
else usersRemoved.push(userOrGuild.username);
}

return msg.sendMessage(msg.language.get('COMMAND_BLACKLIST_SUCCESS', usersAdded, usersRemoved, guildsAdded, guildsRemoved));
}

};
7 changes: 7 additions & 0 deletions src/languages/en-US.js
Expand Up @@ -49,6 +49,13 @@ module.exports = class extends Language {
INHIBITOR_REQUIRED_CONFIGS: (configs) => `The guild is missing the **${configs.join(', ')}** guild setting${configs.length !== 1 ? 's' : ''} and thus the command cannot run.`,
INHIBITOR_RUNIN: (types) => `This command is only available in ${types} channels`,
INHIBITOR_RUNIN_NONE: (name) => `The ${name} command is not configured to run in any channel.`,
COMMAND_BLACKLIST_DESCRIPTION: 'Blacklists or un-blacklists users and guilds from the bot.',
COMMAND_BLACKLIST_SUCCESS: (usersAdded, usersRemoved, guildsAdded, guildsRemoved) => [
usersAdded.length ? `**UsersAdded**\n${util.codeBlock('', usersAdded.join(', '))}` : '',
usersRemoved.length ? `**UsersRemoved**\n${util.codeBlock('', usersRemoved.join(', '))}` : '',
guildsAdded.length ? `**GuildsAdded**\n${util.codeBlock('', guildsAdded.join(', '))}` : '',
guildsRemoved.length ? `**GuildsRemoved**\n${util.codeBlock('', guildsRemoved.join(', '))}` : ''
].filter(val => val !== '').join('\n'),
COMMAND_EVAL_DESCRIPTION: 'Evaluates arbitrary Javascript. Reserved for bot owner.',
COMMAND_EVAL_EXTENDEDHELP: [
'The eval command evaluates code as-in, any error thrown from it will be handled.',
Expand Down

0 comments on commit 266d64b

Please sign in to comment.