All files / src/modules/bot/events NotQuiteNitro.ts

0% Statements 0/22
0% Branches 0/8
0% Functions 0/4
0% Lines 0/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 48 49 50 51 52 53 54 55                                                                                                             
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
import { OnEvent } from "@nestjs/event-emitter";
import { Client, Message, TextChannel } from "discord.js";
 
@Injectable()
export class NotQuiteNitroEvent {
	public constructor(
		@Inject(LOCALIZATION_ADAPTER) private readonly translate: NestedLocalizationAdapter,
		private readonly client: Client,
	) {}
 
	@OnEvent("NotQuiteNitro")
	public async onNQN(message: Message, emojis: RegExpMatchArray) {
		let replyContent = message.content;
		for (const _emoji of emojis) {
			const emoji = this.client.emojis.cache.find((e) => e.name === _emoji);
			if (!emoji) return;
			if (new RegExp(emoji.toString(), "g").test(replyContent)) {
				replyContent = message.content.replace(new RegExp(emoji.toString(), "g"), emoji.toString());
			} else {
				replyContent = message.content.replace(new RegExp(`:${_emoji}:`, "g"), emoji.toString());
			}
 
			const webhook = (await (message.channel as TextChannel).fetchWebhooks()).find((w) => w.name === "N-D-B_NQN");
			if (!webhook) {
				await (message.channel as TextChannel).createWebhook({
					reason: this.translate.getTranslation(
						"Events.MessageCreate.NQNCreationReason",
						message.guild.preferredLocale,
						{
							Username: message.author.username,
							UserId: message.author.id,
						},
					),
					name: "N-D-B_NQN",
					avatar: this.client.user.displayAvatarURL(),
				});
			}
			await webhook.edit({
				name: message.member.nickname ? message.member.nickname : message.author.username,
				avatar: message.author.displayAvatarURL(),
			});
 
			message.delete();
			webhook.send(replyContent);
 
			await webhook.edit({
				name: "N-D-B_NQN",
				avatar: this.client.user.displayAvatarURL(),
			});
		}
	}
}