diff --git a/packages/bot/src/utils/errors.ts b/packages/bot/src/utils/errors.ts new file mode 100644 index 0000000..02f483b --- /dev/null +++ b/packages/bot/src/utils/errors.ts @@ -0,0 +1,18 @@ +// rome-ignore lint/suspicious/noExplicitAny: +type RecursiveError = Record; + +export function parseErrors( + obj: RecursiveError, +): { code: string; message: string }[] { + const errors = []; + + for (const key in obj) { + if (key === "_errors") { + errors.push(obj[key]); + } else if (typeof obj[key] === "object") { + errors.push(...parseErrors(obj[key])); + } + } + + return errors.flat(); +} diff --git a/packages/bot/src/utils/returnRoleLpe.ts b/packages/bot/src/utils/returnRoleLpe.ts index abd7804..ab6fc96 100644 --- a/packages/bot/src/utils/returnRoleLpe.ts +++ b/packages/bot/src/utils/returnRoleLpe.ts @@ -34,6 +34,7 @@ export default async function (data: BasicData, ctx: Context, rawRole: string) { new TextInputBuilder() .setLabel("Label") .setCustomId("label") + .setMaxLength(data.selecting === "buttons" ? 80 : 100) .setPlaceholder("Ping") .setStyle(TextInputStyle.Short) .setRequired(true), @@ -75,6 +76,7 @@ export default async function (data: BasicData, ctx: Context, rawRole: string) { new TextInputBuilder() .setLabel("Description") .setCustomId("description") + .setMaxLength(100) .setPlaceholder("pingping pong pong") .setStyle(TextInputStyle.Short) .setRequired(false), diff --git a/packages/bot/src/utils/sendFinal.ts b/packages/bot/src/utils/sendFinal.ts index 4312037..e02afa2 100644 --- a/packages/bot/src/utils/sendFinal.ts +++ b/packages/bot/src/utils/sendFinal.ts @@ -21,6 +21,7 @@ import splitArray from "./splitArray"; import { resolvePartialEmoji } from "./resolveEmoji"; import { BasicData } from "../types"; import resolveButtonStyle from "./resolveButtonStyle"; +import { parseErrors } from "./errors"; type DataBot = BasicData & { sendAs: "bot"; @@ -66,7 +67,9 @@ export default async function (ctx: Context, data: Data) { const components: APIActionRowComponent[] = []; const array = splitArray(data.roleIds, data.selecting === "buttons" ? 5 : 24); for (const items of array) { - const actionRow = new ActionRowBuilder(); + const actionRow = new ActionRowBuilder< + ButtonBuilder | StringSelectMenuBuilder + >(); const selectMenuNaiveOption = new StringSelectMenuOptionBuilder() .setLabel("Make a choice") @@ -113,8 +116,7 @@ export default async function (ctx: Context, data: Data) { if (data.selecting === "dropdowns") actionRow.addComponents(selectMenu); - // @ts-expect-error i know i know - components.push(actionRow); + components.push(actionRow.toJSON()); } payload.components = components; @@ -152,11 +154,23 @@ export default async function (ctx: Context, data: Data) { } if (!res.ok) { - const json: { message: string; code: string } = await res.json(); + const json: { + message: string; + code: string; + errors: Record; + } = await res.json(); + const errors = parseErrors(json?.errors ?? {}); + return ctx.respond({ type: InteractionResponseType.ChannelMessageWithSource, data: { - content: `Error: ${json.message} (${json.code})`, + content: `Error: ${json.message} (${json.code})${ + errors.length > 0 + ? `\n${errors + .map((e) => ` - ${e.message} (${e.code})`) + .join("\n")}` + : "" + }`, flags: MessageFlags.Ephemeral, }, }); @@ -200,11 +214,23 @@ export default async function (ctx: Context, data: Data) { ); if (!res.ok) { - const json: { message: string; code: string } = await res.json(); + const json: { + message: string; + code: string; + errors: Record; + } = await res.json(); + const errors = parseErrors(json?.errors ?? {}); + return ctx.respond({ type: InteractionResponseType.ChannelMessageWithSource, data: { - content: `Error: ${json.message} (${json.code})`, + content: `Error: ${json.message} (${json.code})${ + errors.length > 0 + ? `\n${errors + .map((e) => ` - ${e.message} (${e.code})`) + .join("\n")}` + : "" + }`, flags: MessageFlags.Ephemeral, }, });