Skip to content

check if an user is present in the channel for nickchange #241

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
May 16, 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
8 changes: 5 additions & 3 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ class Bot {
channels.forEach((channelName) => {
const channel = channelName.toLowerCase();
if (this.channelUsers[channel]) {
this.channelUsers[channel].delete(oldNick);
this.channelUsers[channel].add(newNick);
this.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`);
if (this.channelUsers[channel].has(oldNick)) {
this.channelUsers[channel].delete(oldNick);
this.channelUsers[channel].add(newNick);
this.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`);
}
} else {
logger.warn(`No channelUsers found for ${channel} when ${oldNick} changed.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't think we really need the logger warning here, so maybe just fold the two ifs into one and do if (this.channelUsers[channel] && this.channelUsers[channel].has(oldNick)) {?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what do you think @Throne3d?

Copy link
Collaborator

@Throne3d Throne3d May 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logger warning probably isn't necessary – it was mostly to get around the issue with lowercasing channel names, in the other events. I don't think it's harmful to leave it though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I guess not. Just a bit cleaner code, but it'll do.

}
Expand Down
12 changes: 8 additions & 4 deletions test/bot-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,22 @@ describe('Bot Events', function () {
it('should send name change event to discord', function () {
const channel1 = '#channel1';
const channel2 = '#channel2';
const channel3 = '#channel3';
const oldNick = 'user1';
const newNick = 'user2';
const user3 = 'user3';
const bot = createBot({ ...config, ircStatusNotices: true });
const staticChannel = new Set([bot.nickname, user3]);
bot.connect();
bot.ircClient.emit('names', '#channel1', { [bot.nickname]: '', [oldNick]: '' });
bot.ircClient.emit('names', channel1, { [bot.nickname]: '', [oldNick]: '' });
bot.ircClient.emit('names', channel2, { [bot.nickname]: '', [user3]: '' });
const channelNicksPre = new Set([bot.nickname, oldNick]);
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksPre });
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksPre, '#channel2': staticChannel });
const formattedText = `*${oldNick}* is now known as ${newNick}`;
const channelNicksAfter = new Set([bot.nickname, newNick]);
bot.ircClient.emit('nick', oldNick, newNick, [channel1, channel2]);
bot.ircClient.emit('nick', oldNick, newNick, [channel1, channel2, channel3]);
bot.sendExactToDiscord.should.have.been.calledWithExactly(channel1, formattedText);
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksAfter });
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksAfter, '#channel2': staticChannel });
});

it('should send actions to discord', function () {
Expand Down