@@ -22,6 +22,7 @@ This will be fixed in 0.8.x.
2222*/
2323
2424var util = require ( 'util' ) ;
25+ var format = util . format ;
2526
2627var partition = function ( array , length ) {
2728 var partitions = [ ] ;
@@ -33,48 +34,53 @@ var partition = function (array, length) {
3334
3435var OutputSocket = function ( socket , logger , nick ) {
3536 var raw = function ( line ) {
36- logger . info ( "->: " + Array . isArray ( line ) ? line . join ( " " ) : String ( line ) ) ;
37+ if ( Array . isArray ( line ) ) { line = line . join ( " " ) ; }
38+ logger . info ( "->: " + String ( line ) ) ;
3739 socket . raw ( line ) ;
3840 } ;
3941
42+ var rawf = function ( ) {
43+ raw ( format . apply ( null , arguments ) ) ;
44+ } ;
45+
4046 return {
41- say : function ( location , message ) {
47+ say : function recur ( location , message ) {
4248 if ( util . isArray ( message ) ) {
4349 message . forEach ( function ( msg ) {
44- say . call ( this , location , msg ) ;
50+ recur . call ( this , location , msg ) ;
4551 } ) ;
4652
4753 return ;
4854 }
49- raw ( [ "PRIVMSG" , location , ":" + message ] ) ;
55+ rawf ( "PRIVMSG %s :%s " , location , message ) ;
5056 } ,
5157
52- ctcp : function ( location , type , message ) {
58+ ctcp : function recur ( location , type , message ) {
5359 if ( util . isArray ( message ) ) {
5460 message . forEach ( function ( msg ) {
55- ctcp . call ( this , location , type , msg ) ;
61+ recur . call ( this , location , type , msg ) ;
5662 } ) ;
5763
5864 return ;
5965 }
60- this . say ( location , '\u0001' + type + " " + message + '\u0001' ) ;
66+ this . say ( location , format ( '\u0001%s %s\u0001' , type , message ) ) ;
6167 } ,
6268
6369 act : function ( location , message ) {
6470 this . ctcp ( location , "ACTION" , message ) ;
6571 } ,
6672
6773 join : function ( channel ) {
68- raw ( [ "JOIN" , channel ] ) ;
74+ rawf ( "JOIN :%s " , channel ) ;
6975 } ,
7076
7177 part : function ( channel , reason ) {
72- raw ( "PART " + channel + ( reason ? " :" + reason : '' ) ) ;
78+ raw ( "PART " + channel + ( reason ? " :" + reason : "" ) ) ;
7379 } ,
7480
7581 nick : function ( newNick ) {
7682 if ( newNick ) {
77- raw ( "NICK " + newNick ) ;
83+ rawf ( "NICK %s" , newNick ) ;
7884 nick = newNick ;
7985 return ;
8086 } else {
@@ -83,6 +89,7 @@ var OutputSocket = function (socket, logger, nick) {
8389 } ,
8490
8591 quit : function ( reason ) {
92+ logger . notice ( format ( "Quitting with reason: %s" , reason ) ) ;
8693 raw ( "QUIT" + ( reason ? " :" + reason : "" ) ) ;
8794 } ,
8895
@@ -104,34 +111,35 @@ var OutputSocket = function (socket, logger, nick) {
104111 raw ( [ "MODE" , target , args ] ) ;
105112 } ,
106113
107- userhost : function userhost ( users ) {
114+ userhost : function recur ( users ) {
108115 if ( typeof users === 'string' ) {
109- raw ( "USERHOST " + users ) ;
116+ rawf ( "USERHOST :%s" , users ) ;
110117 } else if ( typeof users === 'array' ) {
111118 partition ( users , 5 )
112119 . map ( function ( hosts ) { return hosts . join ( ' ' ) ; } )
113- . map ( userhost ) ;
120+ . map ( recur ) ;
114121 } else {
115122 throw new Error ( "Userhost command takes either a string (a single nick) or an array (of string nicks)" ) ;
116123 }
117124 } ,
118125
119- whois : function whois ( users , server ) {
126+ whois : function recur ( users , server ) {
120127 if ( typeof users === "array" ) {
121128 if ( users . length > 15 ) {
122129 partition ( users , 15 )
123130 . map ( function ( users ) { return users . join ( ',' ) ; } )
124- . map ( function ( users ) { whois ( users , server ) ; } ) ;
131+ . map ( function ( users ) { recur ( users , server ) ; } ) ;
125132 }
126133 } else if ( typeof users === 'string' ) {
127- raw ( "WHOIS " + server ? server + " " : "" + users ) ;
134+ raw ( "WHOIS " + ( server ? server + " " : "" ) + users ) ;
128135 } else {
129136 throw new Error ( "Whois command takes either a string (a single nick) or an array (of string nicks)" ) ;
130137 }
131138 } ,
132139
133140 _raw : raw ,
134- toString : require ( './make-toString' ) ( 'OutputSocket' )
141+ _rawf : rawf ,
142+ toString : function ( ) { return "[Object IrcOutputSocket]" ; }
135143 } ;
136144} ;
137145
0 commit comments