diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-09-05 17:36:42 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-09-05 17:36:42 -0400 |
| commit | 048f99752550c6e03d1990a03cad78f3ac7d73aa (patch) | |
| tree | c238ac29b1b526e86bcbc4989036df981c860187 /src/inhibitors/checks | |
| parent | 6f8a4d13a490eda7a195d14833c83810f7b5a789 (diff) | |
| download | tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.tar.gz tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.tar.bz2 tanzanite-048f99752550c6e03d1990a03cad78f3ac7d73aa.zip | |
revamp command permissions, fix permission exploit for some command when used in forum channels, use enums more
Diffstat (limited to 'src/inhibitors/checks')
| -rw-r--r-- | src/inhibitors/checks/cannotSend.ts | 39 | ||||
| -rw-r--r-- | src/inhibitors/checks/fatal.ts | 10 | ||||
| -rw-r--r-- | src/inhibitors/checks/guildUnavailable.ts | 10 |
3 files changed, 49 insertions, 10 deletions
diff --git a/src/inhibitors/checks/cannotSend.ts b/src/inhibitors/checks/cannotSend.ts new file mode 100644 index 0000000..e9eab98 --- /dev/null +++ b/src/inhibitors/checks/cannotSend.ts @@ -0,0 +1,39 @@ +import { BotCommand, BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib'; +import { type Message } from 'discord.js'; + +export default class CannotSendInhibitor extends BotInhibitor { + public constructor() { + super(InhibitorReason.CannotSend, { + reason: InhibitorReason.CannotSend, + type: InhibitorType.Post, + priority: 1000 + }); + } + + public async exec(message: Message | SlashMessage, command: BotCommand): Promise<boolean> { + // let it error if it is the owner + if (this.client.isOwner(message.author)) return false; + if (!message.inGuild() || !message.channel) return false; + if (command.skipSendCheck) return false; + + if (!message.guild.members.me) throw new Error(`Client member not cached in ${message.guild.name} (${message.guild.id})`); + + // doesn't apply to slash commands + if (message.util?.isSlash) return false; + + const sendPerm = message.channel.isThread() ? 'SendMessages' : 'SendMessagesInThreads'; + + const perms = message.channel.permissionsFor(message.guild.members.me); + + if (perms == null) { + // todo: remove once forum channels are fixed + if (message.channel.isThread() && message.channel.parent == null) { + return false; + } else { + return true; + } + } + + return !perms.has(sendPerm); + } +} diff --git a/src/inhibitors/checks/fatal.ts b/src/inhibitors/checks/fatal.ts index 4364d48..b585bd8 100644 --- a/src/inhibitors/checks/fatal.ts +++ b/src/inhibitors/checks/fatal.ts @@ -1,11 +1,11 @@ -import { BotInhibitor, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib'; import { type Message } from 'discord.js'; export default class FatalInhibitor extends BotInhibitor { public constructor() { - super('fatal', { - reason: 'fatal', - type: 'all', + super(InhibitorReason.Fatal, { + reason: InhibitorReason.Fatal, + type: InhibitorType.All, priority: 100 }); } @@ -16,7 +16,7 @@ export default class FatalInhibitor extends BotInhibitor { for (const property in globalCache) { if (!globalCache[property as keyof typeof globalCache]) { void this.client.console.verbose( - 'fatal', + InhibitorReason.Fatal, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.` ); return true; diff --git a/src/inhibitors/checks/guildUnavailable.ts b/src/inhibitors/checks/guildUnavailable.ts index 4439d69..dc2ac26 100644 --- a/src/inhibitors/checks/guildUnavailable.ts +++ b/src/inhibitors/checks/guildUnavailable.ts @@ -1,11 +1,11 @@ -import { BotInhibitor, type SlashMessage } from '#lib'; +import { BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib'; import { type Message } from 'discord.js'; export default class GuildUnavailableInhibitor extends BotInhibitor { public constructor() { - super('guildUnavailable', { - reason: 'guildUnavailable', - type: 'all', + super(InhibitorReason.GuildUnavailable, { + reason: InhibitorReason.GuildUnavailable, + type: InhibitorType.All, priority: 70 }); } @@ -13,7 +13,7 @@ export default class GuildUnavailableInhibitor extends BotInhibitor { public async exec(message: Message | SlashMessage): Promise<boolean> { if (message.inGuild() && !message.guild.available) { void this.client.console.verbose( - 'guildUnavailable', + InhibitorReason.GuildUnavailable, `Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.` ); return true; |
