@@ -32,7 +32,10 @@ export class PersistentTimer {
32
32
protected interval ?: NodeJS . Timeout ;
33
33
34
34
/// This constructor has side effects as it immediately starts the timer!
35
- protected constructor ( protected entity : Countdown , protected discord : PersistentTimerDiscordDelegate ) {
35
+ protected constructor (
36
+ protected entity : Countdown ,
37
+ protected discord : PersistentTimerDiscordDelegate
38
+ ) {
36
39
this . interval = setInterval ( ( ) => this . tick ( ) , 1000 ) ;
37
40
}
38
41
@@ -123,23 +126,31 @@ export class PersistentTimer {
123
126
protected async tick ( ) : Promise < void > {
124
127
const end = this . entity . end ;
125
128
const now = new Date ( ) ;
129
+ const iso = now . toISOString ( ) ;
130
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) end(${ end . toISOString ( ) } )` ) ;
126
131
if ( end <= now ) {
132
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) aborting` ) ;
127
133
await this . abort ( ) ;
128
134
try {
135
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) sending message` ) ;
129
136
await this . discord . sendMessage ( this . entity . channelId , this . entity . finalMessage ) ;
137
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) finished` ) ;
130
138
} catch ( error ) {
131
139
logger . warn ( error ) ;
132
140
}
133
141
}
134
142
const secondsRemaining = Math . ceil ( ( now . getTime ( ) - end . getTime ( ) ) / 1000 ) ;
135
- if ( secondsRemaining % this . entity . cronIntervalSeconds == 0 ) {
143
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) secondsRemaining(${ secondsRemaining } )` ) ;
144
+ if ( secondsRemaining % this . entity . cronIntervalSeconds === 0 ) {
136
145
const left = PersistentTimer . formatTime ( end . getTime ( ) - Date . now ( ) ) ;
146
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) left(${ left } )` ) ;
137
147
try {
138
148
await this . discord . editMessage (
139
149
this . entity . channelId ,
140
150
this . entity . messageId ,
141
151
`Time left in the round: \`${ left } \`. Ends ${ time ( end ) } (${ time ( end , "R" ) } ).`
142
152
) ;
153
+ logger . verbose ( `tick: ${ this . entity . id } now(${ iso } ) edited` ) ;
143
154
} catch ( error ) {
144
155
logger . warn ( `tick: could not edit ${ this . entity . channelId } ${ this . entity . messageId } ` ) ;
145
156
logger . warn ( error ) ;
0 commit comments