generated from nhcarrigan/template
feat: notify naomi of name and title mentions
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user