fix: correct announcement API endpoint and add optional content fields #20

Merged
naomi merged 4 commits from fix/announce into main 2026-03-23 15:59:42 -07:00
4 changed files with 62 additions and 17 deletions
+36 -2
View File
@@ -11,7 +11,7 @@ import {
TextInputBuilder, TextInputBuilder,
TextInputStyle, TextInputStyle,
} from "discord.js"; } from "discord.js";
import { entitledUsers } from "../config/entitlements.js"; import { naomiId } from "../config/entitlements.js";
import { errorHandler } from "../utils/errorHandler.js"; import { errorHandler } from "../utils/errorHandler.js";
import type { Command } from "../interfaces/command.js"; import type { Command } from "../interfaces/command.js";
@@ -21,9 +21,10 @@ 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 (interaction.user.id !== naomiId) {
await interaction.reply({ await interaction.reply({
content: "This command is restricted to the owner.", content: "This command is restricted to the owner.",
ephemeral: true, ephemeral: true,
@@ -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,
); );
+4 -4
View File
@@ -3,12 +3,12 @@
* @license Naomi's Public License * @license Naomi's Public License
* @author Naomi Carrigan * @author Naomi Carrigan
*/ */
const naomiId = "465650873650118659";
const entitledGuilds = [ const entitledGuilds = [
"1354624415861833870", "1354624415861833870",
]; ];
const entitledUsers = [ const entitledUsers = [ naomiId ];
"465650873650118659",
];
export { entitledGuilds, entitledUsers }; export { entitledGuilds, entitledUsers, naomiId };
+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/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({
+2 -2
View File
@@ -4,7 +4,7 @@
* @author Naomi Carrigan * @author Naomi Carrigan
*/ */
import { entitledGuilds, entitledUsers } from "../config/entitlements.js"; import { entitledGuilds, naomiId } from "../config/entitlements.js";
import type { Client, Guild, User } from "discord.js"; import type { Client, Guild, User } from "discord.js";
/** /**
@@ -17,7 +17,7 @@ const checkUserEntitlement = async(
hikari: Client, hikari: Client,
user: User, user: User,
): Promise<boolean> => { ): Promise<boolean> => {
if (entitledUsers.includes(user.id)) { if (user.id === naomiId) {
return true; return true;
} }
const entitlements = await hikari.application?.entitlements.fetch({ const entitlements = await hikari.application?.entitlements.fetch({