generated from nhcarrigan/template
This commit is contained in:
+6
-3
@@ -10,6 +10,7 @@ import {
|
||||
GatewayIntentBits,
|
||||
Events,
|
||||
} from "discord.js";
|
||||
import { processButton } from "./modules/processButton.js";
|
||||
import { processInteraction } from "./modules/processInteraction.js";
|
||||
import { processMessage } from "./server/processMessage.js";
|
||||
import { instantiateServer } from "./server/serve.js";
|
||||
@@ -36,10 +37,12 @@ caelia.on(Events.MessageCreate, (message) => {
|
||||
|
||||
caelia.on(Events.InteractionCreate, (interaction) => {
|
||||
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
|
||||
if (!interaction.isChatInputCommand()) {
|
||||
return;
|
||||
if (interaction.isChatInputCommand()) {
|
||||
void processInteraction(interaction);
|
||||
}
|
||||
if (interaction.isButton()) {
|
||||
void processButton(interaction);
|
||||
}
|
||||
void processInteraction(interaction);
|
||||
});
|
||||
|
||||
await caelia.login(process.env.BOT_TOKEN);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type {
|
||||
ButtonInteraction,
|
||||
} from "discord.js";
|
||||
|
||||
/**
|
||||
* Handles a slash command. Only responds with the about information,
|
||||
* because that's all we need.
|
||||
* @param interaction - The interaction payload from Discord.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles a button interaction. If the user is not the author of the reminder,
|
||||
* they cannot acknowledge it.
|
||||
* @param interaction - The interaction payload from Discord.
|
||||
*/
|
||||
export const processButton = async(
|
||||
interaction: ButtonInteraction,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await interaction.deferReply();
|
||||
const { customId, user, message } = interaction;
|
||||
if (customId !== user.id) {
|
||||
await interaction.reply({
|
||||
content: "You cannot acknowledge someone else's reminder.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
await message.delete();
|
||||
await interaction.editReply({
|
||||
content: "Acknowledged!",
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
await logger.error("process interaction module", error);
|
||||
}
|
||||
await interaction.editReply({
|
||||
content: "Oh dear, something went wrong.",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -62,6 +62,14 @@ export const processMessage = async(message: Message): Promise<void> => {
|
||||
},
|
||||
{
|
||||
components: [
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API
|
||||
custom_id: author.id,
|
||||
disabled: false,
|
||||
label: "Okie Dokie!",
|
||||
style: 3,
|
||||
type: 2,
|
||||
},
|
||||
{
|
||||
label: "Is this inaccurate? Let us know!",
|
||||
style: 5,
|
||||
|
||||
Reference in New Issue
Block a user