mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(bots/discord): attempt to fix stuck sticky message timeouts
This commit is contained in:
@@ -7,41 +7,8 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
|
||||
const store = discord.stickyMessages[msg.guildId]?.[msg.channelId]
|
||||
if (!store) return
|
||||
|
||||
// TODO: Fix this by fixing the logic below
|
||||
if (store.timerActive && store.forceTimerActive) {
|
||||
logger.error(
|
||||
`Both timers are active in sticky message store: ${msg.guildId}.${msg.channelId}, this should not happen!`,
|
||||
)
|
||||
logger.info('Clearing the timer and the restarting the force timer...')
|
||||
clearTimeout(store.timer)
|
||||
store.timerActive = false
|
||||
// If the force timer is active, it implies the force timer exists
|
||||
store.forceTimer!.refresh()
|
||||
}
|
||||
|
||||
const timerPreviouslyActive = store.timerActive
|
||||
// If there isn't a timer, start it up
|
||||
store.timerActive = true
|
||||
if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout
|
||||
else {
|
||||
/*
|
||||
If:
|
||||
- (negate carried) There's a timer
|
||||
- The timer is not active
|
||||
- The force timer is not active
|
||||
Then:
|
||||
- Restart the timer
|
||||
*/
|
||||
if (!timerPreviouslyActive && !store.forceTimerActive) store.timer.refresh()
|
||||
/*
|
||||
If:
|
||||
- Any of:
|
||||
- (negate carried) The timer is active
|
||||
- (negate carried) The force timer is active
|
||||
- The force timer is not active
|
||||
Then:
|
||||
- Start the force timer and clear the existing timer
|
||||
*/ else if (!store.forceTimerActive && store.forceTimerMs) {
|
||||
if (store.timerActive) {
|
||||
if (!store.forceTimerActive && store.forceTimerMs) {
|
||||
logger.debug(
|
||||
`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`,
|
||||
)
|
||||
@@ -62,5 +29,8 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
|
||||
) as NodeJS.Timeout
|
||||
else store.forceTimer.refresh()
|
||||
}
|
||||
} else if (!store.forceTimerActive) {
|
||||
store.timerActive = true
|
||||
if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout
|
||||
}
|
||||
})
|
||||
|
||||
@@ -69,7 +69,7 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie
|
||||
timerMs: timeout,
|
||||
send,
|
||||
// If the store exists before the configuration refresh, take its current message
|
||||
currentMessage: oldStore?.[channelId]?.currentMessage
|
||||
currentMessage: oldStore?.[channelId]?.currentMessage,
|
||||
}
|
||||
|
||||
// Send a new sticky message immediately, as well as deleting the old/outdated message, if it exists
|
||||
|
||||
Reference in New Issue
Block a user