\r
\r
\r
+/**\r
+ * Truncate a string into blocks of a set size\r
+ */\r
+function truncateString(str, block_size) {\r
+ block_size = block_size || 350;\r
+\r
+ var blocks = [],\r
+ current_pos;\r
+\r
+ for (current_pos = 0; current_pos < str.length; current_pos = current_pos + block_size) {\r
+ blocks.push(str.substr(current_pos, block_size));\r
+ }\r
+\r
+ return blocks;\r
+}\r
+\r
+\r
+\r
+\r
var listeners = {\r
PRIVMSG: function (args, irc_connection, callback) {\r
- if (args.target && (args.msg)) {\r
- // TODO: Enable plugin support here again\r
- //obj = kiwi.kiwi_mod.run('msgsend', args, {websocket: websocket});\r
- //if (obj !== null) {\r
- irc_connection.write('PRIVMSG ' + args.target + ' :' + args.msg, callback);\r
- //}\r
- }\r
+ // Maximum length of target + message we can send to the IRC server is 500 characters\r
+ // but we need to leave extra room for the sender prefix so the entire message can\r
+ // be sent from the IRCd to the target without being truncated.\r
+\r
+ var blocks = truncateString(args.msg, 350);\r
+ blocks.forEach(function (block, idx) {\r
+ // Apply the callback on the last message only\r
+ var cb = (idx === blocks.length - 1) ?\r
+ callback :\r
+ undefined;\r
+\r
+ irc_connection.write('PRIVMSG ' + args.target + ' :' + block, cb);\r
+ });\r
},\r
- \r
+\r
\r
CTCP: function (args, irc_connection, callback) {\r
if ((args.target) && (args.type)) {\r
},\r
\r
\r
+ CHANNEL_INFO: function (args, irc_connection, callback) {\r
+ if (args.channel) {\r
+ irc_connection.write('MODE ' + args.channel, callback);\r
+ }\r
+ },\r
+\r
+\r
PART: function (args, irc_connection, callback) {\r
if (args.channel) {\r
_.each(args.channel.split(","), function (chan) {\r
\r
KICK: function (args, irc_connection, callback) {\r
if ((args.channel) && (args.nick)) {\r
- irc_connection.write('KICK ' + args.channel + ' ' + args.nick + ':' + args.reason, callback);\r
+ irc_connection.write('KICK ' + args.channel + ' ' + args.nick + ' :' + args.reason, callback);\r
}\r
},\r
\r
\r
\r
NOTICE: function (args, irc_connection, callback) {\r
- if ((args.target) && (args.msg)) {\r
- irc_connection.write('NOTICE ' + args.target + ' :' + args.msg, callback);\r
- }\r
+ // Maximum length of target + message we can send to the IRC server is 500 characters\r
+ // but we need to leave extra room for the sender prefix so the entire message can\r
+ // be sent from the IRCd to the target without being truncated.\r
+\r
+ var blocks = truncateString(args.msg, 350);\r
+ blocks.forEach(function (block, idx) {\r
+ // Apply the callback on the last message only\r
+ var cb = (idx === blocks.length - 1) ?\r
+ callback :\r
+ undefined;\r
+\r
+ irc_connection.write('NOTICE ' + args.target + ' :' + block, cb);\r
+ });\r
},\r
\r
\r
if ((args.target) && (args.data)) {\r
irc_connection.write('PRIVMSG ' + args.target + ': ' + String.fromCharCode(1) + 'KIWI ' + args.data + String.fromCharCode(1), callback);\r
}\r
+ },\r
+\r
+ ENCODING: function (args, irc_connection, callback) {\r
+ if (args.encoding) {\r
+ return callback(irc_connection.setEncoding(args.encoding));\r
+ }\r
}\r
};\r