-
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.
To prevent given users from triggering commands. Global blacklist will prevent in ALL guilds as well as DMs
- Loading branch information
Showing
3 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Bot } from '../../../bot/Bot'; | ||
import { Message } from '../../../types/Message'; | ||
import { Command } from '../../Command'; | ||
import { Middleware } from '../../middleware/Middleware'; | ||
import { User } from 'discord.js'; | ||
|
||
export default class Blacklist extends Command<Bot> | ||
{ | ||
public constructor(bot: Bot) | ||
{ | ||
super(bot, { | ||
name: 'blacklist', | ||
description: 'Blacklist a user from calling commands', | ||
aliases: ['bl'], | ||
usage: '<prefix>blacklist <user>, [\'global\']', | ||
extraHelp: 'If global, this will block the user from calling commands in ANY server and DMs', | ||
group: 'base', | ||
permissions: ['ADMINISTRATOR'] | ||
}); | ||
|
||
this.use(Middleware.resolveArgs({ '<user>': 'User' })); | ||
this.use(Middleware.expect({ '<user>': 'User' })); | ||
} | ||
|
||
public async action(message: Message, [user, global]: [User, string]): Promise<Message | Message[]> | ||
{ | ||
if (user.id === message.author.id) | ||
return message.channel.send(`I don't think you want to blacklist yourself.`); | ||
|
||
if (user.bot) return message.channel.send( | ||
`Bots already cannot call commands and do not need to be blacklisted.`); | ||
|
||
if (global === 'global') | ||
{ | ||
if (!this.bot.isOwner(message.author)) | ||
return message.channel.send('Only bot owners may blacklist globally.'); | ||
|
||
if (this.bot.storage.exists(`blacklist/${user.id}`)) | ||
return message.channel.send('That user is already globally blacklisted.'); | ||
|
||
this.bot.storage.setItem(`blacklist/${user.id}`, true); | ||
return message.channel.send(`Added ${user.username}#${user.discriminator} to the global blacklist.`); | ||
} | ||
|
||
if ((await message.guild.fetchMember(user)).hasPermission('ADMINISTRATOR')) | ||
return message.channel.send('You may not use this command on that person.'); | ||
|
||
if (message.guild.storage.settingExists(`blacklist/${user.id}`)) | ||
return message.channel.send('That user is already blacklisted in this server.'); | ||
|
||
message.guild.storage.setSetting(`blacklist/${user.id}`, true); | ||
return message.channel.send(`Added ${user.username}#${user.discriminator} to this server's blacklist.`); | ||
} | ||
} |
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,45 @@ | ||
import { Bot } from '../../../bot/Bot'; | ||
import { Message } from '../../../types/Message'; | ||
import { Command } from '../../Command'; | ||
import { Middleware } from '../../middleware/Middleware'; | ||
import { User } from 'discord.js'; | ||
|
||
export default class Whitelist extends Command<Bot> | ||
{ | ||
public constructor(bot: Bot) | ||
{ | ||
super(bot, { | ||
name: 'whitelist', | ||
description: 'Remove a user from the command blacklist', | ||
aliases: ['wl'], | ||
usage: '<prefix>whitelist <user>, [\'global\']', | ||
extraHelp: '', | ||
group: 'base', | ||
permissions: ['ADMINISTRATOR'] | ||
}); | ||
|
||
this.use(Middleware.resolveArgs({ '<user>': 'User' })); | ||
this.use(Middleware.expect({ '<user>': 'User' })); | ||
} | ||
|
||
public action(message: Message, [user, global]: [User, string]): Promise<Message | Message[]> | ||
{ | ||
if (global === 'global') | ||
{ | ||
if (!this.bot.isOwner(message.author)) | ||
return message.channel.send('Only bot owners may remove a global blacklisting.'); | ||
|
||
if (!this.bot.storage.exists(`blacklist/${user.id}`)) | ||
return message.channel.send('That user is not currently globally blacklisted.'); | ||
|
||
this.bot.storage.removeItem(`blacklist/${user.id}`); | ||
return message.channel.send(`Removed ${user.username}#${user.discriminator} from the global blacklist.`); | ||
} | ||
|
||
if (!message.guild.storage.settingExists(`blacklist/${user.id}`)) | ||
return message.channel.send('That user is not currently blacklisted in this server.'); | ||
|
||
message.guild.storage.removeSetting(`blacklist/${user.id}`); | ||
return message.channel.send(`Removed ${user.username}#${user.discriminator} from this server's blacklist.`); | ||
} | ||
} |