Skip to content

Commit fd95d7d

Browse files
author
Richard Schöbel
committed
check if an user is present in the channel
1 parent fd88a99 commit fd95d7d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/bot.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ class Bot {
129129
channels.forEach((channelName) => {
130130
const channel = channelName.toLowerCase();
131131
if (this.channelUsers[channel]) {
132-
this.channelUsers[channel].delete(oldNick);
133-
this.channelUsers[channel].add(newNick);
134-
this.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`);
132+
if (this.channelUsers[channel].has(oldNick)) {
133+
this.channelUsers[channel].delete(oldNick);
134+
this.channelUsers[channel].add(newNick);
135+
this.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`);
136+
}
135137
} else {
136138
logger.warn(`No channelUsers found for ${channel} when ${oldNick} changed.`);
137139
}

test/bot-events.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,22 @@ describe('Bot Events', function () {
124124
it('should send name change event to discord', function () {
125125
const channel1 = '#channel1';
126126
const channel2 = '#channel2';
127+
const channel3 = '#channel3';
127128
const oldNick = 'user1';
128129
const newNick = 'user2';
130+
const user3 = 'user3';
129131
const bot = createBot({ ...config, ircStatusNotices: true });
132+
const staticChannel = new Set([bot.nickname, user3]);
130133
bot.connect();
131-
bot.ircClient.emit('names', '#channel1', { [bot.nickname]: '', [oldNick]: '' });
134+
bot.ircClient.emit('names', channel1, { [bot.nickname]: '', [oldNick]: '' });
135+
bot.ircClient.emit('names', channel2, { [bot.nickname]: '', [user3]: '' });
132136
const channelNicksPre = new Set([bot.nickname, oldNick]);
133-
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksPre });
137+
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksPre, '#channel2': staticChannel });
134138
const formattedText = `*${oldNick}* is now known as ${newNick}`;
135139
const channelNicksAfter = new Set([bot.nickname, newNick]);
136-
bot.ircClient.emit('nick', oldNick, newNick, [channel1, channel2]);
140+
bot.ircClient.emit('nick', oldNick, newNick, [channel1, channel2, channel3]);
137141
bot.sendExactToDiscord.should.have.been.calledWithExactly(channel1, formattedText);
138-
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksAfter });
142+
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksAfter, '#channel2': staticChannel });
139143
});
140144

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

0 commit comments

Comments
 (0)