aboutsummaryrefslogtreecommitdiff
path: root/src/inhibitors/checks/fatal.ts
blob: b585bd8e0d90cb2ed3aca5908f01dcdfa4e47d1c (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
import { BotInhibitor, InhibitorReason, InhibitorType, type SlashMessage } from '#lib';
import { type Message } from 'discord.js';

export default class FatalInhibitor extends BotInhibitor {
	public constructor() {
		super(InhibitorReason.Fatal, {
			reason: InhibitorReason.Fatal,
			type: InhibitorType.All,
			priority: 100
		});
	}

	public async exec(message: Message | SlashMessage): Promise<boolean> {
		if (this.client.isOwner(message.author)) return false;
		const globalCache = this.client.cache.global;
		for (const property in globalCache) {
			if (!globalCache[property as keyof typeof globalCache]) {
				void this.client.console.verbose(
					InhibitorReason.Fatal,
					`Blocked message with id <<${message.id}>> from <<${message.author.tag}>> in <<${message.guild?.name}>>.`
				);
				return true;
			}
		}
		return false;
	}
}