aboutsummaryrefslogtreecommitdiff
path: root/src/listeners/message/highlight.ts
blob: ae48b246046cfefb6ab0603c65787b2415088cda (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
import { BotListener, Emitter, type BotClientEvents } from '#lib';
import { Events } from 'discord.js';

export default class HighlightListener extends BotListener {
	public constructor() {
		super('highlight', {
			emitter: Emitter.Client,
			event: Events.MessageCreate
		});
	}

	public async exec(...[message]: BotClientEvents[Events.MessageCreate]) {
		if (!message.inGuild()) return;
		if (message.author.bot || message.system) return;
		if (!(await message.guild.hasFeature('highlight'))) return; // allows highlighting to be disabled on a guild-by-guild basis

		this.client.highlightManager.updateLastTalked(message);
		const res = this.client.highlightManager.checkMessage(message);

		for (const [user, hl] of res.entries()) {
			if (message.author.id === user) continue;
			void this.client.highlightManager.notify(message, user, hl);
		}
	}
}