From 284d60b0ad4c44982bb0c304f405a9dfcb9edb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sch=C3=B6bel?= Date: Tue, 9 May 2017 22:19:52 +0200 Subject: [PATCH 1/6] send nick change fromn irc to discord --- lib/bot.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/bot.js b/lib/bot.js index e4295297..9b984b33 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -124,6 +124,13 @@ class Bot { this.ircClient.on('notice', (author, to, text) => { this.sendToDiscord(author, to, `*${text}*`); }); + + this.ircClient.on('nick',(oldnick, newnick, channels, message) => { + channels.forEach(channelName => { + const channel = channelName.toLowerCase(); + this.sendExactToDiscord(channel,`*${oldnick}* are now known as ${newnick}`); + }); + }); this.ircClient.on('join', (channelName, nick) => { logger.debug('Received join:', channelName, nick); From e2eb354c0bfde8c850f23b9d14604613715507ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sch=C3=B6bel?= Date: Tue, 9 May 2017 22:44:32 +0200 Subject: [PATCH 2/6] removed tabs and so --- lib/bot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 9b984b33..bc063ead 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -124,8 +124,8 @@ class Bot { this.ircClient.on('notice', (author, to, text) => { this.sendToDiscord(author, to, `*${text}*`); }); - - this.ircClient.on('nick',(oldnick, newnick, channels, message) => { + + this.ircClient.on('nick',(oldnick, newnick, channels) => { channels.forEach(channelName => { const channel = channelName.toLowerCase(); this.sendExactToDiscord(channel,`*${oldnick}* are now known as ${newnick}`); From 4edb3075562fc6c6da405410aa139d9bd14707c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sch=C3=B6bel?= Date: Wed, 10 May 2017 00:13:48 +0200 Subject: [PATCH 3/6] fixed linter stuff --- lib/bot.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index bc063ead..5e4a6afc 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -125,11 +125,11 @@ class Bot { this.sendToDiscord(author, to, `*${text}*`); }); - this.ircClient.on('nick',(oldnick, newnick, channels) => { - channels.forEach(channelName => { - const channel = channelName.toLowerCase(); - this.sendExactToDiscord(channel,`*${oldnick}* are now known as ${newnick}`); - }); + this.ircClient.on('nick', (oldnick, newnick, channels) => { + channels.forEach((channelName) => { + const channel = channelName.toLowerCase(); + this.sendExactToDiscord(channel, `*${oldnick}* are now known as ${newnick}`); + }); }); this.ircClient.on('join', (channelName, nick) => { From 2e96dd7b7926f529b9bcd8167224741d705a0cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sch=C3=B6bel?= Date: Wed, 10 May 2017 00:56:27 +0200 Subject: [PATCH 4/6] Added test --- lib/bot.js | 8 +++++++- test/bot-events.test.js | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/bot.js b/lib/bot.js index 5e4a6afc..21cf5213 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -128,7 +128,13 @@ class Bot { this.ircClient.on('nick', (oldnick, newnick, channels) => { channels.forEach((channelName) => { const channel = channelName.toLowerCase(); - this.sendExactToDiscord(channel, `*${oldnick}* are now known as ${newnick}`); + if (this.channelUsers[channel]) { + this.channelUsers[channel].delete(oldnick); + this.channelUsers[channel].add(newnick); + } else { + logger.warn(`No channelUsers found for ${channel} when ${oldnick} changed.`); + } + this.sendExactToDiscord(channel, `*${oldnick}* is now known as ${newnick}`); }); }); diff --git a/test/bot-events.test.js b/test/bot-events.test.js index 44f8fb1f..e29cc39a 100644 --- a/test/bot-events.test.js +++ b/test/bot-events.test.js @@ -113,6 +113,15 @@ describe('Bot Events', function () { this.bot.sendToDiscord.should.have.been.calledWithExactly(author, channel, formattedText); }); + it('should send name change event to discord', function () { + const channel = '#channel'; + const oldnick = 'user1'; + const newnick = 'user2'; + const formattedText = `*${oldnick}* is now known as ${newnick}`; + this.bot.ircClient.emit('nick', oldnick, newnick, [channel]); + this.bot.sendExactToDiscord.should.have.been.calledWithExactly(channel, formattedText); + }); + it('should send actions to discord', function () { const channel = '#channel'; const author = 'user'; From ec7ca8b88d2e2c3ea16975d6864fa043bf2bb5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sch=C3=B6bel?= Date: Wed, 10 May 2017 01:25:00 +0200 Subject: [PATCH 5/6] more tests and usage of ircStatusNotices --- lib/bot.js | 1 + test/bot-events.test.js | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 21cf5213..0cbb49c0 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -126,6 +126,7 @@ class Bot { }); this.ircClient.on('nick', (oldnick, newnick, channels) => { + if (!this.ircStatusNotices) return; channels.forEach((channelName) => { const channel = channelName.toLowerCase(); if (this.channelUsers[channel]) { diff --git a/test/bot-events.test.js b/test/bot-events.test.js index e29cc39a..b640df0b 100644 --- a/test/bot-events.test.js +++ b/test/bot-events.test.js @@ -113,13 +113,42 @@ describe('Bot Events', function () { this.bot.sendToDiscord.should.have.been.calledWithExactly(author, channel, formattedText); }); - it('should send name change event to discord', function () { + it('should not send name change event to discord', function () { const channel = '#channel'; const oldnick = 'user1'; const newnick = 'user2'; - const formattedText = `*${oldnick}* is now known as ${newnick}`; this.bot.ircClient.emit('nick', oldnick, newnick, [channel]); - this.bot.sendExactToDiscord.should.have.been.calledWithExactly(channel, formattedText); + this.bot.sendExactToDiscord.should.not.have.been.called; + }); + + it('should send name change event to discord (untracked user)', function () { + const channel1 = '#channel1'; + const channel2 = '#channel2'; + const oldnick = 'user1'; + const newnick = 'user2'; + const bot = createBot({ ...config, ircStatusNotices: true }); + bot.connect(); + const formattedText = `*${oldnick}* is now known as ${newnick}`; + bot.ircClient.emit('nick', oldnick, newnick, [channel1, channel2]); + bot.sendExactToDiscord.should.have.been.calledTwice; + bot.sendExactToDiscord.getCall(0).args.should.deep.equal([channel1, formattedText]); + bot.sendExactToDiscord.getCall(1).args.should.deep.equal([channel2, formattedText]); + }); + + it('should send name change event to discord (tracked user)', function () { + const channel = '#channel'; + const oldnick = 'user1'; + const newnick = 'user2'; + const bot = createBot({ ...config, ircStatusNotices: true }); + bot.connect(); + bot.ircClient.emit('names', channel, { [bot.nickname]: '', [oldnick]: '' }); + const channelNicksPre = new Set([bot.nickname, oldnick]); + bot.channelUsers.should.deep.equal({ '#channel': channelNicksPre }); + const formattedText = `*${oldnick}* is now known as ${newnick}`; + const channelNicksAfter = new Set([bot.nickname, newnick]); + bot.ircClient.emit('nick', oldnick, newnick, [channel]); + bot.sendExactToDiscord.should.have.been.calledWithExactly(channel, formattedText); + bot.channelUsers.should.deep.equal({ '#channel': channelNicksAfter }); }); it('should send actions to discord', function () { From fd88a992b1a7d5f42246a20ae5e8b9c2527f6a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sch=C3=B6bel?= Date: Tue, 16 May 2017 14:05:22 +0200 Subject: [PATCH 6/6] fixed 'nitpick' :D, and only sends to tracked channels, edited tests to reflect these changes --- lib/bot.js | 11 +++++------ test/bot-events.test.js | 35 +++++++++++------------------------ 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 0cbb49c0..f223c5d7 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -48,7 +48,6 @@ class Bot { this.formatCommandPrelude = this.format.commandPrelude || 'Command sent from Discord by {$nickname}:'; this.formatIRCText = this.format.ircText || '<{$displayUsername}> {$text}'; this.formatURLAttachment = this.format.urlAttachment || '<{$displayUsername}> {$attachmentURL}'; - // "{$keyName}" => "variableValue" // author: IRC nickname // text: the (Discord-formatted) message content @@ -125,17 +124,17 @@ class Bot { this.sendToDiscord(author, to, `*${text}*`); }); - this.ircClient.on('nick', (oldnick, newnick, channels) => { + this.ircClient.on('nick', (oldNick, newNick, channels) => { if (!this.ircStatusNotices) return; channels.forEach((channelName) => { const channel = channelName.toLowerCase(); if (this.channelUsers[channel]) { - this.channelUsers[channel].delete(oldnick); - this.channelUsers[channel].add(newnick); + 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.`); + logger.warn(`No channelUsers found for ${channel} when ${oldNick} changed.`); } - this.sendExactToDiscord(channel, `*${oldnick}* is now known as ${newnick}`); }); }); diff --git a/test/bot-events.test.js b/test/bot-events.test.js index b640df0b..d3d18a83 100644 --- a/test/bot-events.test.js +++ b/test/bot-events.test.js @@ -121,34 +121,21 @@ describe('Bot Events', function () { this.bot.sendExactToDiscord.should.not.have.been.called; }); - it('should send name change event to discord (untracked user)', function () { + it('should send name change event to discord', function () { const channel1 = '#channel1'; const channel2 = '#channel2'; - const oldnick = 'user1'; - const newnick = 'user2'; - const bot = createBot({ ...config, ircStatusNotices: true }); - bot.connect(); - const formattedText = `*${oldnick}* is now known as ${newnick}`; - bot.ircClient.emit('nick', oldnick, newnick, [channel1, channel2]); - bot.sendExactToDiscord.should.have.been.calledTwice; - bot.sendExactToDiscord.getCall(0).args.should.deep.equal([channel1, formattedText]); - bot.sendExactToDiscord.getCall(1).args.should.deep.equal([channel2, formattedText]); - }); - - it('should send name change event to discord (tracked user)', function () { - const channel = '#channel'; - const oldnick = 'user1'; - const newnick = 'user2'; + const oldNick = 'user1'; + const newNick = 'user2'; const bot = createBot({ ...config, ircStatusNotices: true }); bot.connect(); - bot.ircClient.emit('names', channel, { [bot.nickname]: '', [oldnick]: '' }); - const channelNicksPre = new Set([bot.nickname, oldnick]); - bot.channelUsers.should.deep.equal({ '#channel': channelNicksPre }); - const formattedText = `*${oldnick}* is now known as ${newnick}`; - const channelNicksAfter = new Set([bot.nickname, newnick]); - bot.ircClient.emit('nick', oldnick, newnick, [channel]); - bot.sendExactToDiscord.should.have.been.calledWithExactly(channel, formattedText); - bot.channelUsers.should.deep.equal({ '#channel': channelNicksAfter }); + bot.ircClient.emit('names', '#channel1', { [bot.nickname]: '', [oldNick]: '' }); + const channelNicksPre = new Set([bot.nickname, oldNick]); + bot.channelUsers.should.deep.equal({ '#channel1': channelNicksPre }); + const formattedText = `*${oldNick}* is now known as ${newNick}`; + const channelNicksAfter = new Set([bot.nickname, newNick]); + bot.ircClient.emit('nick', oldNick, newNick, [channel1, channel2]); + bot.sendExactToDiscord.should.have.been.calledWithExactly(channel1, formattedText); + bot.channelUsers.should.deep.equal({ '#channel1': channelNicksAfter }); }); it('should send actions to discord', function () {