From 048f99752550c6e03d1990a03cad78f3ac7d73aa Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Mon, 5 Sep 2022 17:36:42 -0400 Subject: revamp command permissions, fix permission exploit for some command when used in forum channels, use enums more --- src/inhibitors/command/disabledGlobal.ts | 23 +++++++++++++++++++++++ src/inhibitors/command/disabledGuild.ts | 25 +++++++++++++++++++++++++ src/inhibitors/command/dm.ts | 8 ++++---- src/inhibitors/command/globalDisabledCommand.ts | 23 ----------------------- src/inhibitors/command/guild.ts | 10 +++++----- src/inhibitors/command/guildDisabledCommand.ts | 25 ------------------------- src/inhibitors/command/notNsfw.ts | 23 +++++++++++++++++++++++ src/inhibitors/command/nsfw.ts | 23 ----------------------- src/inhibitors/command/owner.ts | 10 +++++----- src/inhibitors/command/restrictedChannel.ts | 10 +++++----- src/inhibitors/command/restrictedGuild.ts | 10 +++++----- src/inhibitors/command/superUser.ts | 8 ++++---- 12 files changed, 99 insertions(+), 99 deletions(-) create mode 100644 src/inhibitors/command/disabledGlobal.ts create mode 100644 src/inhibitors/command/disabledGuild.ts delete mode 100644 src/inhibitors/command/globalDisabledCommand.ts delete mode 100644 src/inhibitors/command/guildDisabledCommand.ts create mode 100644 src/inhibitors/command/notNsfw.ts delete mode 100644 src/inhibitors/command/nsfw.ts (limited to 'src/inhibitors/command') diff --git a/src/inhibitors/command/disabledGlobal.ts b/src/inhibitors/command/disabledGlobal.ts new file mode 100644 index 0000000..bfb5969 --- /dev/null +++ b/src/inhibitors/command/disabledGlobal.ts @@ -0,0 +1,23 @@ +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; + +export default class DisabledGlobalInhibitor extends BotInhibitor { + public constructor() { + super(InhibitorReason.DisabledGlobal, { + reason: InhibitorReason.DisabledGlobal, + type: InhibitorType.Post, + priority: 300 + }); + } + + public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { + if (message.author.isOwner()) return false; + if (this.client.cache.global.disabledCommands.includes(command?.id)) { + void this.client.console.verbose( + InhibitorReason.DisabledGlobal, + `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` + ); + return true; + } + return false; + } +} diff --git a/src/inhibitors/command/disabledGuild.ts b/src/inhibitors/command/disabledGuild.ts new file mode 100644 index 0000000..0df827d --- /dev/null +++ b/src/inhibitors/command/disabledGuild.ts @@ -0,0 +1,25 @@ +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; + +export default class DisabledGuildInhibitor extends BotInhibitor { + public constructor() { + super(InhibitorReason.DisabledGuild, { + reason: InhibitorReason.DisabledGuild, + type: InhibitorType.Post, + priority: 250 + }); + } + + public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { + if (!message.guild || !message.guild) return false; + if (message.author.isOwner() || message.author.isSuperUser()) return false; // super users bypass guild disabled commands + + if ((await message.guild.getSetting('disabledCommands'))?.includes(command?.id)) { + void this.client.console.verbose( + InhibitorReason.DisabledGuild, + `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` + ); + return true; + } + return false; + } +} diff --git a/src/inhibitors/command/dm.ts b/src/inhibitors/command/dm.ts index f25f542..aa39b94 100644 --- a/src/inhibitors/command/dm.ts +++ b/src/inhibitors/command/dm.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class DMInhibitor extends BotInhibitor { public constructor() { - super('dm', { - reason: 'dm', - type: 'post', + super(InhibitorReason.Dm, { + reason: InhibitorReason.Dm, + type: InhibitorType.Post, priority: 75 }); } diff --git a/src/inhibitors/command/globalDisabledCommand.ts b/src/inhibitors/command/globalDisabledCommand.ts deleted file mode 100644 index 4a93f2f..0000000 --- a/src/inhibitors/command/globalDisabledCommand.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; - -export default class DisabledGuildCommandInhibitor extends BotInhibitor { - public constructor() { - super('disabledGlobalCommand', { - reason: 'disabledGlobal', - type: 'post', - priority: 300 - }); - } - - public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { - if (message.author.isOwner()) return false; - if (this.client.cache.global.disabledCommands.includes(command?.id)) { - void this.client.console.verbose( - 'disabledGlobalCommand', - `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` - ); - return true; - } - return false; - } -} diff --git a/src/inhibitors/command/guild.ts b/src/inhibitors/command/guild.ts index 1d70c7d..24e2577 100644 --- a/src/inhibitors/command/guild.ts +++ b/src/inhibitors/command/guild.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class GuildInhibitor extends BotInhibitor { public constructor() { - super('guild', { - reason: 'guild', - type: 'post', + super(InhibitorReason.Guild, { + reason: InhibitorReason.Guild, + type: InhibitorType.Post, priority: 80 }); } @@ -12,7 +12,7 @@ export default class GuildInhibitor extends BotInhibitor { public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { if (command.channel === 'guild' && !message.guild) { void this.client.console.verbose( - 'guild', + InhibitorReason.Guild, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.author.tag}>>.` ); return true; diff --git a/src/inhibitors/command/guildDisabledCommand.ts b/src/inhibitors/command/guildDisabledCommand.ts deleted file mode 100644 index 97ac995..0000000 --- a/src/inhibitors/command/guildDisabledCommand.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; - -export default class DisabledGuildCommandInhibitor extends BotInhibitor { - public constructor() { - super('disabledGuildCommand', { - reason: 'disabledGuild', - type: 'post', - priority: 250 - }); - } - - public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { - if (!message.guild || !message.guild) return false; - if (message.author.isOwner() || message.author.isSuperUser()) return false; // super users bypass guild disabled commands - - if ((await message.guild.getSetting('disabledCommands'))?.includes(command?.id)) { - void this.client.console.verbose( - 'disabledGuildCommand', - `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` - ); - return true; - } - return false; - } -} diff --git a/src/inhibitors/command/notNsfw.ts b/src/inhibitors/command/notNsfw.ts new file mode 100644 index 0000000..08e5556 --- /dev/null +++ b/src/inhibitors/command/notNsfw.ts @@ -0,0 +1,23 @@ +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { type TextChannel } from 'discord.js'; + +export default class NotNsfwInhibitor extends BotInhibitor { + public constructor() { + super(InhibitorReason.NotNsfw, { + reason: InhibitorReason.NotNsfw, + type: InhibitorType.Post, + priority: 25 + }); + } + + public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { + if (command.onlyNsfw && !(message.channel as TextChannel).nsfw) { + void this.client.console.verbose( + InhibitorReason.NotNsfw, + `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` + ); + return true; + } + return false; + } +} diff --git a/src/inhibitors/command/nsfw.ts b/src/inhibitors/command/nsfw.ts deleted file mode 100644 index 623115e..0000000 --- a/src/inhibitors/command/nsfw.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; -import { type TextChannel } from 'discord.js'; - -export default class NsfwInhibitor extends BotInhibitor { - public constructor() { - super('nsfw', { - reason: 'notNsfw', - type: 'post', - priority: 25 - }); - } - - public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise { - if (command.onlyNsfw && !(message.channel as TextChannel).nsfw) { - void this.client.console.verbose( - 'notNsfw', - `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` - ); - return true; - } - return false; - } -} diff --git a/src/inhibitors/command/owner.ts b/src/inhibitors/command/owner.ts index 15643be..8736cff 100644 --- a/src/inhibitors/command/owner.ts +++ b/src/inhibitors/command/owner.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class OwnerInhibitor extends BotInhibitor { public constructor() { - super('owner', { - reason: 'owner', - type: 'post', + super(InhibitorReason.Owner, { + reason: InhibitorReason.Owner, + type: InhibitorType.Post, priority: 100 }); } @@ -13,7 +13,7 @@ export default class OwnerInhibitor extends BotInhibitor { if (command.ownerOnly) { if (!this.client.isOwner(message.author)) { void this.client.console.verbose( - 'owner', + InhibitorReason.Owner, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/restrictedChannel.ts b/src/inhibitors/command/restrictedChannel.ts index ec23604..bfacebc 100644 --- a/src/inhibitors/command/restrictedChannel.ts +++ b/src/inhibitors/command/restrictedChannel.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class RestrictedChannelInhibitor extends BotInhibitor { public constructor() { - super('restrictedChannel', { - reason: 'restrictedChannel', - type: 'post', + super(InhibitorReason.RestrictedChannel, { + reason: InhibitorReason.RestrictedChannel, + type: InhibitorType.Post, priority: 10 }); } @@ -13,7 +13,7 @@ export default class RestrictedChannelInhibitor extends BotInhibitor { if (command.restrictedChannels?.length && message.channel) { if (!command.restrictedChannels.includes(message.channel.id)) { void this.client.console.verbose( - 'restrictedChannel', + InhibitorReason.RestrictedChannel, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/restrictedGuild.ts b/src/inhibitors/command/restrictedGuild.ts index ec0ad2c..4520cbc 100644 --- a/src/inhibitors/command/restrictedGuild.ts +++ b/src/inhibitors/command/restrictedGuild.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class RestrictedGuildInhibitor extends BotInhibitor { public constructor() { - super('restrictedGuild', { - reason: 'restrictedGuild', - type: 'post', + super(InhibitorReason.RestrictedGuild, { + reason: InhibitorReason.RestrictedGuild, + type: InhibitorType.Post, priority: 5 }); } @@ -13,7 +13,7 @@ export default class RestrictedGuildInhibitor extends BotInhibitor { if (command.restrictedChannels?.length && message.channel) { if (!command.restrictedChannels.includes(message.channel.id)) { void this.client.console.verbose( - 'restrictedGuild', + InhibitorReason.RestrictedGuild, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/command/superUser.ts b/src/inhibitors/command/superUser.ts index a923c1a..dd71539 100644 --- a/src/inhibitors/command/superUser.ts +++ b/src/inhibitors/command/superUser.ts @@ -1,10 +1,10 @@ -import { BotInhibitor, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class SuperUserInhibitor extends BotInhibitor { public constructor() { - super('superUser', { - reason: 'superUser', - type: 'post', + super(InhibitorReason.SuperUser, { + reason: InhibitorReason.SuperUser, + type: InhibitorType.Post, priority: 99 }); } -- cgit