feat: initial prototype

This commit is contained in:
2025-07-21 15:28:32 -07:00
parent da76bb5327
commit 26bea6e8f7
26 changed files with 5884 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { about } from "../commands/about.js";
import { add } from "../commands/add.js";
import { dm } from "../commands/dm.js";
import { list } from "../commands/list.js";
import { remove } from "../commands/remove.js";
import type { Command } from "../interfaces/command.js";
import type { Liora } from "../interfaces/liora.js";
import type { ChatInputCommandInteraction } from "discord.js";
const handlers: { _default: Command } & Record<string, Command> = {
_default: async(_, interaction): Promise<void> => {
await interaction.reply({
content: `Unknown command: ${interaction.commandName}`,
});
},
about: about,
add: add,
dm: dm,
list: list,
remove: remove,
};
/**
* Processes a slash command.
* @param liora - Liora's Discord instance.
* @param interaction - The command interaction payload from Discord.
*/
const chatInputInteractionCreate = async(
liora: Liora,
interaction: ChatInputCommandInteraction<"cached">,
): Promise<void> => {
const name = interaction.commandName;
// eslint-disable-next-line no-underscore-dangle -- We use _default as a fallback handler.
const handler = handlers[name] ?? handlers._default;
await handler(liora, interaction);
};
export { chatInputInteractionCreate };
+115
View File
@@ -0,0 +1,115 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ContainerBuilder,
SeparatorBuilder,
SeparatorSpacingSize,
TextDisplayBuilder,
type Message,
} from "discord.js";
import { checkGuildEntitlement } from "../utils/checkEntitlement.js";
import type { Liora } from "../interfaces/liora.js";
/**
* Processes a slash command.
* @param liora - Liora's Discord instance.
* @param message - The message payload from Discord.
*/
// eslint-disable-next-line max-lines-per-function -- It's mostly components.
const messageCreate = async(
liora: Liora,
message: Message<true>,
): Promise<void> => {
const isEntitled = await checkGuildEntitlement(liora, message.guild);
if (!isEntitled) {
return;
}
const highlights = await liora.database.highlights.findMany({
where: {
serverId: message.guild.id,
},
});
if (highlights.length <= 0) {
return;
}
await Promise.all(
// eslint-disable-next-line max-lines-per-function -- It's mostly components.
highlights.map(async(record) => {
// No need to notify the user if they are the one who sent the message.
if (record.userId === message.author.id) {
return;
}
if (record.words.length <= 0) {
return;
}
const foundWords = record.words.filter((word) => {
return message.content.toLowerCase().includes(word.toLowerCase());
});
if (foundWords.length <= 0) {
return;
}
const dm = await message.client.users.fetch(record.userId).catch(() => {
return null;
});
if (!dm) {
return;
}
await dm.send({
components: [
new ContainerBuilder().
addTextDisplayComponents(
new TextDisplayBuilder().setContent(
"One of your highlights was mentioned in a message!",
),
).
addSeparatorComponents(
new SeparatorBuilder().
setSpacing(SeparatorSpacingSize.Small).
setDivider(true),
).
addTextDisplayComponents(
new TextDisplayBuilder().setContent(
`The word(s) \`${foundWords.join(
", ",
)}\` were mentioned in the server \`${
message.guild.name
}\` by <@${message.author.displayName}>.`,
),
).
addTextDisplayComponents(
new TextDisplayBuilder().setContent(
`You can view the message here: ${message.url}`,
),
),
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().
setStyle(ButtonStyle.Link).
setLabel("Jump to Message").
setURL(message.url),
new ButtonBuilder().
setStyle(ButtonStyle.Link).
setLabel("Discord Server").
setURL("https://chat.nhcarrigan.com"),
new ButtonBuilder().
setStyle(ButtonStyle.Link).
setLabel("Forum").
setURL("https://forum.nhcarrigan.com"),
),
],
}).catch(() => {
// If we cannot send the DM, we do not want to throw an error.
return null;
});
}),
);
};
export { messageCreate };