File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,11 @@ class Bot {
146
146
delete this . channelUsers [ channel ] ;
147
147
return ;
148
148
}
149
- this . channelUsers [ channel ] . delete ( nick ) ;
149
+ if ( this . channelUsers [ channel ] ) {
150
+ this . channelUsers [ channel ] . delete ( nick ) ;
151
+ } else {
152
+ logger . warn ( `No channelUsers found for ${ channel } when ${ nick } parted.` ) ;
153
+ }
150
154
this . sendExactToDiscord ( channel , `*${ nick } * has left the channel (${ reason } )` ) ;
151
155
} ) ;
152
156
@@ -155,6 +159,10 @@ class Bot {
155
159
if ( ! this . ircStatusNotices || nick === this . nickname ) return ;
156
160
channels . forEach ( ( channelName ) => {
157
161
const channel = channelName . toLowerCase ( ) ;
162
+ if ( ! this . channelUsers [ channel ] ) {
163
+ logger . warn ( `No channelUsers found for ${ channel } when ${ nick } quit, ignoring.` ) ;
164
+ return ;
165
+ }
158
166
if ( ! this . channelUsers [ channel ] . delete ( nick ) ) return ;
159
167
this . sendExactToDiscord ( channel , `*${ nick } * has quit (${ reason } )` ) ;
160
168
} ) ;
Original file line number Diff line number Diff line change @@ -263,6 +263,19 @@ describe('Bot Events', function () {
263
263
bot . sendExactToDiscord . should . not . have . been . called ;
264
264
} ) ;
265
265
266
+ it ( 'should warn if it receives a part/quit before a names event' , function ( ) {
267
+ const bot = createBot ( { ...config , ircStatusNotices : true } ) ;
268
+ bot . connect ( ) ;
269
+ const channel = '#channel' ;
270
+ const reason = 'Leaving' ;
271
+
272
+ bot . ircClient . emit ( 'part' , channel , 'user1' , reason ) ;
273
+ bot . ircClient . emit ( 'quit' , 'user2' , reason , [ channel ] ) ;
274
+ this . warnSpy . should . have . been . calledTwice ;
275
+ this . warnSpy . getCall ( 0 ) . args . should . deep . equal ( [ `No channelUsers found for ${ channel } when user1 parted.` ] ) ;
276
+ this . warnSpy . getCall ( 1 ) . args . should . deep . equal ( [ `No channelUsers found for ${ channel } when user2 quit, ignoring.` ] ) ;
277
+ } ) ;
278
+
266
279
it ( 'should not listen to discord debug messages in production' , function ( ) {
267
280
logger . level = 'info' ;
268
281
const bot = createBot ( ) ;
You can’t perform that action at this time.
0 commit comments