mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(modals): Implement add-note-modal modal.
This commit is contained in:
@@ -1,40 +1,38 @@
|
|||||||
import { Client, MessageFlags, ModalSubmitInteraction } from 'discord.js';
|
import { Client, ModalSubmitInteraction } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { logCustomEvent } from '../utils';
|
import { deferInteraction, logCustomEvent } from '../utils';
|
||||||
|
import { Modal } from '../types';
|
||||||
|
|
||||||
export default {
|
class AddNoteModal implements Modal<Client> {
|
||||||
name: 'add-note-modal',
|
id = 'add-note-modal';
|
||||||
handler: async function (client: Client, interaction: ModalSubmitInteraction, id: string) {
|
|
||||||
const message = interaction.fields.getTextInputValue('note-message');
|
|
||||||
|
|
||||||
const user = await client.users.fetch(id);
|
async execute(context: Client<boolean>, interaction: ModalSubmitInteraction, id: string): Promise<void> {
|
||||||
|
if (!interaction.inGuild()) return;
|
||||||
|
await deferInteraction(interaction);
|
||||||
|
|
||||||
logCustomEvent(interaction.guild!, {
|
try {
|
||||||
title: 'Note Added',
|
const message = interaction.fields.getTextInputValue('note-message');
|
||||||
description: null,
|
const guild = await context.guilds.fetch(interaction.guildId);
|
||||||
color: 0x00FF00,
|
const user = await context.users.fetch(id);
|
||||||
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
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
await Database.putNote(id, message, interaction.user.id);
|
await logCustomEvent(guild, {
|
||||||
|
title: 'Note Added',
|
||||||
|
description: null,
|
||||||
|
color: 0x00FF00,
|
||||||
|
timestamp: new Date(),
|
||||||
|
fields: [
|
||||||
|
{ 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 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Note added' });
|
await Database.putNote(id, message, interaction.user.id);
|
||||||
|
await interaction.editReply({ content: 'Note added.' });
|
||||||
|
} catch (error: Error | any) {
|
||||||
|
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export default new AddNoteModal();
|
||||||
Reference in New Issue
Block a user