generated from nhcarrigan/template
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { MessageFlags, type Message } from "discord.js";
|
||||
import { ids } from "../config/ids.js";
|
||||
import { responses } from "../config/responses.js";
|
||||
import { getComponentsForNaomi } from "../utils/getComponentsForNaomi.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type { Amari } from "../interfaces/amari.js";
|
||||
|
||||
/**
|
||||
* Checks if a message mentions Naomi or our team role.
|
||||
* If so, responds.
|
||||
* @param amari -- Amari's instance.
|
||||
* @param message -- The guild message payload from Discord.
|
||||
*/
|
||||
// eslint-disable-next-line max-lines-per-function, complexity -- Mainly those reply options...
|
||||
export const respondToMention = async(
|
||||
amari: Amari,
|
||||
message: Message<true>,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const naomi = amari.discord.users.cache.get(ids.users.naomi)
|
||||
?? await amari.discord.users.fetch(ids.users.naomi);
|
||||
const { mentions, content, author, url } = message;
|
||||
if (author.bot || author.id === ids.users.naomi) {
|
||||
return;
|
||||
}
|
||||
if (mentions.has(ids.users.naomi, {
|
||||
ignoreEveryone: true,
|
||||
ignoreRepliedUser: true,
|
||||
ignoreRoles: true,
|
||||
}) || /naomi/i.test(content)) {
|
||||
await message.reply({
|
||||
allowedMentions: {
|
||||
repliedUser: false,
|
||||
},
|
||||
content: responses.naomiMentioned,
|
||||
});
|
||||
await naomi.send(
|
||||
{
|
||||
components: getComponentsForNaomi(author, content, url),
|
||||
flags: [ MessageFlags.IsComponentsV2 ],
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (mentions.has(ids.roles.nhcarrigan, {
|
||||
ignoreEveryone: true,
|
||||
ignoreRepliedUser: true,
|
||||
}) || mentions.has(ids.users.nhcarrigan, {
|
||||
ignoreEveryone: true,
|
||||
ignoreRepliedUser: true,
|
||||
ignoreRoles: true,
|
||||
}) || /nhcarrigan/i.test(content)) {
|
||||
await message.reply({
|
||||
allowedMentions: {
|
||||
repliedUser: false,
|
||||
},
|
||||
content: responses.naomiMentioned,
|
||||
});
|
||||
await naomi.send(
|
||||
{
|
||||
components: getComponentsForNaomi(author, content, url),
|
||||
flags: [ MessageFlags.IsComponentsV2 ],
|
||||
},
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
await logger.error("respond to mention module", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user