Rename poll files a bit better

This commit is contained in:
Cadence Ember
2026-01-26 02:35:58 +13:00
parent 90606d9176
commit f3ae7ba792
5 changed files with 14 additions and 14 deletions
@@ -13,8 +13,8 @@ const api = sync.require("../../matrix/api")
const registerUser = sync.require("./register-user") const registerUser = sync.require("./register-user")
/** @type {import("./create-room")} */ /** @type {import("./create-room")} */
const createRoom = sync.require("../actions/create-room") const createRoom = sync.require("../actions/create-room")
/** @type {import("./add-or-remove-vote.js")} */ /** @type {import("./poll-vote")} */
const vote = sync.require("../actions/add-or-remove-vote") const vote = sync.require("../actions/poll-vote")
/** @type {import("../../m2d/converters/poll-components")} */ /** @type {import("../../m2d/converters/poll-components")} */
const pollComponents = sync.require("../../m2d/converters/poll-components") const pollComponents = sync.require("../../m2d/converters/poll-components")
/** @type {import("../../m2d/actions/channel-webhook")} */ /** @type {import("../../m2d/actions/channel-webhook")} */
@@ -64,7 +64,7 @@ async function getAllVotesOnAnswer(channelID, messageID, answerID){
* @param {typeof import("../../../test/data.js")["poll_close"]} closeMessage * @param {typeof import("../../../test/data.js")["poll_close"]} closeMessage
* @param {DiscordTypes.APIGuild} guild * @param {DiscordTypes.APIGuild} guild
*/ */
async function closePoll(closeMessage, guild){ async function endPoll(closeMessage, guild){
const pollCloseObject = closeMessage.embeds[0] const pollCloseObject = closeMessage.embeds[0]
const pollMessageID = closeMessage.message_reference.message_id const pollMessageID = closeMessage.message_reference.message_id
@@ -148,4 +148,4 @@ async function closePoll(closeMessage, guild){
} }
} }
module.exports.closePoll = closePoll module.exports.endPoll = endPoll
+3 -3
View File
@@ -17,8 +17,8 @@ const registerPkUser = sync.require("./register-pk-user")
const registerWebhookUser = sync.require("./register-webhook-user") const registerWebhookUser = sync.require("./register-webhook-user")
/** @type {import("../actions/create-room")} */ /** @type {import("../actions/create-room")} */
const createRoom = sync.require("../actions/create-room") const createRoom = sync.require("../actions/create-room")
/** @type {import("../actions/close-poll")} */ /** @type {import("../actions/poll-end")} */
const closePoll = sync.require("../actions/close-poll") const pollEnd = sync.require("../actions/poll-end")
/** @type {import("../../discord/utils")} */ /** @type {import("../../discord/utils")} */
const dUtils = sync.require("../../discord/utils") const dUtils = sync.require("../../discord/utils")
/** @type {import("../../m2d/actions/channel-webhook")} */ /** @type {import("../../m2d/actions/channel-webhook")} */
@@ -103,7 +103,7 @@ async function sendMessage(message, channel, guild, row) {
} }
if (message.type === DiscordTypes.MessageType.PollResult) { // We might need to send a message to Discord (if there were any Matrix-side votes). if (message.type === DiscordTypes.MessageType.PollResult) { // We might need to send a message to Discord (if there were any Matrix-side votes).
const detailedResultsMessage = await closePoll.closePoll(message, guild) const detailedResultsMessage = await pollEnd.endPoll(message, guild)
if (detailedResultsMessage) { if (detailedResultsMessage) {
const threadParent = select("channel_room", "thread_parent", {channel_id: message.channel_id}).pluck().get() const threadParent = select("channel_room", "thread_parent", {channel_id: message.channel_id}).pluck().get()
const channelID = threadParent ? threadParent : message.channel_id const channelID = threadParent ? threadParent : message.channel_id
+2 -2
View File
@@ -32,8 +32,8 @@ const speedbump = sync.require("./actions/speedbump")
const retrigger = sync.require("./actions/retrigger") const retrigger = sync.require("./actions/retrigger")
/** @type {import("./actions/set-presence")} */ /** @type {import("./actions/set-presence")} */
const setPresence = sync.require("./actions/set-presence") const setPresence = sync.require("./actions/set-presence")
/** @type {import("./actions/add-or-remove-vote")} */ /** @type {import("./actions/poll-vote")} */
const vote = sync.require("./actions/add-or-remove-vote") const vote = sync.require("./actions/poll-vote")
/** @type {import("../m2d/event-dispatcher")} */ /** @type {import("../m2d/event-dispatcher")} */
const matrixEventDispatcher = sync.require("../m2d/event-dispatcher") const matrixEventDispatcher = sync.require("../m2d/event-dispatcher")
/** @type {import("../discord/interactions/matrix-info")} */ /** @type {import("../discord/interactions/matrix-info")} */
+5 -5
View File
@@ -12,8 +12,8 @@ const api = sync.require("../../matrix/api")
const utils = sync.require("../../matrix/utils") const utils = sync.require("../../matrix/utils")
/** @type {import("../../m2d/converters/poll-components")} */ /** @type {import("../../m2d/converters/poll-components")} */
const pollComponents = sync.require("../../m2d/converters/poll-components") const pollComponents = sync.require("../../m2d/converters/poll-components")
/** @type {import("../../d2m/actions/add-or-remove-vote")} */ /** @type {import("../../d2m/actions/poll-vote")} */
const vote = sync.require("../../d2m/actions/add-or-remove-vote") const vote = sync.require("../../d2m/actions/poll-vote")
/** /**
* @param {DiscordTypes.APIMessageComponentButtonInteraction} interaction * @param {DiscordTypes.APIMessageComponentButtonInteraction} interaction
@@ -34,7 +34,7 @@ async function* _interact({data, message, member, user}, {api}) {
const maxSelections = pollRow.max_selections const maxSelections = pollRow.max_selections
const alreadySelected = select("poll_vote", "matrix_option", {discord_or_matrix_user_id: userID, message_id: message.id}).pluck().all() const alreadySelected = select("poll_vote", "matrix_option", {discord_or_matrix_user_id: userID, message_id: message.id}).pluck().all()
// Show modal (if no capacity or if requested) // Show modal (if no capacity or if requested)
if (data.custom_id === "POLL_VOTE" || (maxSelections > 1 && alreadySelected.length === maxSelections)) { if (data.custom_id === "POLL_VOTE" || (maxSelections > 1 && alreadySelected.length === maxSelections)) {
const options = select("poll_option", ["matrix_option", "option_text", "seq"], {message_id: message.id}, "ORDER BY seq").all().map(option => ({ const options = select("poll_option", ["matrix_option", "option_text", "seq"], {message_id: message.id}, "ORDER BY seq").all().map(option => ({
@@ -91,7 +91,7 @@ async function* _interact({data, message, member, user}, {api}) {
db.prepare("INSERT OR IGNORE INTO poll_vote (discord_or_matrix_user_id, message_id, matrix_option) VALUES (?, ?, ?)").run(userID, message.id, option) db.prepare("INSERT OR IGNORE INTO poll_vote (discord_or_matrix_user_id, message_id, matrix_option) VALUES (?, ?, ?)").run(userID, message.id, option)
} }
})() })()
// Update counts on message // Update counts on message
yield {createInteractionResponse: { yield {createInteractionResponse: {
type: DiscordTypes.InteractionResponseType.UpdateMessage, type: DiscordTypes.InteractionResponseType.UpdateMessage,
@@ -105,7 +105,7 @@ async function* _interact({data, message, member, user}, {api}) {
const optionPrefix = "POLL_OPTION#" // we use a prefix to prevent someone from sending a Matrix poll that intentionally collides with other elements of the embed const optionPrefix = "POLL_OPTION#" // we use a prefix to prevent someone from sending a Matrix poll that intentionally collides with other elements of the embed
const matrixOption = select("poll_option", "matrix_option", {matrix_option: data.custom_id.substring(optionPrefix.length), message_id: message.id}).pluck().get() const matrixOption = select("poll_option", "matrix_option", {matrix_option: data.custom_id.substring(optionPrefix.length), message_id: message.id}).pluck().get()
assert(matrixOption) assert(matrixOption)
// Remove a vote // Remove a vote
if (alreadySelected.includes(matrixOption)) { if (alreadySelected.includes(matrixOption)) {
db.prepare("DELETE FROM poll_vote WHERE discord_or_matrix_user_id = ? AND message_id = ? AND matrix_option = ?").run(userID, message.id, matrixOption) db.prepare("DELETE FROM poll_vote WHERE discord_or_matrix_user_id = ? AND message_id = ? AND matrix_option = ?").run(userID, message.id, matrixOption)