feat: notify naomi of name and title mentions
Node.js CI / CI (pull_request) Successful in 28s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 56s

This commit is contained in:
2026-03-02 13:34:11 -08:00
committed by Naomi Carrigan
parent f2f6775ab1
commit 8ee5fa7ced
2 changed files with 70 additions and 0 deletions
+2
View File
@@ -5,6 +5,7 @@
*/
import { ids } from "../config/ids.js";
import { notifyNameMention } from "../modules/notifyNameMention.js";
import { respondToMention } from "../modules/respondToMention.js";
import { updateMentorshipThread } from "../modules/updateMentorshipThread.js";
import type { Amari } from "../interfaces/amari.js";
@@ -29,4 +30,5 @@ export const handleMessageCreate = async(
}
await updateMentorshipThread(amari, message);
await respondToMention(amari, message);
await notifyNameMention(amari, message);
};
+68
View File
@@ -0,0 +1,68 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { MessageFlags, type Message } from "discord.js";
import { ids } from "../config/ids.js";
import { getComponentsForNaomi } from "../utils/getComponentsForNaomi.js";
import { logger } from "../utils/logger.js";
import type { Amari } from "../interfaces/amari.js";
const nameMentionPatterns = [
/n\s+a\s+o\s+m\s+i/i,
/\bgoddess\b/i,
/\bqueen\b/i,
/\bmistress\b/i,
/\bnaonao\b/i,
/\bnao\b/i,
/\bnomi\b/i,
/\bnae\b/i,
/\byour majesty\b/i,
/\bher majesty\b/i,
/\byour highness\b/i,
/\bher highness\b/i,
];
/**
* Checks if a message contains a nickname or indirect reference to Naomi.
* If so, forwards the message to Naomi via DM.
* @param amari -- Amari's instance.
* @param message -- The guild message payload from Discord.
*/
export const notifyNameMention = async(
amari: Amari,
message: Message<true>,
): Promise<void> => {
try {
const { content, author, url, channel } = message;
if (author.bot || author.id === ids.users.naomi) {
return;
}
if (amari.recentlyActiveChannels.has(channel.id)) {
return;
}
const matchedPattern = nameMentionPatterns.find((pattern) => {
return pattern.test(content);
});
if (matchedPattern === undefined) {
return;
}
const matchedText = content.match(matchedPattern)?.[0] ?? "";
const naomi = amari.discord.users.cache.get(ids.users.naomi)
?? await amari.discord.users.fetch(ids.users.naomi);
await naomi.send({
components: getComponentsForNaomi(author, content, url),
flags: [ MessageFlags.IsComponentsV2 ],
});
await logger.metric("processed_name_mention", 1, {
match: matchedText,
user: author.id,
});
} catch (error) {
if (error instanceof Error) {
await logger.error("notify name mention module", error);
}
}
};