Skip to content

Commit fd88a99

Browse files
author
Richard Schöbel
committed
fixed 'nitpick' :D, and only sends to tracked channels,
edited tests to reflect these changes
1 parent ec7ca8b commit fd88a99

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

lib/bot.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Bot {
4848
this.formatCommandPrelude = this.format.commandPrelude || 'Command sent from Discord by {$nickname}:';
4949
this.formatIRCText = this.format.ircText || '<{$displayUsername}> {$text}';
5050
this.formatURLAttachment = this.format.urlAttachment || '<{$displayUsername}> {$attachmentURL}';
51-
5251
// "{$keyName}" => "variableValue"
5352
// author: IRC nickname
5453
// text: the (Discord-formatted) message content
@@ -125,17 +124,17 @@ class Bot {
125124
this.sendToDiscord(author, to, `*${text}*`);
126125
});
127126

128-
this.ircClient.on('nick', (oldnick, newnick, channels) => {
127+
this.ircClient.on('nick', (oldNick, newNick, channels) => {
129128
if (!this.ircStatusNotices) return;
130129
channels.forEach((channelName) => {
131130
const channel = channelName.toLowerCase();
132131
if (this.channelUsers[channel]) {
133-
this.channelUsers[channel].delete(oldnick);
134-
this.channelUsers[channel].add(newnick);
132+
this.channelUsers[channel].delete(oldNick);
133+
this.channelUsers[channel].add(newNick);
134+
this.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`);
135135
} else {
136-
logger.warn(`No channelUsers found for ${channel} when ${oldnick} changed.`);
136+
logger.warn(`No channelUsers found for ${channel} when ${oldNick} changed.`);
137137
}
138-
this.sendExactToDiscord(channel, `*${oldnick}* is now known as ${newnick}`);
139138
});
140139
});
141140

test/bot-events.test.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,21 @@ describe('Bot Events', function () {
121121
this.bot.sendExactToDiscord.should.not.have.been.called;
122122
});
123123

124-
it('should send name change event to discord (untracked user)', function () {
124+
it('should send name change event to discord', function () {
125125
const channel1 = '#channel1';
126126
const channel2 = '#channel2';
127-
const oldnick = 'user1';
128-
const newnick = 'user2';
129-
const bot = createBot({ ...config, ircStatusNotices: true });
130-
bot.connect();
131-
const formattedText = `*${oldnick}* is now known as ${newnick}`;
132-
bot.ircClient.emit('nick', oldnick, newnick, [channel1, channel2]);
133-
bot.sendExactToDiscord.should.have.been.calledTwice;
134-
bot.sendExactToDiscord.getCall(0).args.should.deep.equal([channel1, formattedText]);
135-
bot.sendExactToDiscord.getCall(1).args.should.deep.equal([channel2, formattedText]);
136-
});
137-
138-
it('should send name change event to discord (tracked user)', function () {
139-
const channel = '#channel';
140-
const oldnick = 'user1';
141-
const newnick = 'user2';
127+
const oldNick = 'user1';
128+
const newNick = 'user2';
142129
const bot = createBot({ ...config, ircStatusNotices: true });
143130
bot.connect();
144-
bot.ircClient.emit('names', channel, { [bot.nickname]: '', [oldnick]: '' });
145-
const channelNicksPre = new Set([bot.nickname, oldnick]);
146-
bot.channelUsers.should.deep.equal({ '#channel': channelNicksPre });
147-
const formattedText = `*${oldnick}* is now known as ${newnick}`;
148-
const channelNicksAfter = new Set([bot.nickname, newnick]);
149-
bot.ircClient.emit('nick', oldnick, newnick, [channel]);
150-
bot.sendExactToDiscord.should.have.been.calledWithExactly(channel, formattedText);
151-
bot.channelUsers.should.deep.equal({ '#channel': channelNicksAfter });
131+
bot.ircClient.emit('names', '#channel1', { [bot.nickname]: '', [oldNick]: '' });
132+
const channelNicksPre = new Set([bot.nickname, oldNick]);
133+
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksPre });
134+
const formattedText = `*${oldNick}* is now known as ${newNick}`;
135+
const channelNicksAfter = new Set([bot.nickname, newNick]);
136+
bot.ircClient.emit('nick', oldNick, newNick, [channel1, channel2]);
137+
bot.sendExactToDiscord.should.have.been.calledWithExactly(channel1, formattedText);
138+
bot.channelUsers.should.deep.equal({ '#channel1': channelNicksAfter });
152139
});
153140

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

0 commit comments

Comments
 (0)