From c971ca3e3d6c1dea88fdc48ce10e787cbdb67a86 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 13 Feb 2026 19:31:28 +1300 Subject: [PATCH] Use radios/checkboxes for poll voting modal --- src/discord/interactions/poll.js | 20 +++++++------------- src/discord/register-interactions.js | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/discord/interactions/poll.js b/src/discord/interactions/poll.js index 0a4689d..6d7a015 100644 --- a/src/discord/interactions/poll.js +++ b/src/discord/interactions/poll.js @@ -43,7 +43,8 @@ async function* _interact({data, message, member, user}, {api}) { default: alreadySelected.includes(option.matrix_option) })) const checkboxGroupExtras = maxSelections === 1 && options.length > 1 ? {} : { - type: 22, // DiscordTypes.ComponentType.CheckboxGroup + /** @type {DiscordTypes.ComponentType.CheckboxGroup} */ + type: DiscordTypes.ComponentType.CheckboxGroup, min_values: 0, max_values: maxSelections } @@ -58,20 +59,12 @@ async function* _interact({data, message, member, user}, {api}) { }, { type: DiscordTypes.ComponentType.Label, label: pollRow.question_text, - component: /* { - type: 21, // DiscordTypes.ComponentType.RadioGroup + component: { + type: DiscordTypes.ComponentType.RadioGroup, custom_id: "POLL_MODAL_SELECTION", options, required: false, ...checkboxGroupExtras - } */ - { - type: DiscordTypes.ComponentType.StringSelect, - custom_id: "POLL_MODAL_SELECTION", - options, - required: false, - min_values: 0, - max_values: maxSelections, } }] } @@ -80,14 +73,15 @@ async function* _interact({data, message, member, user}, {api}) { if (data.custom_id === "POLL_MODAL") { // Clicked options via modal - /** @type {DiscordTypes.APIMessageStringSelectInteractionData} */ // @ts-ignore - close enough to the real thing + /** @type {DiscordTypes.APIModalSubmitRadioGroupComponent | DiscordTypes.APIModalSubmitCheckboxGroupComponent} */ // @ts-ignore - close enough to the real thing const component = data.components[1].component assert.equal(component.custom_id, "POLL_MODAL_SELECTION") + const values = "values" in component ? component.values : [component.value] // Replace votes with selection db.transaction(() => { db.prepare("DELETE FROM poll_vote WHERE message_id = ? AND discord_or_matrix_user_id = ?").run(message.id, userID) - for (const option of component.values) { + for (const option of values) { db.prepare("INSERT OR IGNORE INTO poll_vote (discord_or_matrix_user_id, message_id, matrix_option) VALUES (?, ?, ?)").run(userID, message.id, option) } })() diff --git a/src/discord/register-interactions.js b/src/discord/register-interactions.js index 46a7360..e3d58c4 100644 --- a/src/discord/register-interactions.js +++ b/src/discord/register-interactions.js @@ -113,7 +113,7 @@ async function dispatchInteraction(interaction) { } else if (interactionId === "Responses") { /** @type {DiscordTypes.APIMessageApplicationCommandGuildInteraction} */ // @ts-ignore const messageInteraction = interaction - if (messageInteraction.data.resolved.messages[messageInteraction.data.target_id]?.poll) { + if (select("poll", "message_id", {message_id: messageInteraction.data.target_id}).get()) { await pollResponses.interact(messageInteraction) } else { await reactions.interact(messageInteraction)