(modals): Implement add-note-modal modal.

This commit is contained in:
2026-10-14 13:36:55 +08:00
parent 920fc347fb
commit 0fbb8918dc
+25 -27
View File
@@ -1,40 +1,38 @@
import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js';
import { Client, ModalSubmitInteraction } from 'discord.js';
import { Database } from '../shared/Database';
import { logCustomEvent } from '../utils';
import { deferInteraction, logCustomEvent } from '../utils';
import { Modal } from '../types';
export default {
name: 'add-note-modal',
handler: async function (client: Client, interaction: ModalSubmitInteraction, id: string) {
class AddNoteModal implements Modal<Client> {
id = 'add-note-modal';
async execute(context: Client<boolean>, interaction: ModalSubmitInteraction, id: string): Promise<void> {
if (!interaction.inGuild()) return;
await deferInteraction(interaction);
try {
const message = interaction.fields.getTextInputValue('note-message');
const guild = await context.guilds.fetch(interaction.guildId);
const user = await context.users.fetch(id);
const user = await client.users.fetch(id);
logCustomEvent(interaction.guild!, {
await logCustomEvent(guild, {
title: 'Note Added',
description: null,
color: 0x00FF00,
timestamp: new Date(),
fields: [
{
name: 'Moderator',
value: `<@${interaction.user.id}>\n${interaction.user.username}`,
inline: true
},
{
name: 'User',
value: `<@${id}>\n${user.username}`,
inline: true
},
{
name: 'Note',
value: message,
inline: true
}
]
{ name: 'Moderator', value: `${interaction.user} (${interaction.user.id})`, inline: false },
{ name: 'User', value: `${user.username} (${user.id})`, inline: false },
{ name: 'Note', value: message, inline: false },
],
});
await Database.putNote(id, message, interaction.user.id);
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Note added' });
await interaction.editReply({ content: 'Note added.' });
} catch (error: Error | any) {
await interaction.editReply({ content: error.message }).catch(() => {});
}
};
}
}
export default new AddNoteModal();