aboutsummaryrefslogtreecommitdiff
path: root/src/inhibitors/checks/cannotSend.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-09-05 17:36:42 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-09-05 17:36:42 -0400
commit048f99752550c6e03d1990a03cad78f3ac7d73aa (patch)
treec238ac29b1b526e86bcbc4989036df981c860187 /src/inhibitors/checks/cannotSend.ts
parent6f8a4d13a490eda7a195d14833c83810f7b5a789 (diff)
downloadtanzanite-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/cannotSend.ts')
-rw-r--r--src/inhibitors/checks/cannotSend.ts39
1 files changed, 39 insertions, 0 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);
+ }
+}