]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commandparser.js
12ef4bd540fa79ea35bc9d9d236dcb94171e73ab
1 qwebirc
. irc
. BaseCommandParser
= new Class ({
2 initialize : function ( parentObject
) {
3 this . send
= parentObject
. send
;
4 this . parentObject
= parentObject
;
6 buildExtra : function ( extra
, target
, message
) {
10 extra
[ "n" ] = this . parentObject
. getNickname ();
15 newTargetLine : function ( target
, type
, message
, extra
) {
16 extra
= this . buildExtra ( extra
, target
, message
);
17 var window
= this . parentObject
. getWindow ( target
);
20 type
= "TARGETED" + type
;
22 this . parentObject
. newActiveLine ( "OUR" + type
, extra
);
24 } else if ( window
. type
== qwebirc
. ui
. WINDOW_CHANNEL
) {
30 this . parentObject
. newLine ( target
, "OUR" + type
, extra
);
32 newQueryLine : function ( target
, type
, message
, extra
) {
33 extra
= this . buildExtra ( extra
, target
, message
);
35 if ( this . parentObject
. ui
. uiOptions
. DEDICATED_MSG_WINDOW
) {
36 var window
= this . parentObject
. getWindow ( target
);
38 var w
= this . parentObject
. ui
. newWindow ( this . parentObject
, qwebirc
. ui
. WINDOW_MESSAGES
, "Messages" );
39 w
. addLine ( "OURTARGETED" + type
, extra
);
43 return this . newTargetLine ( target
, type
, message
, extra
);
45 dispatch : function ( line
) {
49 if ( line
. charAt ( 0 ) != "/" )
50 line
= "/SAY " + line
;
52 var line
= line
. substr ( 1 );
53 var allargs
= line
. splitMax ( " " , 2 );
54 var command
= allargs
[ 0 ]. toUpperCase ();
55 var args
= allargs
[ 1 ];
57 var aliascmd
= this . aliases
[ command
];
62 var cmdopts
= this [ "cmd_" + command
];
65 this . send ( command
+ " " + args
);
72 var activewin
= cmdopts
[ 0 ];
73 var splitargs
= cmdopts
[ 1 ];
74 var minargs
= cmdopts
[ 2 ];
77 var w
= this . getActiveWindow ();
78 if ( activewin
&& ( w
. type
!= qwebirc
. ui
. WINDOW_CHANNEL
&& w
. type
!= qwebirc
. ui
. WINDOW_QUERY
)) {
79 w
. errorMessage ( "Can't use this command in this window" );
83 if (( splitargs
!= undefined ) && ( args
!= undefined ))
84 args
= args
. splitMax ( " " , splitargs
);
86 if (( minargs
!= undefined ) && (
87 (( args
!= undefined ) && ( minargs
> args
. length
)) ||
88 (( args
== undefined ) && ( minargs
> 0 ))
90 w
. errorMessage ( "Insufficient arguments for command." );
94 var ret
= fn
. run ([ args
], this );
102 getActiveWindow : function () {
103 return this . parentObject
. getActiveWindow ();
107 qwebirc
. irc
. CommandParser
= new Class ({
108 Extends : qwebirc
. irc
. BaseCommandParser
,
109 initialize : function ( parentObject
) {
110 this . parent ( parentObject
);
122 newUIWindow : function ( property
) {
123 var p
= this . parentObject
. ui
[ property
];
125 this . getActiveWindow (). errorMessage ( "Current UI does not support that command." );
127 p
. bind ( this . parentObject
. ui
)();
131 /* [require_active_window, splitintoXargs, minargs, function] */
132 cmd_ME : [ true , undefined , undefined , function ( args
) {
133 if ( args
== undefined )
136 var target
= this . getActiveWindow (). name
;
137 if (! this . send ( "PRIVMSG " + target
+ " : \x01 ACTION " + args
+ " \x01 " ))
140 this . newQueryLine ( target
, "ACTION" , args
, { "@" : this . parentObject
. getNickStatus ( target
, this . parentObject
. nickname
)});
142 cmd_CTCP : [ false , 3 , 2 , function ( args
) {
143 var target
= args
[ 0 ];
144 var type
= args
[ 1 ]. toUpperCase ();
145 var message
= args
[ 2 ];
147 if ( message
== undefined )
151 if (! this . send ( "PRIVMSG " + target
+ " : \x01 " + type
+ " \x01 " ))
154 if (! this . send ( "PRIVMSG " + target
+ " : \x01 " + type
+ " " + message
+ " \x01 " ))
158 this . newTargetLine ( target
, "CTCP" , message
, { "x" : type
});
160 cmd_PRIVMSG : [ false , 2 , 2 , function ( args
) {
161 var target
= args
[ 0 ];
162 var message
= args
[ 1 ];
164 if (! this . parentObject
. isChannel ( target
))
165 this . parentObject
. pushLastNick ( target
);
166 if ( this . send ( "PRIVMSG " + target
+ " :" + message
))
167 this . newQueryLine ( target
, "MSG" , message
, { "@" : this . parentObject
. getNickStatus ( target
, this . parentObject
. nickname
)});
169 cmd_NOTICE : [ false , 2 , 2 , function ( args
) {
170 var target
= args
[ 0 ];
171 var message
= args
[ 1 ];
173 if ( this . send ( "NOTICE " + target
+ " :" + message
)) {
174 if ( this . parentObject
. isChannel ( target
)) {
175 this . newTargetLine ( target
, "NOTICE" , message
, { "@" : this . parentObject
. getNickStatus ( target
, this . parentObject
. nickname
)});
177 this . newTargetLine ( target
, "NOTICE" , message
);
181 cmd_QUERY : [ false , 2 , 1 , function ( args
) {
182 if ( this . parentObject
. isChannel ( args
[ 0 ])) {
183 this . getActiveWindow (). errorMessage ( "Can't target a channel with this command." );
187 this . parentObject
. newWindow ( args
[ 0 ], qwebirc
. ui
. WINDOW_QUERY
, true );
189 if (( args
. length
> 1 ) && ( args
[ 1 ] != "" ))
190 return [ "SAY" , args
[ 1 ]];
192 cmd_SAY : [ true , undefined , undefined , function ( args
) {
193 if ( args
== undefined )
196 return [ "PRIVMSG" , this . getActiveWindow (). name
+ " " + args
]
198 cmd_ABOUT : [ false , undefined , undefined , function ( args
) {
201 "qwebirc v" + qwebirc
. VERSION
,
202 "Copyright (C) 2008 Chris Porter. All rights reserved." ,
203 "http://webchat.quakenet.org/" ,
205 "For licensing questions please contact slug@quakenet.org." ,
207 "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." ,
209 "This software contains portions by the following third parties:" ,
210 "- MooTools v1.2 -- http://mootools.net/" ,
211 " Copyright (C) 2006-2008 Valerio Proietti, MIT license." ,
212 "- qwebirc icon -- http://meeb.org/" ,
213 "- SoundManager 2 -- http://www.schillmania.com/projects/soundmanager2/" ,
214 " Copyright (C) 2007, Scott Schiller (schillmania.com), BSD license." ,
216 "Thank you for flying QuakeNet!" ,
220 var aw
= this . getActiveWindow ();
221 lines
. forEach ( function ( x
) {
222 this . parentObject
. newActiveLine ( "" , x
);
225 cmd_LOGOUT : [ false , undefined , undefined , function ( args
) {
226 this . parentObject
. ui
. logout ();
228 cmd_OPTIONS : [ false , undefined , undefined , function ( args
) {
229 this . newUIWindow ( "optionsWindow" );
231 cmd_EMBED : [ false , undefined , undefined , function ( args
) {
232 this . newUIWindow ( "embeddedWindow" );
234 cmd_QUOTE : [ false , 1 , 1 , function ( args
) {
237 cmd_KICK : [ true , 2 , 1 , function ( args
) {
238 var channel
= this . getActiveWindow (). name
;
241 var target
= args
[ 0 ];
246 this . send ( "KICK " + channel
+ " " + target
+ " :" + message
);
248 automode : function ( direction
, mode
, args
) {
249 var channel
= this . getActiveWindow (). name
;
251 var modes
= direction
;
252 for ( var i
= 0 ; i
< args
. length
; i
++)
253 modes
= modes
+ mode
;
255 this . send ( "MODE " + channel
+ " " + modes
+ " " + args
. join ( " " ));
257 cmd_OP : [ true , 6 , 1 , function ( args
) {
258 this . automode ( "+" , "o" , args
);
260 cmd_DEOP : [ true , 6 , 1 , function ( args
) {
261 this . automode ( "-" , "o" , args
);
263 cmd_VOICE : [ true , 6 , 1 , function ( args
) {
264 this . automode ( "+" , "v" , args
);
266 cmd_DEVOICE : [ true , 6 , 1 , function ( args
) {
267 this . automode ( "-" , "v" , args
);
269 cmd_TOPIC : [ true , 1 , 1 , function ( args
) {
270 this . send ( "TOPIC " + this . getActiveWindow (). name
+ " :" + args
[ 0 ]);
272 cmd_AWAY : [ false , 1 , 0 , function ( args
) {
273 this . send ( "AWAY :" + ( args
? args
[ 0 ]: "" ));
275 cmd_QUIT : [ false , 1 , 0 , function ( args
) {
276 this . send ( "QUIT :" + ( args
? args
[ 0 ]: "" ));
278 cmd_CYCLE : [ true , 1 , 0 , function ( args
) {
279 var c
= this . getActiveWindow (). name
;
281 this . send ( "PART " + c
+ " :" + ( args
? args
[ 0 ]: "rejoining. . ." ));
282 this . send ( "JOIN " + c
);
284 cmd_UMODE : [ false , 1 , 0 , function ( args
) {
285 this . send ( "MODE " + this . parentObject
. getNickname () + ( args
?( " " + args
[ 0 ]): "" ));
287 cmd_CLEAR : [ false , undefined , undefined , function ( args
) {
288 var w
= this . getActiveWindow (). lines
;
289 while ( w
. childNodes
. length
> 0 )
290 w
. removeChild ( w
. firstChild
);
292 cmd_PART : [ false , 2 , 0 , function ( args
) {
293 var w
= this . getActiveWindow ();
297 if ( w
. type
!= qwebirc
. ui
. WINDOW_CHANNEL
) {
298 if (! args
|| args
. length
== 0 ) {
299 w
. errorMessage ( "Insufficient arguments for command." );
306 if (! args
|| args
. length
== 0 ) {
309 var isChan
= this . parentObject
. isChannel ( args
[ 0 ]);
316 message
= args
. join ( " " );
321 this . send ( "PART " + channel
+ " :" + message
);