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 {
|
import {
|
||||||
ActionRowBuilder,
|
LabelBuilder,
|
||||||
ModalBuilder,
|
ModalBuilder,
|
||||||
StringSelectMenuBuilder,
|
StringSelectMenuBuilder,
|
||||||
TextInputBuilder,
|
TextInputBuilder,
|
||||||
@@ -37,8 +37,6 @@ export const announcement: Command = async(_hikari, interaction) => {
|
|||||||
|
|
||||||
const contentInput = new TextInputBuilder().
|
const contentInput = new TextInputBuilder().
|
||||||
setCustomId("content").
|
setCustomId("content").
|
||||||
// eslint-disable-next-line deprecation/deprecation -- No V2 equivalent exists for modal text input labels
|
|
||||||
setLabel("Announcement Copy").
|
|
||||||
setStyle(TextInputStyle.Paragraph).
|
setStyle(TextInputStyle.Paragraph).
|
||||||
setMaxLength(4000).
|
setMaxLength(4000).
|
||||||
setRequired(true);
|
setRequired(true);
|
||||||
@@ -52,13 +50,18 @@ export const announcement: Command = async(_hikari, interaction) => {
|
|||||||
{ label: "Company", value: "company" },
|
{ label: "Company", value: "company" },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// eslint-disable-next-line deprecation/deprecation -- No V2 equivalent exists for modal component rows
|
const contentLabel = new LabelBuilder().setLabel("Announcement Copy").
|
||||||
modal.addComponents(
|
setDescription(
|
||||||
new ActionRowBuilder<TextInputBuilder>().addComponents(contentInput),
|
"Your version of the announcement, to send to the AI for processing.",
|
||||||
// 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(
|
setTextInputComponent(contentInput);
|
||||||
categorySelect,
|
const categoryLabel = new LabelBuilder().setLabel("Announcement Category").
|
||||||
) as unknown as ActionRowBuilder<TextInputBuilder>,
|
setDescription("The category of the announcement.").
|
||||||
|
setStringSelectMenuComponent(categorySelect);
|
||||||
|
|
||||||
|
modal.addLabelComponents(
|
||||||
|
contentLabel,
|
||||||
|
categoryLabel,
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.showModal(modal);
|
await interaction.showModal(modal);
|
||||||
|
|||||||
@@ -6,9 +6,14 @@
|
|||||||
import { about } from "../commands/about.js";
|
import { about } from "../commands/about.js";
|
||||||
import { announcement } from "../commands/announcement.js";
|
import { announcement } from "../commands/announcement.js";
|
||||||
import { dm } from "../commands/dm.js";
|
import { dm } from "../commands/dm.js";
|
||||||
|
import { handleAnnouncementModal } from "../modules/handleAnnouncementModal.js";
|
||||||
import { logger } from "../utils/logger.js";
|
import { logger } from "../utils/logger.js";
|
||||||
import type { Command } from "../interfaces/command.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> = {
|
const handlers: { _default: Command } & Record<string, Command> = {
|
||||||
_default: async(_, interaction): Promise<void> => {
|
_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 { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
||||||
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
||||||
import { chatInputInteractionCreate } from "./events/interactionCreate.js";
|
|
||||||
import {
|
import {
|
||||||
|
chatInputInteractionCreate,
|
||||||
modalSubmitInteractionCreate,
|
modalSubmitInteractionCreate,
|
||||||
} from "./events/modalInteractionCreate.js";
|
} from "./events/interactionCreate.js";
|
||||||
import { logger } from "./utils/logger.js";
|
import { logger } from "./utils/logger.js";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user