fix(bots/discord): attempt to fix sticky messages one last time

This commit is contained in:
PalmDevs
2025-04-09 21:00:28 +07:00
parent a5067889b2
commit 65288ec424
2 changed files with 17 additions and 29 deletions

View File

@@ -9,9 +9,8 @@ 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`,
)
@@ -20,26 +19,15 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
clearTimeout(store.timer)
store.timerActive = false
// (Re)start the force timer
// 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
// biome-ignore lint/suspicious/noAssignInExpressions: This works fine
;(store.forceTimer ??= setTimeout(store.send, store.forceTimerMs)).refresh()
}
} else if (store.forceTimerActive) {
// Force timer is already active, so force send the message, and clear the force timer
store.send(true)
}
}
} else if (!store.forceTimerActive) {
} 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

View File

@@ -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}`)