Skip to content

Commit

Permalink
Add option to split messages into multiple PRIVMSGs
Browse files Browse the repository at this point in the history
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
PherricOxide committed Sep 2, 2012
1 parent c60b696 commit 1061adc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Client
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
messageSplit: 400,
stripColors: false
}

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function Client(server, nick, opt) {
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
messageSplit: 400,
stripColors: false
};

Expand Down Expand Up @@ -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);
}
});
}
} // }}}
Expand Down

0 comments on commit 1061adc

Please sign in to comment.