Skip to content

Commit 65288ec

Browse files
committed
fix(bots/discord): attempt to fix sticky messages one last time
1 parent a506788 commit 65288ec

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts

+15-27
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,25 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
99

1010
if (store.timerActive) {
1111
// Timer is already active, so we try to start the force timer
12-
if (store.forceTimerMs) {
12+
if (store.forceTimerMs && !store.forceTimerActive) {
1313
// Force timer isn't active, so we start it
14-
if (!store.forceTimerActive) {
15-
logger.debug(
16-
`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`,
17-
)
14+
logger.debug(
15+
`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`,
16+
)
1817

19-
// Clear the timer
20-
clearTimeout(store.timer)
21-
store.timerActive = false
18+
// Clear the timer
19+
clearTimeout(store.timer)
20+
store.timerActive = false
2221

23-
// (Re)start the force timer
24-
store.forceTimerActive = true
25-
if (!store.forceTimer)
26-
store.forceTimer = setTimeout(
27-
() =>
28-
store.send(true).then(() => {
29-
store.forceTimerActive = false
30-
}),
31-
store.forceTimerMs,
32-
) as NodeJS.Timeout
33-
else store.forceTimer.refresh()
34-
} else {
35-
// Force timer is already active, so we clear the force timer
36-
store.forceTimerActive = false
37-
clearTimeout(store.forceTimer)
38-
// and force send
39-
store.send(true)
40-
}
22+
// Start the force timer
23+
store.forceTimerActive = true
24+
// biome-ignore lint/suspicious/noAssignInExpressions: This works fine
25+
;(store.forceTimer ??= setTimeout(store.send, store.forceTimerMs)).refresh()
4126
}
42-
} else if (!store.forceTimerActive) {
27+
} else if (store.forceTimerActive) {
28+
// Force timer is already active, so force send the message, and clear the force timer
29+
store.send(true)
30+
} else {
4331
// Both timers aren't active, so we start the timer
4432
store.timerActive = true
4533
if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout

bots/discord/src/events/discord/ready.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie
4545

4646
if (!forced)
4747
logger.debug(
48-
`Timeout ended for sticky message in channel ${channelId} in guild ${guildId}, channel is inactive`,
48+
`Timer ended for sticky message in channel ${channelId} in guild ${guildId}, channel is inactive`,
4949
)
5050
else
5151
logger.debug(
52-
`Forced send timeout for sticky message in channel ${channelId} in guild ${guildId} ended, channel is too active`,
52+
`Force timer for sticky message in channel ${channelId} in guild ${guildId} hasn't ended but a message was sent, channel is too active`,
5353
)
5454

5555
logger.debug(`Sent sticky message to channel ${channelId} in guild ${guildId}`)

0 commit comments

Comments
 (0)