generated from nhcarrigan/template
refactor: consolidate modal routing and use LabelBuilder for modal components
Merges modalInteractionCreate into interactionCreate, and replaces ActionRowBuilder with LabelBuilder for the announcement modal components.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
LabelBuilder,
|
||||
ModalBuilder,
|
||||
StringSelectMenuBuilder,
|
||||
TextInputBuilder,
|
||||
@@ -37,8 +37,6 @@ export const announcement: Command = async(_hikari, interaction) => {
|
||||
|
||||
const contentInput = new TextInputBuilder().
|
||||
setCustomId("content").
|
||||
// eslint-disable-next-line deprecation/deprecation -- No V2 equivalent exists for modal text input labels
|
||||
setLabel("Announcement Copy").
|
||||
setStyle(TextInputStyle.Paragraph).
|
||||
setMaxLength(4000).
|
||||
setRequired(true);
|
||||
@@ -52,13 +50,18 @@ export const announcement: Command = async(_hikari, interaction) => {
|
||||
{ label: "Company", value: "company" },
|
||||
]);
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation -- No V2 equivalent exists for modal component rows
|
||||
modal.addComponents(
|
||||
new ActionRowBuilder<TextInputBuilder>().addComponents(contentInput),
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- discord.js types don't yet reflect select menus in modals, but they're supported at the API level
|
||||
new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
|
||||
categorySelect,
|
||||
) as unknown as ActionRowBuilder<TextInputBuilder>,
|
||||
const contentLabel = new LabelBuilder().setLabel("Announcement Copy").
|
||||
setDescription(
|
||||
"Your version of the announcement, to send to the AI for processing.",
|
||||
).
|
||||
setTextInputComponent(contentInput);
|
||||
const categoryLabel = new LabelBuilder().setLabel("Announcement Category").
|
||||
setDescription("The category of the announcement.").
|
||||
setStringSelectMenuComponent(categorySelect);
|
||||
|
||||
modal.addLabelComponents(
|
||||
contentLabel,
|
||||
categoryLabel,
|
||||
);
|
||||
|
||||
await interaction.showModal(modal);
|
||||
|
||||
@@ -6,9 +6,14 @@
|
||||
import { about } from "../commands/about.js";
|
||||
import { announcement } from "../commands/announcement.js";
|
||||
import { dm } from "../commands/dm.js";
|
||||
import { handleAnnouncementModal } from "../modules/handleAnnouncementModal.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type { Command } from "../interfaces/command.js";
|
||||
import type { ChatInputCommandInteraction, Client } from "discord.js";
|
||||
import type {
|
||||
ModalSubmitInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
Client,
|
||||
} from "discord.js";
|
||||
|
||||
const handlers: { _default: Command } & Record<string, Command> = {
|
||||
_default: async(_, interaction): Promise<void> => {
|
||||
@@ -41,4 +46,18 @@ const chatInputInteractionCreate = async(
|
||||
});
|
||||
};
|
||||
|
||||
export { chatInputInteractionCreate };
|
||||
/**
|
||||
* Routes a modal submit interaction to the appropriate handler.
|
||||
* @param _hikari - Hikari's Discord instance (unused).
|
||||
* @param interaction - The modal submit interaction payload from Discord.
|
||||
*/
|
||||
const modalSubmitInteractionCreate = async(
|
||||
_hikari: Client,
|
||||
interaction: ModalSubmitInteraction,
|
||||
): Promise<void> => {
|
||||
if (interaction.customId === "announcement_modal") {
|
||||
await handleAnnouncementModal(interaction);
|
||||
}
|
||||
};
|
||||
|
||||
export { chatInputInteractionCreate, modalSubmitInteractionCreate };
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { handleAnnouncementModal } from "../modules/handleAnnouncementModal.js";
|
||||
import type { Client, ModalSubmitInteraction } from "discord.js";
|
||||
|
||||
/**
|
||||
* Routes a modal submit interaction to the appropriate handler.
|
||||
* @param _hikari - Hikari's Discord instance (unused).
|
||||
* @param interaction - The modal submit interaction payload from Discord.
|
||||
*/
|
||||
const modalSubmitInteractionCreate = async(
|
||||
_hikari: Client,
|
||||
interaction: ModalSubmitInteraction,
|
||||
): Promise<void> => {
|
||||
if (interaction.customId === "announcement_modal") {
|
||||
await handleAnnouncementModal(interaction);
|
||||
}
|
||||
};
|
||||
|
||||
export { modalSubmitInteractionCreate };
|
||||
+2
-2
@@ -6,10 +6,10 @@
|
||||
|
||||
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
||||
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
||||
import { chatInputInteractionCreate } from "./events/interactionCreate.js";
|
||||
import {
|
||||
chatInputInteractionCreate,
|
||||
modalSubmitInteractionCreate,
|
||||
} from "./events/modalInteractionCreate.js";
|
||||
} from "./events/interactionCreate.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user