File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments