Skip to content

Commit

Permalink
Remove whitelist command, move functionality into blacklist command
Browse files Browse the repository at this point in the history
A new `action` argument determines adding or removing from the blacklist
  • Loading branch information
zajrik committed Aug 7, 2017
1 parent 124f8a5 commit bc59e68
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 131 deletions.
62 changes: 0 additions & 62 deletions src/command/base/blacklist/Blacklist.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/command/base/blacklist/Whitelist.ts

This file was deleted.

89 changes: 89 additions & 0 deletions src/command/base/usagecontrol/Blacklist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Message } from '../../../types/Message';
import { Command } from '../../Command';
import { Middleware } from '../../middleware/Middleware';
import { User, GuildMember } from 'discord.js';
import { using, localizable } from '../../CommandDecorators';
import { ResourceLoader } from '../../../types/ResourceLoader';
import { BaseStrings as s } from '../../../localization/BaseStrings';

export default class extends Command
{
public constructor()
{
super({
name: 'blacklist',
desc: 'Blacklist a user from calling commands',
aliases: ['bl'],
usage: `<prefix>blacklist <action> <user> ['global']`,
info: 'If global, this will block the user from calling commands in ANY server and DMs',
callerPermissions: ['ADMINISTRATOR']
});
}

@using(Middleware.resolve('action: String, user: User'))
@using(Middleware.expect(`action: ['add', 'remove'], user: User`))
@localizable
public async action(message: Message, [res, action, user, global]: [ResourceLoader, string, User, string]): Promise<Message | Message[]>
{
if (action === 'add')
{
if (user.id === message.author.id)
return message.channel.send(res(s.CMD_BLACKLIST_ERR_NOSELF));

if (user.bot) return message.channel.send(res(s.CMD_BLACKLIST_ERR_NOBOT));

if (global === 'global')
{
if (!this.client.isOwner(message.author))
return message.channel.send(res(s.CMD_BLACKLIST_ERR_OWNERONLY));

const globalBlacklist: any = await this.client.storage.get('blacklist') || {};
if (globalBlacklist[user.id])
return message.channel.send(res(s.CMD_BLACKLIST_ERR_ALREADYGLOBAL));

await this.client.storage.set(`blacklist.${user.id}`, true);
this.client.emit('blacklistAdd', user, true);
return message.channel.send(res(s.CMD_BLACKLIST_GLOBALSUCCESS, { user: user.tag }));
}

let member: GuildMember;
try { member = await message.guild.fetchMember(user); }
catch (err) {}

if (member && member.permissions.has('ADMINISTRATOR'))
return message.channel.send(res(s.CMD_BLACKLIST_ERR_BADTARGET));

const guildBlacklist: any = await message.guild.storage.settings.get('blacklist') || {};
if (guildBlacklist[user.id])
return message.channel.send(res(s.CMD_BLACKLIST_ERR_ALREADYBLACKLISTED));

await message.guild.storage.settings.set(`blacklist.${user.id}`, true);
this.client.emit('blacklistAdd', user, false);
return message.channel.send(res(s.CMD_BLACKLIST_SUCCESS, { user: user.tag }));
}
else if (action === 'remove')
{
if (global === 'global')
{
if (!this.client.isOwner(message.author))
return message.channel.send(res(s.CMD_WHITELIST_ERR_OWNERONLY));

const globalBlacklist: any = await this.client.storage.get('blacklist') || {};
if (!globalBlacklist[user.id])
return message.channel.send(res(s.CMD_WHITELIST_ERR_NOTGLOBAL));

await this.client.storage.remove(`blacklist.${user.id}`);
this.client.emit('blacklistRemove', user, true);
return message.channel.send(res(s.CMD_WHITELIST_GLOBALSUCCESS, { user: user.tag }));
}

const guildBlacklist: any = await message.guild.storage.settings.get('blacklist') || {};
if (!guildBlacklist[user.id])
return message.channel.send(res(s.CMD_WHITELIST_ERR_NOTBLACKLISTED));

await message.guild.storage.settings.remove(`blacklist.${user.id}`);
this.client.emit('blacklistRemove', user, false);
return message.channel.send(res(s.CMD_WHITELIST_SUCCESS, { user: user.tag }));
}
}
}
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/localization/en_us/cmd/en_us.cmd.blacklist.lang
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ Added {{ user }} to the global blacklist.

[CMD_BLACKLIST_SUCCESS]
Added {{ user }} to the blacklist for this server.

[CMD_WHITELIST_ERR_OWNERONLY]
Only bot owners may remove a user from the global blacklist.

[CMD_WHITELIST_ERR_NOTGLOBAL]
That user is not currently on the global blacklist.

[CMD_WHITELIST_ERR_NOTBLACKLISTED]
That user is not currently blacklisted in this server.

[CMD_WHITELIST_GLOBALSUCCESS]
Removed {{ user }} from the global blacklist.

[CMD_WHITELIST_SUCCESS]
Removed {{ user }} from the blacklist for this server.
14 changes: 0 additions & 14 deletions src/localization/en_us/cmd/en_us.cmd.whitelist.lang

This file was deleted.

8 changes: 3 additions & 5 deletions src/types/BaseCommandName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated automatically at Thu Jul 06 2017 09:05:41 GMT-0500 (CDT)
// Generated automatically at Mon Aug 07 2017 02:16:27 GMT-0500 (Central Daylight Time)

/**
* @typedef {string} BaseCommandName String representing a name of a base command. Valid names are:
Expand All @@ -15,8 +15,7 @@
* 'ping',
* 'reload',
* 'setlang',
* 'setprefix',
* 'whitelist'
* 'setprefix'
* ```
*/

Expand All @@ -32,5 +31,4 @@ export type BaseCommandName = 'blacklist'
| 'ping'
| 'reload'
| 'setlang'
| 'setprefix'
| 'whitelist';
| 'setprefix';
2 changes: 1 addition & 1 deletion src/util/static/baseCommandNames.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["blacklist","clearlimit","disablegroup","enablegroup","eval","eval:ts","help","limit","listgroups","ping","reload","setlang","setprefix","whitelist"]
["blacklist","clearlimit","disablegroup","enablegroup","eval","eval:ts","help","limit","listgroups","ping","reload","setlang","setprefix"]

0 comments on commit bc59e68

Please sign in to comment.