@@ -40,6 +40,7 @@ IrcClient.prototype._applyDefaultOptions = function(user_options) {
4040 auto_reconnect_max_retries : 3 ,
4141 ping_interval : 30 ,
4242 ping_timeout : 120 ,
43+ message_max_length : 350 ,
4344 transport : default_transport
4445 } ;
4546
@@ -160,7 +161,7 @@ IrcClient.prototype.proxyIrcEvents = function() {
160161
161162 this . command_handler . on ( 'all' , function ( event_name , event_arg ) {
162163 client . resetPingTimer ( ) ;
163-
164+
164165 // Add a reply() function to selected message events
165166 if ( [ 'privmsg' , 'notice' , 'action' ] . indexOf ( event_name ) > - 1 ) {
166167 event_arg . reply = function ( message ) {
@@ -254,38 +255,38 @@ IrcClient.prototype.startPeriodicPing = function() {
254255 var that = this ;
255256 var ping_timer = null ;
256257 var timeout_timer = null ;
257-
258+
258259 if ( that . options . ping_interval <= 0 || that . options . ping_timeout <= 0 ) {
259260 return ;
260261 }
261-
262+
262263 function scheduleNextPing ( ) {
263264 ping_timer = that . connection . setTimeout ( pingServer , that . options . ping_interval * 1000 ) ;
264265 }
265-
266+
266267 function resetPingTimer ( ) {
267268 if ( ping_timer ) {
268269 that . connection . clearTimeout ( ping_timer ) ;
269270 }
270-
271+
271272 if ( timeout_timer ) {
272273 that . connection . clearTimeout ( timeout_timer ) ;
273274 }
274-
275+
275276 scheduleNextPing ( ) ;
276277 }
277-
278+
278279 function pingServer ( ) {
279280 timeout_timer = that . connection . setTimeout ( pingTimeout , that . options . ping_timeout * 1000 ) ;
280281 that . ping ( ) ;
281282 }
282-
283+
283284 function pingTimeout ( ) {
284285 that . emit ( 'ping timeout' ) ;
285286 var end_msg = that . rawString ( 'QUIT' , 'Ping timeout (' + that . options . ping_timeout + ' seconds)' ) ;
286287 that . connection . end ( end_msg , true ) ;
287288 }
288-
289+
289290 this . resetPingTimer = resetPingTimer ;
290291 scheduleNextPing ( ) ;
291292} ;
@@ -348,31 +349,29 @@ IrcClient.prototype.changeNick = function(nick) {
348349} ;
349350
350351
351- IrcClient . prototype . say = function ( target , message ) {
352+ IrcClient . prototype . sendMessage = function ( commandName , target , message ) {
352353 var that = this ;
353354
354355 // Maximum length of target + message we can send to the IRC server is 500 characters
355356 // but we need to leave extra room for the sender prefix so the entire message can
356357 // be sent from the IRCd to the target without being truncated.
357- var blocks = truncateString ( message , 350 ) ;
358+ var blocks = truncateString ( message , this . options . message_max_length ) ;
358359
359360 blocks . forEach ( function ( block ) {
360- that . raw ( 'PRIVMSG' , target , block ) ;
361+ that . raw ( commandName , target , block ) ;
361362 } ) ;
363+
364+ return blocks ;
362365} ;
363366
364367
365- IrcClient . prototype . notice = function ( target , message ) {
366- var that = this ;
368+ IrcClient . prototype . say = function ( target , message ) {
369+ return this . sendMessage ( 'PRIVMSG' , target , message ) ;
370+ } ;
367371
368- // Maximum length of target + message we can send to the IRC server is 500 characters
369- // but we need to leave extra room for the sender prefix so the entire message can
370- // be sent from the IRCd to the target without being truncated.
371- var blocks = truncateString ( message , 350 ) ;
372372
373- blocks . forEach ( function ( block ) {
374- that . raw ( 'NOTICE' , target , block ) ;
375- } ) ;
373+ IrcClient . prototype . notice = function ( target , message ) {
374+ return this . sendMessage ( 'NOTICE' , target , message ) ;
376375} ;
377376
378377
@@ -468,11 +467,19 @@ IrcClient.prototype.action = function(target, message) {
468467 // Maximum length of target + message we can send to the IRC server is 500 characters
469468 // but we need to leave extra room for the sender prefix so the entire message can
470469 // be sent from the IRCd to the target without being truncated.
471- var blocks = truncateString ( message , 350 ) ;
470+
471+ // The block length here is the max, but without the non-content characters:
472+ // the command name, the space, and the two SOH chars
473+
474+ var commandName = 'ACTION' ;
475+ var blockLength = this . options . message_max_length - ( commandName . length + 3 ) ;
476+ var blocks = truncateString ( message , blockLength ) ;
472477
473478 blocks . forEach ( function ( block ) {
474- that . ctcpRequest ( target , 'ACTION' , block ) ;
479+ that . ctcpRequest ( target , commandName , block ) ;
475480 } ) ;
481+
482+ return blocks ;
476483} ;
477484
478485
0 commit comments