Skip to content

Warn if a part/quit is received and no channelUsers is set #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ class Bot {
delete this.channelUsers[channel];
return;
}
this.channelUsers[channel].delete(nick);
if (this.channelUsers[channel]) {
this.channelUsers[channel].delete(nick);
} else {
logger.warn(`No channelUsers found for ${channel} when ${nick} parted.`);
}
this.sendExactToDiscord(channel, `*${nick}* has left the channel (${reason})`);
});

Expand All @@ -155,6 +159,10 @@ class Bot {
if (!this.ircStatusNotices || nick === this.nickname) return;
channels.forEach((channelName) => {
const channel = channelName.toLowerCase();
if (!this.channelUsers[channel]) {
logger.warn(`No channelUsers found for ${channel} when ${nick} quit, ignoring.`);
return;
}
if (!this.channelUsers[channel].delete(nick)) return;
this.sendExactToDiscord(channel, `*${nick}* has quit (${reason})`);
});
Expand Down
13 changes: 13 additions & 0 deletions test/bot-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ describe('Bot Events', function () {
bot.sendExactToDiscord.should.not.have.been.called;
});

it('should warn if it receives a part/quit before a names event', function () {
const bot = createBot({ ...config, ircStatusNotices: true });
bot.connect();
const channel = '#channel';
const reason = 'Leaving';

bot.ircClient.emit('part', channel, 'user1', reason);
bot.ircClient.emit('quit', 'user2', reason, [channel]);
this.warnSpy.should.have.been.calledTwice;
this.warnSpy.getCall(0).args.should.deep.equal([`No channelUsers found for ${channel} when user1 parted.`]);
this.warnSpy.getCall(1).args.should.deep.equal([`No channelUsers found for ${channel} when user2 quit, ignoring.`]);
});

it('should not listen to discord debug messages in production', function () {
logger.level = 'info';
const bot = createBot();
Expand Down