From cd4dfb8064e2e973a08ae77d972b93f1af99de3f Mon Sep 17 00:00:00 2001 From: Nick Wanninger Date: Sat, 17 Feb 2018 17:12:28 -0600 Subject: [PATCH 1/2] Add Presence System This allows the bot to show their presence to the discord guild as "WATCHING irc://server/+port This only runs when the .alterPresence option in the config is truthy --- lib/bot.js | 67 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 7688ee70..3f85bbf9 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -25,7 +25,8 @@ class Bot { validateChannelMapping(options.channelMapping); - this.discord = new discord.Client({ autoReconnect: true }); + this.discord = new discord.Client({ autoRe + : true }); this.server = options.server; this.nickname = options.nickname; @@ -36,6 +37,7 @@ class Bot { this.channels = _.values(options.channelMapping); this.ircStatusNotices = options.ircStatusNotices; this.announceSelfJoin = options.announceSelfJoin; + this.alterPresence = options.alterPresence // Nicks to ignore this.ignoreUsers = options.ignoreUsers || {}; @@ -82,32 +84,49 @@ class Bot { connect() { logger.debug('Connecting to IRC and Discord'); - this.discord.login(this.discordToken); - - const ircOptions = { - userName: this.nickname, - realName: this.nickname, - channels: this.channels, - floodProtection: true, - floodProtectionDelay: 500, - retryCount: 10, - autoRenick: true, - // options specified in the configuration file override the above defaults - ...this.ircOptions - }; + this.discord.login(this.discordToken).then(_ => { + if (this.alterPresence) { + let { secure, port } = this.ircOptions + port = port || 6667 + let name = `irc://${this.server}/${secure ? '+' : ''} ${port}` + + this.discord.user.setPresence({ + game: { + type: 'WATCHING', + name + } + }) + } + + const ircOptions = { + userName: this.nickname, + realName: this.nickname, + channels: this.channels, + floodProtection: true, + floodProtectionDelay: 500, + retryCount: 10, + autoRenick: true, + // options specified in the configuration file override the above defaults + ...this.ircOptions + }; - // default encoding to UTF-8 so messages to Discord aren't corrupted - if (!Object.prototype.hasOwnProperty.call(ircOptions, 'encoding')) { - if (irc.canConvertEncoding()) { - ircOptions.encoding = 'utf-8'; - } else { - logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.\n' + - 'For information on how to fix this, please see: https://github.com/Throne3d/node-irc#character-set-detection'); + // default encoding to UTF-8 so messages to Discord aren't corrupted + if (!Object.prototype.hasOwnProperty.call(ircOptions, 'encoding')) { + if (irc.canConvertEncoding()) { + ircOptions.encoding = 'utf-8'; + } else { + logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.\n' + + 'For information on how to fix this, please see: https://github.com/Throne3d/node-irc#character-set-detection'); + } } - } - this.ircClient = new irc.Client(this.server, this.nickname, ircOptions); - this.attachListeners(); + this.ircClient = new irc.Client(this.server, this.nickname, ircOptions); + this.attachListeners(); + + + }); + + } attachListeners() { From a4e566ee3d563d0ca29318c98ecfcbb49072e4b1 Mon Sep 17 00:00:00 2001 From: Ben Mintz Date: Thu, 22 Feb 2018 15:57:33 -0600 Subject: [PATCH 2/2] bot.js: remove extra space in playing status --- lib/bot.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 3f85bbf9..ff56ebde 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -25,8 +25,7 @@ class Bot { validateChannelMapping(options.channelMapping); - this.discord = new discord.Client({ autoRe - : true }); + this.discord = new discord.Client({ autoReconnect: true }); this.server = options.server; this.nickname = options.nickname; @@ -88,7 +87,7 @@ class Bot { if (this.alterPresence) { let { secure, port } = this.ircOptions port = port || 6667 - let name = `irc://${this.server}/${secure ? '+' : ''} ${port}` + let name = `irc://${this.server}/${secure ? '+' : ''}${port}` this.discord.user.setPresence({ game: {