From bd28b84f2c695fd42b10cde87672dfd3009df7d2 Mon Sep 17 00:00:00 2001 From: James Ross Date: Sun, 1 Apr 2018 12:32:47 +0100 Subject: [PATCH 1/2] Allow sending IRC topic changes to Discord Part of reactiflux/discord-irc#220 --- README.md | 3 +++ lib/bot.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index f3272f1d..19395b61 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ First you need to create a Discord bot user, which you can do by following the i "#discord": "#irc channel-password", // Add channel keys after the channel name "1234567890": "#channel" // Use a discord channel ID instead of its name (so you can rename it or to disambiguate) }, + "channelTopicsToDiscord": [ // Sends topic changes from IRC to Discord + "#irc + ], "ircOptions": { // Optional node-irc options "floodProtection": false, // On by default "floodProtectionDelay": 1000 // 500 by default diff --git a/lib/bot.js b/lib/bot.js index 418c7a41..e1e41ef9 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -37,6 +37,7 @@ class Bot { this.ircStatusNotices = options.ircStatusNotices; this.announceSelfJoin = options.announceSelfJoin; this.webhookOptions = options.webhooks; + this.channelTopicsToDiscord = options.channelTopicsToDiscord; // Nicks to ignore this.ignoreUsers = options.ignoreUsers || {}; @@ -238,6 +239,17 @@ class Bot { } }); + if (typeof this.channelTopicsToDiscord !== 'undefined') { + this.ircClient.on('topic', (channel, topic, nick, message) => { + if (message.command !== 'rpl_topicwhotime') { + logger.debug('Received topic change from IRC:', channel, topic); + if (this.channelTopicsToDiscord === true || this.channelTopicsToDiscord.includes(channel)) { + this.sendExactToDiscord(channel, `*${nick}* has changed the topic to "${topic}"`); + } + } + }); + } + if (logger.level === 'debug') { this.discord.on('debug', (message) => { logger.debug('Received debug event from Discord', message); From 33de9605562ef02cb66ba22afc3aebe1dc2c2d40 Mon Sep 17 00:00:00 2001 From: James Ross Date: Sun, 1 Apr 2018 12:47:25 +0100 Subject: [PATCH 2/2] Fix for max-len lint rule lost in a sea of 2460 other errors --- lib/bot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bot.js b/lib/bot.js index e1e41ef9..77d96a5d 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -243,7 +243,9 @@ class Bot { this.ircClient.on('topic', (channel, topic, nick, message) => { if (message.command !== 'rpl_topicwhotime') { logger.debug('Received topic change from IRC:', channel, topic); - if (this.channelTopicsToDiscord === true || this.channelTopicsToDiscord.includes(channel)) { + const channelIncluded = this.channelTopicsToDiscord === true || + this.channelTopicsToDiscord.includes(channel); + if (channelIncluded) { this.sendExactToDiscord(channel, `*${nick}* has changed the topic to "${topic}"`); } }