-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove whitelist command, move functionality into blacklist command
A new `action` argument determines adding or removing from the blacklist
- Loading branch information
Showing
9 changed files
with
108 additions
and
131 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |