aboutsummaryrefslogtreecommitdiff
path: root/src/inhibitors/blacklist/channelGuildBlacklist.ts
blob: ec81666a2f9c5d2bf18074a53f5d4d85f35934c2 (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
import { BotInhibitor, InhibitorReason, InhibitorType, type BotCommand, type CommandMessage, type SlashMessage } from '#lib';

export default class ChannelGuildBlacklistInhibitor extends BotInhibitor {
	public constructor() {
		super(InhibitorReason.ChannelGuildBlacklist, {
			reason: InhibitorReason.ChannelGuildBlacklist,
			type: InhibitorType.Post,
			priority: 499
		});
	}

	public async exec(message: CommandMessage | SlashMessage, command: BotCommand): Promise<boolean> {
		if (!message.author || !message.inGuild()) return false;
		//! do not change to message.author.isOwner()
		if (this.client.isOwner(message.author) || this.client.user!.id === message.author.id) return false;
		if (
			(await message.guild.getSetting('bypassChannelBlacklist'))?.includes(message.author.id) &&
			!command.bypassChannelBlacklist
		) {
			return false;
		}
		if (
			(await message.guild.getSetting('blacklistedChannels'))?.includes(message.channel!.id) &&
			!command.bypassChannelBlacklist
		) {
			void this.client.console.verbose(
				InhibitorReason.ChannelGuildBlacklist,
				`Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild.name}>>.`
			);
			return true;
		}
		return false;
	}
}