Skip to content
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
15 changes: 14 additions & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +124,20 @@ class Bot {
this.sendToDiscord(author, to, `*${text}*`);
});

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.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`);
} else {
logger.warn(`No channelUsers found for ${channel} when ${oldNick} changed.`);
}
});
});

this.ircClient.on('join', (channelName, nick) => {
logger.debug('Received join:', channelName, nick);
if (!this.ircStatusNotices) return;
Expand Down
25 changes: 25 additions & 0 deletions test/bot-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,31 @@ describe('Bot Events', function () {
this.bot.sendToDiscord.should.have.been.calledWithExactly(author, channel, formattedText);
});

it('should not send name change event to discord', function () {
const channel = '#channel';
const oldnick = 'user1';
const newnick = 'user2';
this.bot.ircClient.emit('nick', oldnick, newnick, [channel]);
this.bot.sendExactToDiscord.should.not.have.been.called;
});

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();
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 () {
const channel = '#channel';
const author = 'user';
Expand Down