Permalink
Browse files

Add option to split messages into multiple PRIVMSGs

Many IRC servers only allow a PRIVMESSAGE length of some number of
characters. This lets the user specify what size they want messages
to be split into.
  • Loading branch information...
1 parent c60b696 commit 1061adcdbae046a8476df3911e5dd38cdd514ab5 @PherricOxide PherricOxide committed Sep 2, 2012
Showing with 10 additions and 2 deletions.
  1. +4 −0 docs/API.rst
  2. +6 −2 lib/irc.js
View
@@ -29,6 +29,7 @@ Client
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
+ messageSplit: 400,
stripColors: false
}
@@ -45,6 +46,9 @@ Client
`floodProtectionDelay` sets the amount of time that the client will wait
between sending subsequent messages when `floodProtection` is enabled.
+ `messageSplit` will split up large messages sent with the `say` method
+ into multiple messages of length less than `messageSplit` characters.
+
`stripColors` removes mirc colors (0x03 followed by one or two ascii
numbers for foreground,background) and ircII "effect" codes (0x02
bold, 0x1f underline, 0x16 reverse, 0x0f reset) from the entire
View
@@ -48,6 +48,7 @@ function Client(server, nick, opt) {
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
+ messageSplit: 400,
stripColors: false
};
@@ -674,8 +675,11 @@ Client.prototype.say = function(target, text) { // {{{
text.toString().split(/\r?\n/).filter(function(line) {
return line.length > 0;
}).forEach(function(line) {
- self.send('PRIVMSG', target, line);
- self.emit('selfMessage', target, line);
+ var r = new RegExp(".{1," + self.opt.messageSplit + "}", "g");
+ while ((messagePart = r.exec(line)) != null) {
+ self.send('PRIVMSG', target, messagePart);
+ self.emit('selfMessage', target, messagePart);
+ }
});
}
} // }}}

0 comments on commit 1061adc

Please sign in to comment.