From ff128fb5f10a50ff933b8cf315c732673c622feb Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 19 Aug 2016 22:26:38 -0700 Subject: [PATCH 1/3] support bot messages with message attachment fallback --- lib/bot.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/bot.js b/lib/bot.js index 9c8ecbf..c7aebe7 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -7,7 +7,7 @@ import emojis from '../assets/emoji.json'; import { validateChannelMapping } from './validators'; import { highlightUsername } from './helpers'; -const ALLOWED_SUBTYPES = ['me_message']; +const ALLOWED_SUBTYPES = ['me_message', 'bot_message']; const REQUIRED_FIELDS = ['server', 'nickname', 'channelMapping', 'token']; /** @@ -145,6 +145,7 @@ class Bot { } parseText(text) { + if (typeof(text) == "undefined") return ""; const { dataStore } = this.slack.rtm; return text .replace(/\n|\r\n|\r/g, ' ') @@ -209,6 +210,10 @@ class Bot { text = `<${user.name}> ${text}`; } else if (message.subtype === 'me_message') { text = `Action: ${user.name} ${text}`; + } else if (message.subtype === 'bot_message' && "attachments" in message && message.attachments.length > 0 && "fallback" in message.attachments[0]) { + text = `\x0303${message.attachments[0].fallback.replace(/\|/g, " ")}\x03`; + } else if (message.subtype === 'bot_message') { + return; } logger.debug('Sending message to IRC', channelName, text); this.ircClient.say(ircChannel, text); From 2c676eef35b961842eb21ddaca2762917bf0475e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 19 Aug 2016 23:31:44 -0700 Subject: [PATCH 2/3] check text for non-empty, non-null, non-undefined --- lib/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bot.js b/lib/bot.js index c7aebe7..08a6e76 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -145,7 +145,7 @@ class Bot { } parseText(text) { - if (typeof(text) == "undefined") return ""; + if (!text) return ""; const { dataStore } = this.slack.rtm; return text .replace(/\n|\r\n|\r/g, ' ') From fd4ff25dbafc03c22021f854afa5254614226f63 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 19 Aug 2016 23:37:12 -0700 Subject: [PATCH 3/3] quote fixes for lint validation --- lib/bot.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index 08a6e76..9273227 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -145,7 +145,7 @@ class Bot { } parseText(text) { - if (!text) return ""; + if (!text) return ''; const { dataStore } = this.slack.rtm; return text .replace(/\n|\r\n|\r/g, ' ') @@ -210,8 +210,9 @@ class Bot { text = `<${user.name}> ${text}`; } else if (message.subtype === 'me_message') { text = `Action: ${user.name} ${text}`; - } else if (message.subtype === 'bot_message' && "attachments" in message && message.attachments.length > 0 && "fallback" in message.attachments[0]) { - text = `\x0303${message.attachments[0].fallback.replace(/\|/g, " ")}\x03`; + } else if (message.subtype === 'bot_message' && 'attachments' in message && + message.attachments.length > 0 && 'fallback' in message.attachments[0]) { + text = `\x0303${message.attachments[0].fallback.replace(/\|/g, ' ')}\x03`; } else if (message.subtype === 'bot_message') { return; }