]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commandparser.js
7952d650d0fa24782bb88b3ed0ea33d138a1d58f
1 var CommandParser
= new Class({
2 initialize: function(parentObject
) {
10 this.send
= parentObject
.send
;
11 this.parentObject
= parentObject
;
13 newTargetLine: function(target
, type
, message
, extra
) {
17 extra
["n"] = this.parentObject
.getNickname();
21 var window
= this.parentObject
.getWindow(target
);
24 type
= "TARGETED" + type
;
26 this.parentObject
.newActiveLine("OUR" + type
, extra
);
28 } else if(window
.type
== WINDOW_CHANNEL
) {
34 this.parentObject
.newLine(target
, "OUR" + type
, extra
);
36 dispatch: function(line
) {
40 if(line
.charAt(0) != "/")
41 line
= "/SAY " + line
;
43 var line
= line
.substr(1);
44 var allargs
= line
.splitMax(" ", 2);
45 var command
= allargs
[0].toUpperCase();
46 var args
= allargs
[1];
48 var aliascmd
= this.aliases
[command
];
53 var cmdopts
= this["cmd_" + command
];
56 this.send(command
+ " " + args
);
63 var activewin
= cmdopts
[0];
64 var splitargs
= cmdopts
[1];
65 var minargs
= cmdopts
[2];
68 var w
= this.parentObject
.getActiveWindow();
69 if(activewin
&& w
.type
== WINDOW_STATUS
) {
70 w
.errorMessage("Can't use this command in this window");
74 if((splitargs
!= undefined) && (args
!= undefined))
75 args
= args
.splitMax(" ", splitargs
);
77 if((minargs
!= undefined) && (
78 ((args
!= undefined) && (minargs
> args
.length
)) ||
79 ((args
== undefined) && (minargs
> 0))
81 w
.errorMessage("Insufficient arguments for command.");
85 var ret
= fn
.attempt([args
], this);
93 cmd_ME: [true, undefined, undefined, function(args
) {
97 var target
= this.parentObject
.getActiveWindow().name
;
98 if(!this.send("PRIVMSG " + target
+ " :\x01ACTION " + args
+ "\x01"))
101 this.newTargetLine(target
, "ACTION", args
);
103 cmd_CTCP: [false, 3, 2, function(args
) {
104 var target
= args
[0];
105 var type
= args
[1].toUpperCase();
106 var message
= args
[2];
108 if(message
== undefined)
112 if(!this.send("PRIVMSG " + target
+ " :\x01" + type
+ "\x01"))
115 if(!this.send("PRIVMSG " + target
+ " :\x01" + type
+ " " + message
+ "\x01"))
119 this.newTargetLine(target
, "CTCP", message
, {"x": type
});
121 cmd_PRIVMSG: [false, 2, 2, function(args
) {
122 var target
= args
[0];
123 var message
= args
[1];
125 if(this.send("PRIVMSG " + target
+ " :" + message
))
126 this.newTargetLine(target
, "MSG", message
, {});
128 cmd_NOTICE: [false, 2, 2, function(args
) {
129 var target
= args
[0];
130 var message
= args
[1];
132 if(this.send("NOTICE " + target
+ " :" + message
))
133 this.newTargetLine(target
, "NOTICE", message
);
135 cmd_QUERY: [false, 2, 1, function(args
) {
136 this.parentObject
.newWindow(args
[0], WINDOW_QUERY
, true);
138 if((args
.length
> 1) && (args
[1] != ""))
139 return ["SAY", args
[1]];
141 cmd_SAY: [true, undefined, undefined, function(args
) {
142 if(args
== undefined)
145 return ["PRIVMSG", this.parentObject
.getActiveWindow().name
+ " " + args
]
147 KICK: [true, 3, 2, function(args
) {
148 var channel
= args
[0];
149 var target
= args
[1];
150 var message
= args
[2];
154 this.send("KICK " + channel
+ " " + target
+ " :" + message
);