Skip to content

Commit 665c8cf

Browse files
committed
Fix html entities when echoing slack messages to IRC
Change user messages on IRC to have <username> instead of username:
1 parent be092a2 commit 665c8cf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/bot.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var _ = require('underscore');
22
var IRC = require('irc');
33
var SlackClient = require('slack-client');
44
var Log = require('log');
5+
var Entities = require('html-entities').XmlEntities;
6+
57

68
/**
79
* IRC Bot for syncing messages from IRC to Slack
@@ -23,6 +25,7 @@ var Bot = function (config) {
2325
});
2426

2527
this.logger = new Log(process.env.SLACK_LOG_LEVEL || 'info');
28+
this.entities = new Entities();
2629
// default node-irc options
2730
// (@see https://github.com/martynsmith/node-irc/blob/0.3.x/lib/irc.js)
2831
this.irc = {
@@ -244,6 +247,8 @@ Bot.prototype.ircSpeak = function (channel, message, username) {
244247
if(!self.config.highlight) {
245248
username = username.replace(/^(.)/, '$1\u200C')
246249
}
250+
username = "<" + username + "> "
251+
message = self.entities.decode(message)
247252

248253
// IRC max length is 512, minus the CR LF and other headers ...
249254
// In practice, it looks like this:
@@ -255,7 +260,7 @@ Bot.prototype.ircSpeak = function (channel, message, username) {
255260
// 497 = 510 - 13
256261

257262
maxLineLength = 479 - (self.hostmask.length + self.client.nick.length + self.client.hostMask.length)
258-
maxLineLength -= (channel.length + username.length + 2)
263+
maxLineLength -= (channel.length + username.length + 3)
259264

260265
message.split(/\s*[\r\n]+\s*/).forEach(function(msg) {
261266
while (msg.length > maxLineLength) {
@@ -264,11 +269,11 @@ Bot.prototype.ircSpeak = function (channel, message, username) {
264269
line = msg.slice(0, length)
265270
msg = msg.slice(length).trim()
266271

267-
self.logger.info('IRC(' + line.length + ')> ' + channel + ": " + username + ': ' + line);
268-
self.client.say(channel, username + ": " + line);
272+
self.logger.debug('IRC(' + line.length + ')> #' + channel + " " + username + line);
273+
self.client.say(channel, username + line);
269274
}
270-
self.logger.info('IRC> ' + channel + ": " + username + ': ' + msg);
271-
self.client.say(channel, username + ": " + msg);
275+
self.logger.debug('IRC> #' + channel + " " + username + msg);
276+
self.client.say(channel, username + msg);
272277
});
273278
};
274279

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"underscore": "^1.7.0",
2929
"irc": "~0.3.6",
3030
"slack-client": "~1.3.1",
31-
"log": "~1.4.0"
31+
"log": "~1.4.0",
32+
"html-entities": "~1.1.2"
3233
},
3334
"devDependencies": {},
3435
"bin": {

0 commit comments

Comments
 (0)