feat: add three optional content fields to announcement modal
Node.js CI / CI (pull_request) Successful in 1m41s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 2m0s

This commit is contained in:
2026-03-23 15:06:08 -07:00
committed by Naomi Carrigan
parent 0db0d220cc
commit 1c4bc9ca03
2 changed files with 54 additions and 9 deletions
+34
View File
@@ -21,6 +21,7 @@ import type { Command } from "../interfaces/command.js";
* @param _hikari - Hikari's Discord instance (unused). * @param _hikari - Hikari's Discord instance (unused).
* @param interaction - The command interaction payload from Discord. * @param interaction - The command interaction payload from Discord.
*/ */
// eslint-disable-next-line max-lines-per-function -- Modal requires many input components
export const announcement: Command = async(_hikari, interaction) => { export const announcement: Command = async(_hikari, interaction) => {
try { try {
if (!entitledUsers.includes(interaction.user.id)) { if (!entitledUsers.includes(interaction.user.id)) {
@@ -41,6 +42,24 @@ export const announcement: Command = async(_hikari, interaction) => {
setMaxLength(4000). setMaxLength(4000).
setRequired(true); setRequired(true);
const contentInput2 = new TextInputBuilder().
setCustomId("content_2").
setStyle(TextInputStyle.Paragraph).
setMaxLength(4000).
setRequired(false);
const contentInput3 = new TextInputBuilder().
setCustomId("content_3").
setStyle(TextInputStyle.Paragraph).
setMaxLength(4000).
setRequired(false);
const contentInput4 = new TextInputBuilder().
setCustomId("content_4").
setStyle(TextInputStyle.Paragraph).
setMaxLength(4000).
setRequired(false);
const categorySelect = new StringSelectMenuBuilder(). const categorySelect = new StringSelectMenuBuilder().
setCustomId("category"). setCustomId("category").
setPlaceholder("Select a category"). setPlaceholder("Select a category").
@@ -55,12 +74,27 @@ export const announcement: Command = async(_hikari, interaction) => {
"Your version of the announcement, to send to the AI for processing.", "Your version of the announcement, to send to the AI for processing.",
). ).
setTextInputComponent(contentInput); setTextInputComponent(contentInput);
// eslint-disable-next-line stylistic/max-len -- Label chain exceeds line length limit
const contentLabel2 = new LabelBuilder().setLabel("Additional Copy (Part 2)").
setDescription("Optional continuation of your announcement copy.").
setTextInputComponent(contentInput2);
// eslint-disable-next-line stylistic/max-len -- Label chain exceeds line length limit
const contentLabel3 = new LabelBuilder().setLabel("Additional Copy (Part 3)").
setDescription("Optional continuation of your announcement copy.").
setTextInputComponent(contentInput3);
// eslint-disable-next-line stylistic/max-len -- Label chain exceeds line length limit
const contentLabel4 = new LabelBuilder().setLabel("Additional Copy (Part 4)").
setDescription("Optional continuation of your announcement copy.").
setTextInputComponent(contentInput4);
const categoryLabel = new LabelBuilder().setLabel("Announcement Category"). const categoryLabel = new LabelBuilder().setLabel("Announcement Category").
setDescription("The category of the announcement."). setDescription("The category of the announcement.").
setStringSelectMenuComponent(categorySelect); setStringSelectMenuComponent(categorySelect);
modal.addLabelComponents( modal.addLabelComponents(
contentLabel, contentLabel,
contentLabel2,
contentLabel3,
contentLabel4,
categoryLabel, categoryLabel,
); );
+20 -9
View File
@@ -87,26 +87,37 @@ const buildAnnouncementFiles = (rawPost: RawPost): Array<AttachmentBuilder> => {
* to the owner's DMs, and replies ephemerally with the platform recap. * to the owner's DMs, and replies ephemerally with the platform recap.
* @param interaction - The modal submit interaction payload from Discord. * @param interaction - The modal submit interaction payload from Discord.
*/ */
// eslint-disable-next-line max-lines-per-function -- This is a big function.
export const handleAnnouncementModal = async( export const handleAnnouncementModal = async(
interaction: ModalSubmitInteraction, interaction: ModalSubmitInteraction,
): Promise<void> => { ): Promise<void> => {
try { try {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
const content = interaction.fields.getTextInputValue("content"); const content = [
interaction.fields.getTextInputValue("content"),
interaction.fields.getTextInputValue("content_2"),
interaction.fields.getTextInputValue("content_3"),
interaction.fields.getTextInputValue("content_4"),
].filter((part) => {
return part.length > 0;
}).join("\n\n");
const categoryValues = interaction.fields.getStringSelectValues("category"); const categoryValues = interaction.fields.getStringSelectValues("category");
const type = categoryValues[0] ?? "company"; const type = categoryValues[0] ?? "company";
const response = await fetch("https://hikari.nhcarrigan.com/api/announcement", { const response = await fetch(
body: JSON.stringify({ content, type }), "https://hikari.nhcarrigan.com/api/announcement",
headers: { {
body: JSON.stringify({ content, type }),
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention -- HTTP header capitalisation convention // eslint-disable-next-line @typescript-eslint/naming-convention -- HTTP header capitalisation convention
"Authorization": process.env.ANNOUNCEMENT_TOKEN ?? "", "Authorization": process.env.ANNOUNCEMENT_TOKEN ?? "",
// eslint-disable-next-line @typescript-eslint/naming-convention -- HTTP header naming convention // eslint-disable-next-line @typescript-eslint/naming-convention -- HTTP header naming convention
"Content-Type": "application/json", "Content-Type": "application/json",
},
method: "POST",
}, },
method: "POST", );
});
if (!response.ok) { if (!response.ok) {
await interaction.editReply({ await interaction.editReply({