]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commandparser.js
65ec8823d665ae8c26d04e653f1d5313e3b73f16
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 . parentObject
. isChannel ( target
))
129 this . parentObject
. pushLastNick ( target
);
130 if ( this . send ( "PRIVMSG " + target
+ " :" + message
))
131 this . newTargetLine ( target
, "MSG" , message
, {});
133 cmd_NOTICE : [ false , 2 , 2 , function ( args
) {
134 var target
= args
[ 0 ];
135 var message
= args
[ 1 ];
137 if ( this . send ( "NOTICE " + target
+ " :" + message
))
138 this . newTargetLine ( target
, "NOTICE" , message
);
140 cmd_QUERY : [ false , 2 , 1 , function ( args
) {
141 this . parentObject
. newWindow ( args
[ 0 ], qwebirc
. ui
. WINDOW_QUERY
, true );
143 if (( args
. length
> 1 ) && ( args
[ 1 ] != "" ))
144 return [ "SAY" , args
[ 1 ]];
146 cmd_SAY : [ true , undefined , undefined , function ( args
) {
147 if ( args
== undefined )
150 return [ "PRIVMSG" , this . parentObject
. getActiveWindow (). name
+ " " + args
]
152 cmd_ABOUT : [ false , undefined , undefined , function ( args
) {
155 "qwebirc v" + qwebirc
. VERSION
,
156 "Copyright (C) 2008 Chris Porter. All rights reserved." ,
157 "http://webchat.quakenet.org/" ,
158 "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." ,
160 "This software contains portions by the following third parties:" ,
161 "- MooTools v1.2 -- http://mootools.net/" ,
162 " Copyright (C) 2006-2008 Valerio Proietti, MIT license." ,
164 "Thank you for flying QuakeNet!" ,
168 var aw
= this . parentObject
. getActiveWindow ();
169 lines
. forEach ( function ( x
) {
170 this . parentObject
. newActiveLine ( "" , x
);
173 cmd_QUOTE : [ false , 1 , 1 , function ( args
) {
176 cmd_KICK : [ true , 2 , 1 , function ( args
) {
177 var channel
= this . parentObject
. getActiveWindow (). name
;
180 var target
= args
[ 0 ];
185 this . send ( "KICK " + channel
+ " " + target
+ " :" + message
);
187 automode : function ( direction
, mode
, args
) {
188 var channel
= this . parentObject
. getActiveWindow (). name
;
190 var modes
= direction
;
191 for ( var i
= 0 ; i
< args
. length
; i
++)
192 modes
= modes
+ mode
;
194 this . send ( "MODE " + channel
+ " " + modes
+ " " + args
. join ( " " ));
196 cmd_OP : [ true , 6 , 1 , function ( args
) {
197 this . automode ( "+" , "o" , args
);
199 cmd_DEOP : [ true , 6 , 1 , function ( args
) {
200 this . automode ( "-" , "o" , args
);
202 cmd_VOICE : [ true , 6 , 1 , function ( args
) {
203 this . automode ( "+" , "v" , args
);
205 cmd_DEVOICE : [ true , 6 , 1 , function ( args
) {
206 this . automode ( "-" , "v" , args
);
208 cmd_TOPIC : [ true , 1 , 1 , function ( args
) {
209 this . send ( "TOPIC " + this . parentObject
. getActiveWindow (). name
+ " :" + args
[ 0 ]);
211 cmd_AWAY : [ false , 1 , 0 , function ( args
) {
212 this . send ( "AWAY :" + ( args
? args
[ 0 ]: "" ));
214 cmd_QUIT : [ false , 1 , 0 , function ( args
) {
215 this . send ( "QUIT :" + ( args
? args
[ 0 ]: "" ));
217 cmd_CYCLE : [ true , 1 , 0 , function ( args
) {
218 var c
= this . parentObject
. getActiveWindow (). name
;
220 this . send ( "PART " + c
+ " :" + ( args
? args
[ 0 ]: "rejoining. . ." ));
221 this . send ( "JOIN " + c
);
223 cmd_CLEAR : [ false , undefined , undefined , function ( args
) {
224 var w
= this . parentObject
. getActiveWindow (). lines
;
225 while ( w
. childNodes
. length
> 0 )
226 w
. removeChild ( w
. firstChild
);
228 cmd_PART : [ false , 2 , 0 , function ( args
) {
229 var w
= this . parentObject
. getActiveWindow ();
233 if ( w
. type
== qwebirc
. ui
. WINDOW_STATUS
) {
234 if (! args
|| args
. length
== 0 ) {
235 w
. errorMessage ( "Insufficient arguments for command." );
242 if (! args
|| args
. length
== 0 ) {
245 var isChan
= this . parentObject
. isChannel ( args
[ 0 ]);
252 message
= args
. join ( " " );
257 this . send ( "PART " + channel
+ " :" + message
);