aboutsummaryrefslogtreecommitdiff
path: root/lib/extensions/discord-akairo/BotInhibitor.ts
blob: 8892b8b87e9bcef283d761719788aa376450a789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { BotCommand, CommandMessage, InhibitorReason, InhibitorType, SlashMessage } from '#lib';
import { Inhibitor, InhibitorOptions } from 'discord-akairo';
import { Message } from 'discord.js';

export abstract class BotInhibitor extends Inhibitor {
	public constructor(id: InhibitorReason, options?: BotInhibitorOptions) {
		super(id, options);
	}

	/**
	 * Checks if message should be blocked.
	 * A return value of true will block the message.
	 * If returning a Promise, a resolved value of true will block the message.
	 *
	 * **Note:** `'all'` type inhibitors do not have {@link Message.util} defined.
	 *
	 * @param message - Message being handled.
	 * @param command - Command to check.
	 */
	public abstract override exec(message: CommandMessage, command: BotCommand): any;
	public abstract override exec(message: CommandMessage | SlashMessage, command: BotCommand): any;
}

/**
 * Options to use for inhibitor execution behavior.
 */
export interface BotInhibitorOptions extends InhibitorOptions {
	/**
	 * Reason emitted when command or message is blocked.
	 * @default ""
	 */
	reason: InhibitorReason;

	/**
	 * - {@link InhibitorType.All} run on all messages
	 * - {@link InhibitorType.Pre} run on messages not blocked by the built-in inhibitors
	 * - {@link InhibitorType.Post} run on messages that are commands
	 */
	type: InhibitorType;

	/**
	 * Priority for the inhibitor for when more than one inhibitors block a message.
	 * The inhibitor with the highest priority is the one that is used for the block reason.
	 * @default 0
	 */
	priority?: number;
}