]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commandparser.js
4efad3916350fcecf2581a0529070260a4ad57ca
1 qwebirc
. irc
. CommandParser
= new Class ({
2 initialize : function ( parentObject
) {
12 this . send
= parentObject
. send
;
13 this . parentObject
= parentObject
;
15 newTargetLine : function ( target
, type
, message
, extra
) {
19 extra
[ "n" ] = this . parentObject
. getNickname ();
23 var window
= this . parentObject
. getWindow ( target
);
26 type
= "TARGETED" + type
;
28 this . parentObject
. newActiveLine ( "OUR" + type
, extra
);
30 } else if ( window
. type
== qwebirc
. ui
. WINDOW_CHANNEL
) {
36 this . parentObject
. newLine ( target
, "OUR" + type
, extra
);
38 dispatch : function ( line
) {
42 if ( line
. charAt ( 0 ) != "/" )
43 line
= "/SAY " + line
;
45 var line
= line
. substr ( 1 );
46 var allargs
= line
. splitMax ( " " , 2 );
47 var command
= allargs
[ 0 ]. toUpperCase ();
48 var args
= allargs
[ 1 ];
50 var aliascmd
= this . aliases
[ command
];
55 var cmdopts
= this [ "cmd_" + command
];
58 this . send ( command
+ " " + args
);
65 var activewin
= cmdopts
[ 0 ];
66 var splitargs
= cmdopts
[ 1 ];
67 var minargs
= cmdopts
[ 2 ];
70 var w
= this . parentObject
. getActiveWindow ();
71 if ( activewin
&& w
. type
== qwebirc
. ui
. WINDOW_STATUS
) {
72 w
. errorMessage ( "Can't use this command in this window" );
76 if (( splitargs
!= undefined ) && ( args
!= undefined ))
77 args
= args
. splitMax ( " " , splitargs
);
79 if (( minargs
!= undefined ) && (
80 (( args
!= undefined ) && ( minargs
> args
. length
)) ||
81 (( args
== undefined ) && ( minargs
> 0 ))
83 w
. errorMessage ( "Insufficient arguments for command." );
87 var ret
= fn
. attempt ([ args
], this );
95 /* [require_active_window, splitintoXargs, minargs, function] */
96 cmd_ME : [ true , undefined , undefined , function ( args
) {
100 var target
= this . parentObject
. getActiveWindow (). name
;
101 if (! this . send ( "PRIVMSG " + target
+ " : \x01 ACTION " + args
+ " \x01 " ))
104 this . newTargetLine ( target
, "ACTION" , args
);
106 cmd_CTCP : [ false , 3 , 2 , function ( args
) {
107 var target
= args
[ 0 ];
108 var type
= args
[ 1 ]. toUpperCase ();
109 var message
= args
[ 2 ];
111 if ( message
== undefined )
115 if (! this . send ( "PRIVMSG " + target
+ " : \x01 " + type
+ " \x01 " ))
118 if (! this . send ( "PRIVMSG " + target
+ " : \x01 " + type
+ " " + message
+ " \x01 " ))
122 this . newTargetLine ( target
, "CTCP" , message
, { "x" : type
});
124 cmd_PRIVMSG : [ false , 2 , 2 , function ( args
) {
125 var target
= args
[ 0 ];
126 var message
= args
[ 1 ];
128 if ( this . send ( "PRIVMSG " + target
+ " :" + message
))
129 this . newTargetLine ( target
, "MSG" , message
, {});
131 cmd_NOTICE : [ false , 2 , 2 , function ( args
) {
132 var target
= args
[ 0 ];
133 var message
= args
[ 1 ];
135 if ( this . send ( "NOTICE " + target
+ " :" + message
))
136 this . newTargetLine ( target
, "NOTICE" , message
);
138 cmd_QUERY : [ false , 2 , 1 , function ( args
) {
139 this . parentObject
. newWindow ( args
[ 0 ], qwebirc
. ui
. WINDOW_QUERY
, true );
141 if (( args
. length
> 1 ) && ( args
[ 1 ] != "" ))
142 return [ "SAY" , args
[ 1 ]];
144 cmd_SAY : [ true , undefined , undefined , function ( args
) {
145 if ( args
== undefined )
148 return [ "PRIVMSG" , this . parentObject
. getActiveWindow (). name
+ " " + args
]
150 cmd_ABOUT : [ false , undefined , undefined , function ( args
) {
153 "qwebirc v" + qwebirc
. VERSION
,
154 "Copyright (C) 2008 Chris Porter. All rights reserved." ,
155 "http://webchat.quakenet.org/" ,
156 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \" AS IS \" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ,
158 "This software contains portions by the following third parties:" ,
159 "- MooTools v1.2 -- http://mootools.net/" ,
160 " Copyright (C) 2006-2008 Valerio Proietti, MIT license." ,
162 "Thank you for flying QuakeNet!" ,
166 var aw
= this . parentObject
. getActiveWindow ();
167 lines
. forEach ( function ( x
) {
168 this . parentObject
. newActiveLine ( "" , x
);
171 cmd_QUOTE : [ false , 1 , 1 , function ( args
) {
174 cmd_KICK : [ true , 2 , 1 , function ( args
) {
175 var channel
= this . parentObject
. getActiveWindow (). name
;
178 var target
= args
[ 0 ];
183 this . send ( "KICK " + channel
+ " " + target
+ " :" + message
);
185 automode : function ( direction
, mode
, args
) {
186 var channel
= this . parentObject
. getActiveWindow (). name
;
188 var modes
= direction
;
189 for ( var i
= 0 ; i
< args
. length
; i
++)
190 modes
= modes
+ mode
;
192 this . send ( "MODE " + channel
+ " " + modes
+ " " + args
. join ( " " ));
194 cmd_OP : [ true , 6 , 1 , function ( args
) {
195 this . automode ( "+" , "o" , args
);
197 cmd_DEOP : [ true , 6 , 1 , function ( args
) {
198 this . automode ( "-" , "o" , args
);
200 cmd_VOICE : [ true , 6 , 1 , function ( args
) {
201 this . automode ( "+" , "v" , args
);
203 cmd_DEVOICE : [ true , 6 , 1 , function ( args
) {
204 this . automode ( "-" , "v" , args
);
206 cmd_TOPIC : [ true , 1 , 1 , function ( args
) {
207 this . send ( "TOPIC " + this . parentObject
. getActiveWindow (). name
+ " :" + args
[ 0 ]);
209 cmd_AWAY : [ false , 1 , 0 , function ( args
) {
210 this . send ( "AWAY :" + ( args
? args
[ 0 ]: "" ));
212 cmd_CYCLE : [ true , 1 , 0 , function ( args
) {
213 var c
= this . parentObject
. getActiveWindow (). name
;
215 this . send ( "PART " + c
+ " :" + ( args
? args
[ 0 ]: "rejoining. . ." ));
216 this . send ( "JOIN " + c
);
218 cmd_CLEAR : [ false , undefined , undefined , function ( args
) {
219 var w
= this . parentObject
. getActiveWindow (). lines
;
220 while ( w
. childNodes
. length
> 0 )
221 w
. removeChild ( w
. firstChild
);
223 cmd_PART : [ false , 2 , 0 , function ( args
) {
224 var w
= this . parentObject
. getActiveWindow ();
228 if ( w
. type
== qwebirc
. ui
. WINDOW_STATUS
) {
229 if (! args
|| args
. length
== 0 ) {
230 w
. errorMessage ( "Insufficient arguments for command." );
237 if (! args
|| args
. length
== 0 ) {
240 var isChan
= args
[ 0 ]. charAt ( 0 ) == '#' ;
247 message
= args
. join ( " " );
252 this . send ( "PART " + channel
+ " :" + message
);