]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/irc/commands.js
f55f0a8ba4e7be8b8858513533e18493a76bd6b6
[irc/quakenet/qwebirc.git] / js / irc / commands.js
1 qwebirc.irc.Commands = new Class({
2 Extends: qwebirc.irc.BaseCommandParser,
3 initialize: function(parentObject) {
4 this.parent(parentObject);
5
6 this.aliases = new QHash({
7 "J": "JOIN",
8 "K": "KICK",
9 "MSG": "PRIVMSG",
10 "Q": "QUERY",
11 "BACK": "AWAY",
12 "PRIVACY": "PRIVACYPOLICY",
13 "HOP": "CYCLE",
14 "": "SAY",
15 "BLOCK": "IGNORE",
16 "UNBLOCK": "UNIGNORE"
17 });
18 },
19
20 newUIWindow: function(property) {
21 var p = this.parentObject.ui[property];
22 if(!$defined(p)) {
23 this.getActiveWindow().errorMessage("Current UI does not support that command.");
24 } else {
25 p.bind(this.parentObject.ui)();
26 }
27 },
28
29 /* [require_active_window, splitintoXargs, minargs, function] */
30 cmd_ME: [true, undefined, undefined, function(args) {
31 if(args == undefined)
32 args = "";
33
34 var target = this.getActiveWindow().name;
35 if(!this.send("PRIVMSG " + target + " :\x01ACTION " + args + "\x01"))
36 return;
37
38 this.newQueryLine(target, "ACTION", args, {"@": this.parentObject.getNickStatus(target, this.parentObject.nickname)});
39 }],
40 cmd_CTCP: [false, 3, 2, function(args) {
41 var target = args[0];
42 var type = args[1].toUpperCase();
43 var message = args[2];
44
45 if(message == undefined)
46 message = "";
47
48 if(message == "") {
49 if(!this.send("PRIVMSG " + target + " :\x01" + type + "\x01"))
50 return;
51 } else {
52 if(!this.send("PRIVMSG " + target + " :\x01" + type + " " + message + "\x01"))
53 return;
54 }
55
56 this.newTargetLine(target, "CTCP", message, {"x": type});
57 }],
58 cmd_PRIVMSG: [false, 2, 2, function(args) {
59 var target = args[0];
60 var message = args[1];
61
62 if(!this.parentObject.isChannel(target))
63 this.parentObject.pushLastNick(target);
64 if(this.send("PRIVMSG " + target + " :" + message))
65 this.newQueryLine(target, "MSG", message, {"@": this.parentObject.getNickStatus(target, this.parentObject.nickname)});
66 }],
67 cmd_NOTICE: [false, 2, 2, function(args) {
68 var target = args[0];
69 var message = args[1];
70
71 if(this.send("NOTICE " + target + " :" + message)) {
72 if(this.parentObject.isChannel(target)) {
73 this.newTargetLine(target, "NOTICE", message, {"@": this.parentObject.getNickStatus(target, this.parentObject.nickname)});
74 } else {
75 this.newTargetLine(target, "NOTICE", message);
76 }
77 }
78 }],
79 cmd_QUERY: [false, 2, 1, function(args) {
80 if(this.parentObject.isChannel(args[0])) {
81 this.getActiveWindow().errorMessage("Can't target a channel with this command.");
82 return;
83 }
84
85 this.parentObject.newWindow(args[0], qwebirc.ui.WINDOW_QUERY, true);
86
87 if((args.length > 1) && (args[1] != ""))
88 return ["SAY", args[1]];
89 }],
90 cmd_SAY: [true, undefined, undefined, function(args) {
91 if(args == undefined)
92 args = "";
93
94 return ["PRIVMSG", this.getActiveWindow().name + " " + args]
95 }],
96 cmd_IGNORE: [false, 1, 0, function(args) {
97 var w = this.getActiveWindow();
98 var info = w.infoMessage.bind(w);
99 if(!args || args.length == 0) {
100 var l = this.parentObject.getIgnoreList();
101 if(l.length == 0) {
102 info("IGNOREEMPTY", "");
103 } else {
104 info("IGNOREHEADER", "");
105 l.forEach(function(v) {
106 info("IGNOREENTRY", {"h": v});
107 });
108 }
109 } else {
110 var nick = args[0];
111 this.parentObject.ignore(nick);
112 info("IGNORED", {"n": nick});
113 }
114 }],
115 cmd_UNIGNORE: [false, 1, 1, function(args) {
116 var nick = args[0];
117 this.parentObject.unignore(nick);
118 this.parentObject.getActiveWindow().infoMessage("UNIGNORED", {"n": nick});
119 }],
120 cmd_LOGOUT: [false, undefined, undefined, function(args) {
121 this.parentObject.ui.logout();
122 }],
123 cmd_OPTIONS: [false, undefined, undefined, function(args) {
124 this.newUIWindow("optionsWindow");
125 }],
126 cmd_EMBED: [false, undefined, undefined, function(args) {
127 this.newUIWindow("embeddedWindow");
128 }],
129 cmd_PRIVACYPOLICY: [false, undefined, undefined, function(args) {
130 this.newUIWindow("privacyWindow");
131 }],
132 cmd_ABOUT: [false, undefined, undefined, function(args) {
133 this.newUIWindow("aboutWindow");
134 }],
135 cmd_QUOTE: [false, 1, 1, function(args) {
136 this.send(args[0]);
137 }],
138 cmd_KICK: [true, 2, 1, function(args) {
139 var channel = this.getActiveWindow().name;
140
141 var message = "";
142 var target = args[0];
143
144 if(args.length == 2)
145 message = args[1];
146
147 this.send("KICK " + channel + " " + target + " :" + message);
148 }],
149 automode: function(direction, mode, args) {
150 var channel = this.getActiveWindow().name;
151
152 var modes = direction;
153 for(var i=0;i<args.length;i++)
154 modes = modes + mode;
155
156 this.send("MODE " + channel + " " + modes + " " + args.join(" "));
157 },
158 cmd_OP: [true, 6, 1, function(args) {
159 this.automode("+", "o", args);
160 }],
161 cmd_DEOP: [true, 6, 1, function(args) {
162 this.automode("-", "o", args);
163 }],
164 cmd_VOICE: [true, 6, 1, function(args) {
165 this.automode("+", "v", args);
166 }],
167 cmd_DEVOICE: [true, 6, 1, function(args) {
168 this.automode("-", "v", args);
169 }],
170 cmd_TOPIC: [false, 1, 1, function(args) {
171 var w = this.getActiveWindow();
172 if(w.client.isChannel(args[0])) {
173 this.send("TOPIC " + args[0]);
174 } else {
175 this.send("TOPIC " + w.name + " :" + args[0]);
176 }
177 }],
178 cmd_AWAY: [false, 1, 0, function(args) {
179 this.send("AWAY :" + (args?args[0]:""));
180 }],
181 cmd_QUIT: [false, 1, 0, function(args) {
182 this.send("QUIT :" + (args?args[0]:""));
183 }],
184 cmd_CYCLE: [true, 1, 0, function(args) {
185 var c = this.getActiveWindow().name;
186
187 this.send("PART " + c + " :" + (args?args[0]:"rejoining. . ."));
188 this.send("JOIN " + c);
189 }],
190 cmd_JOIN: [false, 2, 1, function(args) {
191 var channels = args.shift();
192
193 var schans = channels.split(",");
194 var fchans = [];
195
196 var warn = false;
197
198 schans.forEach(function(x) {
199 if(!this.parentObject.isChannel(x)) {
200 x = "#" + x;
201 warn = true;
202 }
203 fchans.push(x);
204 }.bind(this));
205
206 if(warn) {
207 var delayinfo = function() {
208 this.getActiveWindow().infoMessage("Channel names begin with # (corrected automatically).");
209 }.bind(this).delay(250);
210 }
211
212 this.send("JOIN " + fchans.join(",") + " " + args.join(" "));
213 }],
214 cmd_UMODE: [false, 1, 0, function(args) {
215 this.send("MODE " + this.parentObject.getNickname() + (args?(" " + args[0]):""));
216 }],
217 cmd_BEEP: [false, undefined, undefined, function(args) {
218 this.parentObject.ui.beep();
219 }],
220 cmd_AUTOJOIN: [false, undefined, undefined, function(args) {
221 return ["JOIN", this.parentObject.options.autojoin];
222 }],
223 cmd_HELP: [false, undefined, undefined, function(args) {
224 if(qwebirc.global.helpURL) {
225 this.newUIWindow("helpWindow");
226 } else {
227 this.send("HELP" + (args ? (" " + args[0]) : ""));
228 }
229 }],
230 cmd_CLEAR: [false, undefined, undefined, function(args) {
231 var w = this.getActiveWindow().lines;
232 while(w.childNodes.length > 0)
233 w.removeChild(w.firstChild);
234 }],
235 cmd_PART: [false, 2, 0, function(args) {
236 var w = this.getActiveWindow();
237 var message = "";
238 var channel;
239
240 if(w.type != qwebirc.ui.WINDOW_CHANNEL) {
241 if(!args || args.length == 0) {
242 w.errorMessage("Insufficient arguments for command.");
243 return;
244 }
245 channel = args[0];
246 if(args.length > 1)
247 message = args[1];
248 } else {
249 if(!args || args.length == 0) {
250 channel = w.name;
251 } else {
252 var isChan = this.parentObject.isChannel(args[0]);
253 if(isChan) {
254 channel = args[0];
255 if(args.length > 1)
256 message = args[1];
257 } else {
258 channel = w.name;
259 message = args.join(" ");
260 }
261 }
262 }
263
264 this.send("PART " + channel + " :" + message);
265 }]
266 });