diff --git a/lib/bot.js b/lib/bot.js index fa3b1474..ba0ce19d 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -159,8 +159,23 @@ class Bot { }); this.discord.on('message', (message) => { - // Ignore bot messages and people leaving/joining - this.sendToIRC(message); + // Show the IRC channel's /names list when asked for in Discord + if (message.content.toLowerCase() == '/names') { + const channelName = `#${message.channel.name}`; + const ircChannel = this.channelMapping[message.channel.id] || this.channelMapping[channelName]; + if (this.channelUsers[ircChannel]) { + const ircNames = this.channelUsers[ircChannel].values(); + const ircNamesArr = new Array(...ircNames); + this.sendExactToDiscord(ircChannel, 'Users in ' + ircChannel + "\n> " + ircNamesArr.join(', ')); + } else { + _logger.default.warn(`No channelUsers found for ${ircChannel} when /names requested`); + // Pass the command through if channelUsers is empty + this.sendToIRC(message); + } + } else { + // Ignore bot messages and people leaving/joining + this.sendToIRC(message); + } }); this.ircClient.on('message', this.sendToDiscord.bind(this)); @@ -170,13 +185,13 @@ class Bot { }); this.ircClient.on('nick', (oldNick, newNick, channels) => { - if (!this.ircStatusNotices) return; channels.forEach((channelName) => { const channel = channelName.toLowerCase(); if (this.channelUsers[channel]) { if (this.channelUsers[channel].has(oldNick)) { this.channelUsers[channel].delete(oldNick); this.channelUsers[channel].add(newNick); + if (!this.ircStatusNotices) return; this.sendExactToDiscord(channel, `*${oldNick}* is now known as ${newNick}`); } } else { @@ -187,18 +202,17 @@ class Bot { this.ircClient.on('join', (channelName, nick) => { logger.debug('Received join:', channelName, nick); - if (!this.ircStatusNotices) return; if (nick === this.ircClient.nick && !this.announceSelfJoin) return; const channel = channelName.toLowerCase(); // self-join is announced before names (which includes own nick) // so don't add nick to channelUsers if (nick !== this.ircClient.nick) this.channelUsers[channel].add(nick); + if (!this.ircStatusNotices) return; this.sendExactToDiscord(channel, `*${nick}* has joined the channel`); }); this.ircClient.on('part', (channelName, nick, reason) => { logger.debug('Received part:', channelName, nick, reason); - if (!this.ircStatusNotices) return; const channel = channelName.toLowerCase(); // remove list of users when no longer in channel (as it will become out of date) if (nick === this.ircClient.nick) { @@ -211,12 +225,13 @@ class Bot { } else { logger.warn(`No channelUsers found for ${channel} when ${nick} parted.`); } + if (!this.ircStatusNotices) return; this.sendExactToDiscord(channel, `*${nick}* has left the channel (${reason})`); }); this.ircClient.on('quit', (nick, reason, channels) => { logger.debug('Received quit:', nick, channels); - if (!this.ircStatusNotices || nick === this.ircClient.nick) return; + if (nick === this.ircClient.nick) return; channels.forEach((channelName) => { const channel = channelName.toLowerCase(); if (!this.channelUsers[channel]) { @@ -224,13 +239,13 @@ class Bot { return; } if (!this.channelUsers[channel].delete(nick)) return; + if (!this.ircStatusNotices) return; this.sendExactToDiscord(channel, `*${nick}* has quit (${reason})`); }); }); this.ircClient.on('names', (channelName, nicks) => { logger.debug('Received names:', channelName, nicks); - if (!this.ircStatusNotices) return; const channel = channelName.toLowerCase(); this.channelUsers[channel] = new Set(Object.keys(nicks)); });