diff options
Diffstat (limited to 'src/inhibitors')
16 files changed, 181 insertions, 20 deletions
diff --git a/src/inhibitors/blacklist/channelGlobalBlacklist.ts b/src/inhibitors/blacklist/channelGlobalBlacklist.ts index 9bbf30f..36a6757 100644 --- a/src/inhibitors/blacklist/channelGlobalBlacklist.ts +++ b/src/inhibitors/blacklist/channelGlobalBlacklist.ts @@ -5,7 +5,8 @@ export default class UserGlobalBlacklistInhibitor extends BushInhibitor { super('channelGlobalBlacklist', { reason: 'channelGlobalBlacklist', category: 'blacklist', - type: 'all' + type: 'post', + priority: 500 }); } @@ -14,7 +15,6 @@ export default class UserGlobalBlacklistInhibitor extends BushInhibitor { if (client.isOwner(message.author) || client.isSuperUser(message.author) || client.user!.id === message.author.id) return false; if (client.cache.global.blacklistedChannels.includes(message.channel!.id)) { - // client.console.debug(`channelGlobalBlacklist blocked message.`); return true; } return false; diff --git a/src/inhibitors/blacklist/channelGuildBlacklist.ts b/src/inhibitors/blacklist/channelGuildBlacklist.ts index b4c6f3f..54acb34 100644 --- a/src/inhibitors/blacklist/channelGuildBlacklist.ts +++ b/src/inhibitors/blacklist/channelGuildBlacklist.ts @@ -5,7 +5,8 @@ export default class ChannelGuildBlacklistInhibitor extends BushInhibitor { super('channelGuildBlacklist', { reason: 'channelGuildBlacklist', category: 'blacklist', - type: 'all' + type: 'post', + priority: 499 }); } @@ -14,7 +15,6 @@ export default class ChannelGuildBlacklistInhibitor extends BushInhibitor { if (client.isOwner(message.author) || client.isSuperUser(message.author) || client.user!.id === message.author.id) return false; if ((await message.guild.getSetting('blacklistedChannels'))?.includes(message.channel!.id)) { - // client.console.debug(`channelGuildBlacklist blocked message.`); return true; } return false; diff --git a/src/inhibitors/blacklist/guildBlacklist.ts b/src/inhibitors/blacklist/guildBlacklist.ts index de15d76..ec78995 100644 --- a/src/inhibitors/blacklist/guildBlacklist.ts +++ b/src/inhibitors/blacklist/guildBlacklist.ts @@ -5,7 +5,8 @@ export default class GuildBlacklistInhibitor extends BushInhibitor { super('guildBlacklist', { reason: 'guildBlacklist', category: 'blacklist', - type: 'all' + type: 'all', + priority: 50 }); } @@ -17,7 +18,6 @@ export default class GuildBlacklistInhibitor extends BushInhibitor { ) return false; if (client.cache.global.blacklistedGuilds.includes(message.guild.id)) { - // client.console.debug(`GuildBlacklistInhibitor blocked message.`); return true; } return false; diff --git a/src/inhibitors/blacklist/userGlobalBlacklist.ts b/src/inhibitors/blacklist/userGlobalBlacklist.ts index 967943d..65d763d 100644 --- a/src/inhibitors/blacklist/userGlobalBlacklist.ts +++ b/src/inhibitors/blacklist/userGlobalBlacklist.ts @@ -5,7 +5,8 @@ export default class UserGlobalBlacklistInhibitor extends BushInhibitor { super('userGlobalBlacklist', { reason: 'userGlobalBlacklist', category: 'blacklist', - type: 'all' + type: 'pre', + priority: 30 }); } @@ -14,7 +15,6 @@ export default class UserGlobalBlacklistInhibitor extends BushInhibitor { if (client.isOwner(message.author) || client.isSuperUser(message.author) || client.user!.id === message.author.id) return false; if (client.cache.global.blacklistedUsers.includes(message.author.id)) { - // client.console.debug(`userGlobalBlacklist blocked message.`); return true; } return false; diff --git a/src/inhibitors/blacklist/userGuildBlacklist.ts b/src/inhibitors/blacklist/userGuildBlacklist.ts index 0e28ba4..34a24d3 100644 --- a/src/inhibitors/blacklist/userGuildBlacklist.ts +++ b/src/inhibitors/blacklist/userGuildBlacklist.ts @@ -5,7 +5,8 @@ export default class UserGuildBlacklistInhibitor extends BushInhibitor { super('userGuildBlacklist', { reason: 'userGuildBlacklist', category: 'blacklist', - type: 'all' + type: 'pre', + priority: 20 }); } @@ -14,7 +15,6 @@ export default class UserGuildBlacklistInhibitor extends BushInhibitor { if (client.isOwner(message.author) || client.isSuperUser(message.author) || client.user!.id === message.author.id) return false; if ((await message.guild.getSetting('blacklistedUsers'))?.includes(message.author.id)) { - // client.console.debug(`userGuildBlacklist blocked message.`); return true; } return false; diff --git a/src/inhibitors/noCache.ts b/src/inhibitors/checks/fatal.ts index 673f3ac..6b62507 100644 --- a/src/inhibitors/noCache.ts +++ b/src/inhibitors/checks/fatal.ts @@ -1,10 +1,11 @@ import { BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; -export default class NoCacheInhibitor extends BushInhibitor { +export default class FatalInhibitor extends BushInhibitor { public constructor() { - super('noCache', { - reason: 'noCache', + super('fatal', { + reason: 'fatal', type: 'all', + category: 'checks', priority: 100 }); } @@ -13,7 +14,6 @@ export default class NoCacheInhibitor extends BushInhibitor { if (client.isOwner(message.author)) return false; for (const property in client.cache.global) { if (!client.cache.global[property as keyof typeof client.cache.global]) { - client.console.debug(`NoCacheInhibitor blocked message.`); return true; } } diff --git a/src/inhibitors/checks/guildUnavailable.ts b/src/inhibitors/checks/guildUnavailable.ts new file mode 100644 index 0000000..0bd1bec --- /dev/null +++ b/src/inhibitors/checks/guildUnavailable.ts @@ -0,0 +1,19 @@ +import { BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class GuildUnavailableInhibitor extends BushInhibitor { + public constructor() { + super('guildUnavailable', { + reason: 'guildUnavailable', + type: 'all', + category: 'checks', + priority: 70 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage): Promise<boolean> { + if (message.guild && !message.guild.available) { + return true; + } + return false; + } +} diff --git a/src/inhibitors/command/dm.ts b/src/inhibitors/command/dm.ts new file mode 100644 index 0000000..4e9c53e --- /dev/null +++ b/src/inhibitors/command/dm.ts @@ -0,0 +1,19 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class DMInhibitor extends BushInhibitor { + public constructor() { + super('dm', { + reason: 'dm', + category: 'command', + type: 'post', + priority: 75 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.channel === 'dm' && message.guild) { + return true; + } + return false; + } +} diff --git a/src/inhibitors/commands/globalDisabledCommand.ts b/src/inhibitors/command/globalDisabledCommand.ts index 9a750cc..a6e24c7 100644 --- a/src/inhibitors/commands/globalDisabledCommand.ts +++ b/src/inhibitors/command/globalDisabledCommand.ts @@ -4,15 +4,15 @@ export default class DisabledGuildCommandInhibitor extends BushInhibitor { public constructor() { super('disabledGlobalCommand', { reason: 'disabledGlobal', - type: 'pre', - priority: 4 + category: 'command', + type: 'post', + priority: 300 }); } public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { if (message.author.isOwner()) return false; if (client.cache.global.disabledCommands?.includes(command?.id)) { - client.console.debug(`disabledGlobalCommand blocked message.`); return true; } return false; diff --git a/src/inhibitors/command/guild.ts b/src/inhibitors/command/guild.ts new file mode 100644 index 0000000..b960439 --- /dev/null +++ b/src/inhibitors/command/guild.ts @@ -0,0 +1,19 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class GuildInhibitor extends BushInhibitor { + public constructor() { + super('guild', { + reason: 'guild', + category: 'command', + type: 'post', + priority: 80 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.channel === 'guild' && !message.guild) { + return true; + } + return false; + } +} diff --git a/src/inhibitors/commands/guildDisabledCommand.ts b/src/inhibitors/command/guildDisabledCommand.ts index ee798e5..d56e42c 100644 --- a/src/inhibitors/commands/guildDisabledCommand.ts +++ b/src/inhibitors/command/guildDisabledCommand.ts @@ -4,8 +4,9 @@ export default class DisabledGuildCommandInhibitor extends BushInhibitor { public constructor() { super('disabledGuildCommand', { reason: 'disabledGuild', - type: 'pre', - priority: 3 + category: 'command', + type: 'post', + priority: 250 }); } @@ -14,7 +15,6 @@ export default class DisabledGuildCommandInhibitor extends BushInhibitor { if (message.author.isOwner() || message.author.isSuperUser()) return false; // super users bypass guild disabled commands if ((await message.guild.getSetting('disabledCommands'))?.includes(command?.id)) { - client.console.debug(`disabledGuildCommand blocked message.`); return true; } return false; diff --git a/src/inhibitors/command/nsfw.ts b/src/inhibitors/command/nsfw.ts new file mode 100644 index 0000000..563cb7a --- /dev/null +++ b/src/inhibitors/command/nsfw.ts @@ -0,0 +1,20 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; +import { TextChannel } from 'discord.js'; + +export default class NsfwInhibitor extends BushInhibitor { + public constructor() { + super('nsfw', { + reason: 'notNsfw', + category: 'command', + type: 'post', + priority: 25 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.onlyNsfw && !(message.channel as TextChannel).nsfw) { + return true; + } + return false; + } +} diff --git a/src/inhibitors/command/owner.ts b/src/inhibitors/command/owner.ts new file mode 100644 index 0000000..22ac913 --- /dev/null +++ b/src/inhibitors/command/owner.ts @@ -0,0 +1,21 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class OwnerInhibitor extends BushInhibitor { + public constructor() { + super('owner', { + reason: 'owner', + category: 'command', + type: 'post', + priority: 100 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.ownerOnly) { + if (!client.isOwner(message.author)) { + return true; + } + } + return false; + } +} diff --git a/src/inhibitors/command/restrictedChannel.ts b/src/inhibitors/command/restrictedChannel.ts new file mode 100644 index 0000000..4578d95 --- /dev/null +++ b/src/inhibitors/command/restrictedChannel.ts @@ -0,0 +1,21 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class RestrictedChannelInhibitor extends BushInhibitor { + public constructor() { + super('restrictedChannel', { + reason: 'restrictedChannel', + category: 'command', + type: 'post', + priority: 10 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.restrictedChannels?.length && message.channel) { + if (!command.restrictedChannels.includes(message.channel.id)) { + return true; + } + } + return false; + } +} diff --git a/src/inhibitors/command/restrictedGuild.ts b/src/inhibitors/command/restrictedGuild.ts new file mode 100644 index 0000000..7ec6926 --- /dev/null +++ b/src/inhibitors/command/restrictedGuild.ts @@ -0,0 +1,21 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class RestrictedGuildInhibitor extends BushInhibitor { + public constructor() { + super('restrictedGuild', { + reason: 'restrictedGuild', + category: 'command', + type: 'post', + priority: 5 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.restrictedChannels?.length && message.channel) { + if (!command.restrictedChannels.includes(message.channel.id)) { + return true; + } + } + return false; + } +} diff --git a/src/inhibitors/command/superUser.ts b/src/inhibitors/command/superUser.ts new file mode 100644 index 0000000..28674ea --- /dev/null +++ b/src/inhibitors/command/superUser.ts @@ -0,0 +1,21 @@ +import { BushCommand, BushInhibitor, BushMessage, BushSlashMessage } from '@lib'; + +export default class SuperUserInhibitor extends BushInhibitor { + public constructor() { + super('superUser', { + reason: 'superUser', + category: 'command', + type: 'post', + priority: 99 + }); + } + + public override async exec(message: BushMessage | BushSlashMessage, command: BushCommand): Promise<boolean> { + if (command.superUserOnly) { + if (!client.isSuperUser(message.author)) { + return true; + } + } + return false; + } +} |