diff --git a/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts b/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts index 9ad7e6b..fa59926 100644 --- a/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts +++ b/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts @@ -9,37 +9,25 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => { if (store.timerActive) { // Timer is already active, so we try to start the force timer - if (store.forceTimerMs) { + if (store.forceTimerMs && !store.forceTimerActive) { // Force timer isn't active, so we start it - if (!store.forceTimerActive) { - logger.debug( - `Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`, - ) + logger.debug( + `Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`, + ) - // Clear the timer - clearTimeout(store.timer) - store.timerActive = false + // Clear the timer + clearTimeout(store.timer) + store.timerActive = false - // (Re)start the force timer - store.forceTimerActive = true - if (!store.forceTimer) - store.forceTimer = setTimeout( - () => - store.send(true).then(() => { - store.forceTimerActive = false - }), - store.forceTimerMs, - ) as NodeJS.Timeout - else store.forceTimer.refresh() - } else { - // Force timer is already active, so we clear the force timer - store.forceTimerActive = false - clearTimeout(store.forceTimer) - // and force send - store.send(true) - } + // Start the force timer + store.forceTimerActive = true + // biome-ignore lint/suspicious/noAssignInExpressions: This works fine + ;(store.forceTimer ??= setTimeout(store.send, store.forceTimerMs)).refresh() } - } else if (!store.forceTimerActive) { + } else if (store.forceTimerActive) { + // Force timer is already active, so force send the message, and clear the force timer + store.send(true) + } else { // Both timers aren't active, so we start the timer store.timerActive = true if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout diff --git a/bots/discord/src/events/discord/ready.ts b/bots/discord/src/events/discord/ready.ts index 6d54ab8..05122b2 100644 --- a/bots/discord/src/events/discord/ready.ts +++ b/bots/discord/src/events/discord/ready.ts @@ -45,11 +45,11 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie if (!forced) logger.debug( - `Timeout ended for sticky message in channel ${channelId} in guild ${guildId}, channel is inactive`, + `Timer ended for sticky message in channel ${channelId} in guild ${guildId}, channel is inactive`, ) else logger.debug( - `Forced send timeout for sticky message in channel ${channelId} in guild ${guildId} ended, channel is too active`, + `Force timer for sticky message in channel ${channelId} in guild ${guildId} hasn't ended but a message was sent, channel is too active`, ) logger.debug(`Sent sticky message to channel ${channelId} in guild ${guildId}`)