This repository was archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathirc_commands.js
More file actions
341 lines (322 loc) · 12.6 KB
/
irc_commands.js
File metadata and controls
341 lines (322 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
jIRCs.prototype.irc_PING = function(prefix, args) {
this.send('PONG',args);
};
jIRCs.prototype.irc_NICK = function(prefix, args) {
var oldNick = this.getNick(prefix),
newNick = args.pop();
if(oldNick == this.nickname) {
this.nickname = newNick;
allCookies.setItem("jirc-nickname", this.nickname);
}
this.forEach(this.channels, function(c, channel) {
if(c.names && oldNick in c.names) {
this.renderLine(channel, channel, oldNick + ' is now known as ' + newNick);
c.names[newNick] = c.names[oldNick];
delete(c.names[oldNick]);
}
}, this);
this.forEach(this.displays, function(disobj) {
this.render(disobj);
}, this);
};
jIRCs.prototype.irc_JOIN = function(prefix, args) {
var channel = args.pop().toLowerCase();
if(prefix != this.nickname) {
//this.renderLine(channel, channel, prefix + " joined " + channel);
} else {
this.renderLine(channel, channel, "You have joined " + channel);
}
if(!this.channels[channel].names) {
this.channels[channel].names = {};
}
this.channels[channel].names[prefix] = "";
if (!this.channels[channel].modes) {
this.channels[channel].modes = {};
this.send('MODE', [channel]); // Get the initial modes because the server doesn't send them by default
}
this.forEach(this.displays, function(disobj) {
if(channel.charAt(0) == "#" && prefix == this.nickname) {
this.activateChan(channel, disobj);
}
if(disobj.viewing == channel) {
this.addUser(disobj);
}
}, this);
};
jIRCs.prototype.irc_PART = function(prefix, args) {
var channel = args.shift().toLowerCase();
var reason = args.pop();
if(this.getNick(prefix) == this.nickname) {
this.destroyChan(channel);
} else {
//this.renderLine(channel, channel, prefix + " left " + channel + " [" + reason + "]");
delete(this.channels[channel].names[prefix]);
this.forEach(this.displays, function(disobj) {
if(disobj.viewing == channel) {
this.removeUser(disobj, prefix);
}
}, this);
}
};
jIRCs.prototype.irc_QUIT = function(prefix, args) {
var reason = args.pop();
this.forEach(this.channels, function(c, channel) {
if(channel == 'Status') {
return;
}
if(c.names && prefix in c.names) {
//this.renderLine(channel, channel, prefix + ' quit (' + reason + ')');
delete(c.names[prefix]);
}
}, this);
if(this.getNick(prefix) == this.nickname) {
// Let ondisconnect handle cleanup
} else {
this.forEach(this.displays, function(disobj) {
this.removeUser(disobj, prefix);
}, this);
}
};
jIRCs.prototype.irc_PRIVMSG = function(prefix, args) {
var channel = args.shift().toLowerCase();
var message = args.pop();
//account for private messages
if (channel == this.nickname.toLowerCase()) {
channel = prefix.toLowerCase();
}
if (channel.charAt(0) in this.statusSymbols) {
prefix += ":" + channel; // give a visible indication that the message isn't for the whole channel
channel = channel.substr(1); // trim the status char off so the message gets displayed to the correct channel
}
if(message.charAt(0) == '\u0001') {
message = message.split('\u0001')[1];
if(message.substr(0,6).toUpperCase() == 'ACTION') {
message = prefix + message.substr(6);
prefix = '';
this.renderLine(channel, prefix, message);
} else {
args = message.split(' ');
var method = 'ctcp_' + args.shift().toUpperCase();
if(method in this) {
this[method](channel, args);
}
}
} else {
this.renderLine(channel, "<"+prefix+">", message);
}
if(prefix == "BidServ") {
var cleaned = message.replace("\u0001","").replace("\u0002","").replace("\u00034","").replace("\u000F","").replace("\u0016","").replace("\u001D","").replace("\u001F","");
var parts = cleaned.split(" ");
if(parts.slice(0,2).join(" ") == "Starting Auction") {
var id = parts[4].slice(1,-1);
var name = parts.slice(5,-4).join(" ").slice(1,-2);
this.auctionStart(id,name);
} else if(parts.slice(0,3).join(" ") == "Beginning bidding at") {
var starting = parts[3];
this.auctionBid(starting,"Nobody");
} else if(~cleaned.indexOf("has the high bid of")) { // ~ abuses two's complement notation to make -1 false, and everything else true
var index = 0;
while(index < parts.length - 5) {
if(parts[index+1] == "has" && parts[index+2] == "the" && parts[index+3] == "high" && parts[index+4] == "bid" && parts[index+5] == "of")
break;
index++;
}
var bidder = parts[index];
var bid = parts[index + 6];
this.auctionBid(bid,bidder);
} else if(~cleaned.indexOf("New highest bid is by")) {
parts = cleaned.substr(cleaned.indexOf("New highest bid is by")).split(" ");
var bidder = parts[5];
var bid = parts[7];
this.auctionBid(bid,bidder);
} else if(parts.slice(0,2).join(" ") == "Auction for" && ~cleaned.indexOf("cancelled")) {
this.auctionStop();
} else if(parts[0] == "Sold!") {
this.auctionStop();
}
}
};
jIRCs.prototype.irc_NOTICE = function(prefix, args) {
var nick = '\u2013 ' + this.getNick(prefix);
var message = args.pop();
var dest = args.shift().toLowerCase(); // It'll only be used if it's a channel name, anyway
if (this.chantypes.indexOf(dest.charAt(0)) !== -1 || this.chantypes.indexOf(dest.charAt(1)) !== -1) { // There may or may not be a channel status in the parameter
nick += ":" + dest + ' \u2013'; // Give a visible indication that the message is a channel notice
if (dest.charAt(0) in this.statusSymbols) { // it's not going directly to all of a channel
dest = dest.substr(1); // display it in the correct window
}
this.renderLine(dest, nick, message);
} else {
nick += ' \u2013'; // \u2013 is an en-dash
this.forEach(this.displays, function(disobj) {
this.renderLine(disobj.viewing, nick, message, disobj);
}, this);
}
if(this.getNick(prefix) == "NickServ") {
if(message.slice(0,33) == "You are now identified. Welcome, ") {
this.setAccount(message.slice(33,-1));
} else if(message.slice(0,22) == "You are now logged out") {
this.setAccount(false);
}
}
};
jIRCs.prototype.irc_KICK = function(prefix, args) {
var channel = args.shift().toLowerCase();
var message = args.pop();
this.renderLine(channel, "<"+prefix+">", "\u00034You have been kicked from "+channel+" (Reason: "+message+")");
};
jIRCs.prototype.irc_MODE = function(prefix, args) {
var channel = args.shift().toLowerCase();
var modes = args.shift().split('');
if (channel == this.nickname.toLowerCase()) { // handle user modes here
var adding = true;
this.forEach(modes, function(mode) {
switch (mode) {
case '+':
adding = true;
break;
case '-':
adding = false;
break;
default:
if (adding) {
this.userModes.push(mode);
} else {
var modePos = this.userModes.indexOf(mode);
if (modePos != -1) {
this.userModes.splice(modePos, 1);
}
}
}
}, this);
} else {
// At this point, what's left in args is the parameter list
this.parseModes(channel, modes, args); // handle the channel modes
}
};
jIRCs.prototype.irc_CAP = function(prefix, args) {
// :server CAP dest subcommand :capability list
if (args[1] == "LS") {
var supportedCaps = args[2].split(' ');
if (supportedCaps.indexOf("multi-prefix") != -1) {
this.send("CAP", ["REQ", ":multi-prefix"]);
} else if (!this.registered) {
this.send("CAP", ["END"]);
}
} else if (args[1] == "ACK" && !this.registered) {
this.send("CAP", ["END"]);
}
}
jIRCs.prototype.irc_001 = function(prefix, args) {
this.registered = true;
}
jIRCs.prototype.irc_005 = function(prefix, args) {
var server = args.shift();
var message = args.pop();
this.forEach(args, function(arg) {
if(arg.substr(0,7).toUpperCase() == 'PREFIX=') {
var modes = arg.substr(8).split(')'); // exclude the open paren, split close paren
var symbols = modes[1].split('');
var letters = modes[0].split('');
this.statuses = this.zip(symbols.concat(letters), letters.concat(symbols));
this.statusOrder = letters;
this.statusSymbols = this.zip(symbols, symbols);
this.statuses[''] = '';
this.statusOrder.push('');
}
if (arg.substr(0, 10) == 'CHANMODES=') {
var modes = arg.substr(10); // get all the channel modes
var groups = modes.split(',');
this.forEach(groups, function(group, groupNum) {
this.forEach(group, function(mode) {
this.chanModes[mode] = groupNum; // map modes to their group index for easy lookup
}, this);
}, this);
}
if (arg.substr(0, 10) == 'CHANTYPES=') {
this.chantypes = arg.substr(10).split('');
}
}, this);
};
jIRCs.prototype.irc_324 = function(prefix, args) {
args.shift(); // discard our nick; it's not useful
var channel = args.shift().toLowerCase();
var modes = args.shift().split('');
// At this point, what's left in args (if anything) is the mode parameter list
this.channels[channel].modes = {}; // Reset the channel modes list as 324 is all of the channel's current modes
this.parseModes(channel, modes, args);
};
jIRCs.prototype.irc_353 = function(prefix, args) {
var channel = args[2].toLowerCase();
if (!this.channels[channel].moreNames) {
this.channels[channel].names = {};
this.channels[channel].moreNames = true;
}
var names = args[3].split(' '); // Strip the colon and split the names out
this.forEach(names, function(name) {
var statusList = '';
while (name.charAt(0) in this.statusSymbols) {
statusList += name.charAt(0);
name = name.substr(1);
}
this.channels[channel].names[name] = statusList;
}, this);
};
jIRCs.prototype.irc_366 = function(prefix, args) {
var channel = args[1].toLowerCase();
this.channels[channel].moreNames = false;
this.forEach(this.displays, function(disobj) {
if(disobj.viewing == channel) {
this.render(disobj);
}
}, this);
};
jIRCs.prototype.irc_332 = function(prefix, args) {
var channel = args[1].toLowerCase();
if(!this.channels[channel].topic) {
this.channels[channel].topic = {};
}
this.channels[channel].topic.message = args[2];
this.forEach(this.displays, function(disobj) {
if(disobj.viewing == channel) {
this.render(disobj);
}
}, this);
};
jIRCs.prototype.irc_333 = function(prefix, args) {
var channel = args[1].toLowerCase();
if(!this.channels[channel].topic) {
this.channels[channel].topic = {};
}
this.channels[channel].topic.creator = args[2];
this.channels[channel].topic.time = new Date(args[3] * 1000);
this.forEach(this.displays, function(disobj) {
if(disobj.viewing == channel) {
this.render(disobj);
}
}, this);
};
jIRCs.prototype.irc_TOPIC = function(prefix, args) {
var channel = args[0].toLowerCase();
if(!this.channels[channel].topic) {
this.channels[channel].topic = {};
}
this.channels[channel].topic.creator = prefix;
this.channels[channel].topic.time = new Date();
this.channels[channel].topic.message = args[1];
this.forEach(this.displays, function(disobj) {
if(disobj.viewing == channel) {
this.render(disobj);
}
}, this);
};
jIRCs.prototype.irc_433 = function(prefix, args) {
this.nickname += "_";
allCookies.setItem("jirc-nickname", this.nickname);
this.send('NICK',[this.nickname]);
};
jIRCs.prototype.irc_unknown = function(prefix, args) {
if(args[0] == this.nickname)
args.shift();
this.renderLine("Status", prefix, args.join(" "));
};