Skip to content

Commit c8b3d9b

Browse files
committed
Queue Reference Upkeep module
1 parent 770fbf3 commit c8b3d9b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/events/queueReferenceUpkeep.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { isEmpty, isNil } from 'ramda'
2+
import { Bot } from '../bot'
3+
import { BotEvent } from '../types'
4+
5+
const botEvent: BotEvent = {
6+
name: 'Queue Reference Upkeep',
7+
event: 'ready',
8+
once: true,
9+
execute(bot: Bot) {
10+
bot.log.debug('Queue Reference Upkeep init')
11+
setInterval(async () => await tick(bot), 1000)
12+
}
13+
}
14+
15+
let tickLock = false
16+
async function tick(bot: Bot) {
17+
if (isNil(bot.queueItemReferences) || isEmpty(bot.queueItemReferences)) return
18+
if (bot.queueItemReferences.length <= 20) return
19+
tickLock = true
20+
bot.log.debug('Removing oldest entry from queue references..')
21+
22+
try {
23+
const oldestQueueItem = bot.queueItemReferences[0]
24+
bot.removeQueueItemReference(oldestQueueItem.uuid)
25+
tickLock = false
26+
// @ts-ignore no-implicit-any
27+
} catch(e: any) {
28+
bot.log.error(e.toString())
29+
bot.log.error(e.stack)
30+
tickLock = false
31+
}
32+
}
33+
34+
export default botEvent

0 commit comments

Comments
 (0)