fix: prevent duplicate DM notifications for multi-keyword matches

Coordinates respondToMention and notifyNameMention so only one DM is
sent per message, regardless of how many keyword patterns are triggered.
This commit is contained in:
2026-03-12 22:16:05 -07:00
parent f61ea3b3cb
commit 343d712e33
2 changed files with 11 additions and 6 deletions
+7 -4
View File
@@ -15,21 +15,22 @@ import type { Amari } from "../interfaces/amari.js";
* If so, responds.
* @param amari -- Amari's instance.
* @param message -- The guild message payload from Discord.
* @returns Whether a DM notification was sent.
*/
// eslint-disable-next-line complexity -- Mainly those reply options...
export const respondToMention = async(
amari: Amari,
message: Message<true>,
): Promise<void> => {
): Promise<boolean> => {
try {
const naomi = amari.discord.users.cache.get(ids.users.naomi)
?? await amari.discord.users.fetch(ids.users.naomi);
const { mentions, content, author, url, channel } = message;
if (author.bot || author.id === ids.users.naomi) {
return;
return false;
}
if (amari.recentlyActiveChannels.has(channel.id)) {
return;
return false;
}
const mentionsNaomi = mentions.has(ids.users.naomi, {
ignoreEveryone: true,
@@ -45,7 +46,7 @@ export const respondToMention = async(
ignoreRoles: true,
}) || /nhcarrigan/i.test(content);
if (!mentionsNaomi && !mentionsNHCarrigan) {
return;
return false;
}
await naomi.send(
{
@@ -56,9 +57,11 @@ export const respondToMention = async(
await logger.metric("processed_mention", 1, { pingType: mentionsNaomi
? "naomi"
: "nhcarrigan", user: author.id });
return true;
} catch (error) {
if (error instanceof Error) {
await logger.error("respond to mention module", error);
}
return false;
}
};