\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
// 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
- var wrap_length = 350,\r
- trunc_msg,\r
- trunc_length,\r
- message = args.msg;\r
- \r
- if (args.target && (args.msg)) {\r
- trunc_length = wrap_length - args.target.length;\r
- // If the message is longer than wrap_length, send the message in chunks\r
- while (message.length > trunc_length) {\r
- trunc_msg = message.substr(0, trunc_length);\r
- message = message.substr(trunc_length);\r
- irc_connection.write('PRIVMSG ' + args.target + ' :' + trunc_msg);\r
- }\r
- // Send the remaining text\r
- irc_connection.write('PRIVMSG ' + args.target + ' :' + message, callback);\r
- }\r
+\r
+ var blocks = truncateString(args.msg, 350);\r
+ blocks.forEach(function (block) {\r
+ irc_connection.write('PRIVMSG ' + args.target + ' :' + block);\r
+ });\r
},\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
- var wrap_length = 350,\r
- trunc_msg,\r
- trunc_length,\r
- message = args.msg;\r
- \r
- if (args.target && (args.msg)) {\r
- trunc_length = wrap_length - args.target.length;\r
- // If the message is longer than wrap_length, send the message in chunks\r
- while (message.length > trunc_length) {\r
- trunc_msg = message.substr(0, trunc_length);\r
- message = message.substr(trunc_length);\r
- irc_connection.write('NOTICE ' + args.target + ' :' + trunc_msg);\r
- }\r
- // Send the remaining text\r
- irc_connection.write('NOTICE ' + args.target + ' :' + message, callback);\r
- }\r
+\r
+ var blocks = truncateString(args.msg, 350);\r
+ blocks.forEach(function (block) {\r
+ irc_connection.write('NOTICE ' + args.target + ' :' + block);\r
+ });\r
},\r
\r
\r