mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(modals): Hook up modals. Pre-testing.
This commit is contained in:
+7
-8
@@ -1,6 +1,7 @@
|
|||||||
import { Client, GatewayIntentBits, MessageFlags, Partials } from 'discord.js';
|
import { Client, GatewayIntentBits, MessageFlags, ModalSubmitInteraction, Partials } from 'discord.js';
|
||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
import events from './events';
|
import events from './events';
|
||||||
|
import modals from './modals';
|
||||||
import { Database } from './shared/Database';
|
import { Database } from './shared/Database';
|
||||||
import { openRedisClient } from './shared/RedisClient';
|
import { openRedisClient } from './shared/RedisClient';
|
||||||
import { Handler } from './types';
|
import { Handler } from './types';
|
||||||
@@ -38,7 +39,6 @@ const client = new Client({
|
|||||||
const commands: Handler[] = [];
|
const commands: Handler[] = [];
|
||||||
const contextMenus: Handler[] = [];
|
const contextMenus: Handler[] = [];
|
||||||
const buttons: Handler[] = [];
|
const buttons: Handler[] = [];
|
||||||
const modals: Handler[] = [];
|
|
||||||
const menus: Handler[] = [];
|
const menus: Handler[] = [];
|
||||||
|
|
||||||
// Due to their reliance on each other, these two events (interactionCreate, and ready) have to stay here.
|
// Due to their reliance on each other, these two events (interactionCreate, and ready) have to stay here.
|
||||||
@@ -103,10 +103,11 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
const id = interaction.customId.split('_')[0];
|
const id = interaction.customId.split('_')[0];
|
||||||
|
|
||||||
for (const modal of modals) {
|
for (const modal of modals) {
|
||||||
if (id == modal.name) {
|
if (id != modal.id) continue;
|
||||||
modal.handler(client, interaction, ...interaction.customId.split('_').slice(1));
|
|
||||||
return;
|
Promise.resolve((modal.execute as (context: Client, interaction: ModalSubmitInteraction, ...args: unknown[]) => Promise<void>)(client, interaction, ...interaction.customId.split('_').slice(1))
|
||||||
}
|
.catch(e => console.error('An error occurred while handling a modal interaction: ', e)));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (interaction.isAnySelectMenu()) {
|
} else if (interaction.isAnySelectMenu()) {
|
||||||
// Handle menu selections.
|
// Handle menu selections.
|
||||||
@@ -127,14 +128,12 @@ client.on('clientReady', async () => {
|
|||||||
await loadHandlersFrom('commands', commands);
|
await loadHandlersFrom('commands', commands);
|
||||||
await loadHandlersFrom('context-menus', contextMenus);
|
await loadHandlersFrom('context-menus', contextMenus);
|
||||||
await loadHandlersFrom('buttons', buttons);
|
await loadHandlersFrom('buttons', buttons);
|
||||||
await loadHandlersFrom('modals', modals);
|
|
||||||
await loadHandlersFrom('menus', menus);
|
await loadHandlersFrom('menus', menus);
|
||||||
|
|
||||||
await refreshCommands(client);
|
await refreshCommands(client);
|
||||||
|
|
||||||
await initIfNecessary(client, commands);
|
await initIfNecessary(client, commands);
|
||||||
await initIfNecessary(client, buttons);
|
await initIfNecessary(client, buttons);
|
||||||
await initIfNecessary(client, modals);
|
|
||||||
await initIfNecessary(client, menus);
|
await initIfNecessary(client, menus);
|
||||||
|
|
||||||
Encrypter.initialize(config.DATABASE_SECRET!);
|
Encrypter.initialize(config.DATABASE_SECRET!);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import addKnowledgebaseItemModal from './addKnowledgebaseItemModal';
|
||||||
|
import addNoteModal from './addNoteModal';
|
||||||
|
import editKnowledgebaseItemModal from './editKnowledgebaseItemModal';
|
||||||
|
import openModTicket from './openModTicket';
|
||||||
|
import openTicketModal from './openTicketModal';
|
||||||
|
import reportMessage from './reportMessage';
|
||||||
|
import syncNameModal from './syncNameModal';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
addKnowledgebaseItemModal,
|
||||||
|
addNoteModal,
|
||||||
|
editKnowledgebaseItemModal,
|
||||||
|
openModTicket,
|
||||||
|
openTicketModal,
|
||||||
|
reportMessage,
|
||||||
|
syncNameModal
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user