-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommands.js
423 lines (379 loc) · 15.9 KB
/
commands.js
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/**
* Commands
* Cassius - https://github.com/sirDonovan/Cassius
*
* This file contains the base commands for Cassius.
*
* @license MIT license
*/
'use strict';
const gifts = ["A new pair of pants", "A hug C:", "The new copy of sun and moon you were hoping for!"];
const jokes = ["How does a tree go? It leaves.",
"Why didn't the skeleton go to the party? He had no-body to dance with!",
"Why didn't the skeleton cross the road? Because he didn't have the guts!",
'"Somebody told me you remind them of an owl." "Who?"',
"How do you make an octopus laugh? With ten-tickles!",
"What's an octupus' favorite dessert? Octo-pi!",
"This joke is like a bar at a wedding; it has no punchline.",
'There were two twins named Juan and Amal. I saw a picture of Juan, and wanted to see Amal to compare them, but my friend said, "once you\'ve seen Juan you\'ve seen Amal.',
"What do you call an alligator in a vest? An investigator!",
"Whats a ghosts favorite fruit? Booberries.",
"Whats a vampires favorite fruit? Necktarines.",
"What do you get when you cross a snowman and a vampire? Frostbite.",
"What do you call it when you Santa stops moving? Santa Pause."
]
// Users who use the settour command when a tournament is already
// scheduled will be added here and prompted to reuse the command.
// This prevents accidentally overwriting a scheduled tournament.
/**@type {Map<string, string>} */
let overwriteWarnings = new Map();
/**@type {{[k: string]: Command | string}} */
let commands = {
// Developer commands
js: 'eval',
eval: function (target, room, user) {
if (!user.isDeveloper()) return;
try {
target = eval(target);
this.say(JSON.stringify(target));
} catch (e) {
this.say(e.name + ": " + e.message);
}
},
gift: function (target, room, user) {
if (!user.isDeveloper() && !user.hasRank(room, '+') && (!Games.host || Games.host.id !== user.id)) return;
let userTar = Users.get(target);
if (!userTar) return;
this.say("Inside " + userTar.name + "'s gift is ..." + Tools.sample(gifts));
},
joke: function (target, room, user) {
if (!user.isDeveloper() && !user.hasRank(room, '+') && (!Games.host || Games.host.id !== user.id)) return;
room.say(Tools.sample(jokes));
},
c: 'roomsay',
roomsay: function (target, room, user) {
if (!user.isDeveloper()) return;
let splitStr = target.split(",");
if (splitStr.length !== 2) return;
let realroom = Rooms.get(splitStr[0]);
if (!realroom) return;
realroom.say(splitStr[1]);
},
jr:'joinroom',
joinroom: function (target,room, user){
if (!user.isDeveloper() || !(room instanceof Users.User) && !user.hasRank(room, '+')) return;
this.say("/join " + target);
},
pick: function (target, room, user) {
if (!user.hasRank(room, '+') && (!Games.host || Games.host.id !== user.id)) return;
if (Users.self.hasRank(room, '*')) {
let stuff = target.split(",");
let str = "<em>We randomly picked:</em> " + Tools.sample(stuff);
if (room.id === 'developmen') {
room.say("/addhtmlbox " + str);
} else {
room.say("!htmlbox " + str);
}
}
else {
this.say("!pick " + target);
}
},
timer: function (target, room, user) {
if (!user.hasRank(room, '+') && (!Games.host || Games.host.id !== user.id)) return;
let x = Math.floor(target);
if (!x || x >= 120 || (x < 10 && x > 2) || x <= 0) return room.say("The timer must be between 10 seconds and 2 minutes.");
if (x === 1) x = 60;
let minutes = Math.floor(x / 60);
let seconds = x % 60;
clearTimeout(Games.timeout);
this.say("Timer set for " + (minutes > 0 ? "1 minute" + (seconds > 0 ? " and " : "") : "") + (seconds > 0 ? ((seconds) + " second" + (seconds > 1 ? "s" : "")) : "") + ".");
setTimeout(() => this.say("Times Up!"), x * 1000);
},
roll: function (target, room, user) {
let realtarget = target;
if (!user.hasRank(room, '+') && (!Games.host || Games.host.id !== user.id)) return;
let plusIndex = target.indexOf("+");
let adder = 0;
if (plusIndex !== -1) {
adder = parseInt(target.substr(plusIndex + 1));
let str = adder.toString();
if (str.length !== (target.substr(plusIndex + 1)).length) return;
if (!adder) return;
target = target.substr(0, plusIndex);
}
let dIndex = target.indexOf("d");
let numDice = 1;
let roll;
if (dIndex !== -1) {
numDice = parseInt(target.substr(0, dIndex));;
if (!numDice) return;
roll = parseInt(target.substr(dIndex + 1));
if (!roll) return;
} else {
roll = parseInt(target);
if (!roll) return;
}
let rolls = [];
let sum = 0;
for (let i = 0; i < numDice; i++) {
rolls.push(Tools.random(roll) + 1);
sum += rolls[i];
}
if ((Users.self.hasRank(room, "*"))) {
if (numDice === 1) {
let str = "Roll (1 - " + roll + "): " + rolls[0];
if (room.id === 'survivor') {
this.say("/addhtmlbox " + str);
} else {
this.say("!htmlbox " + str);
}
} else {
let str = numDice + " Rolls (1 - " + roll + "): " + rolls.join(", ") + "<br></br>" + "Sum: " + sum;
if (room.id === 'survivor') {
this.say("/addhtmlbox " + str);
} else {
this.say("!htmlbox " + str);
}
}
} else {
room.say("Rolls: " + rolls.join(",") + " || Total: " + (sum + adder));
}
},
about: function (target, room, user) {
if (!(room instanceof Users.User) && !user.hasRank(room, '+')) return;
this.say(Config.username + " https://github.com/Zerapium/Phantom-Ozonix");
},
help: function (target, room, user) {
if (!(room instanceof Users.User) && !user.hasRank(room, '+')) return;
if (!Config.guide) return this.say("There is no guide available.");
this.say(Users.self.name + " guide: " + Config.guide);
},
mail: function (target, room, user) {
if (!(room instanceof Users.User) || !Config.allowMail) return;
let targets = target.split(',');
if (targets.length < 2) return this.say("Please use the following format: .mail user, message");
let to = Tools.toId(targets[0]);
if (!to || to.length > 18 || to === Users.self.id || to.startsWith('guest')) return this.say("Please enter a valid username");
let message = targets.slice(1).join(',').trim();
let id = Tools.toId(message);
if (!id) return this.say("Please include a message to send.");
if (message.length > (258 - user.name.length)) return this.say("Your message is too long.");
let database = Storage.getDatabase('global');
if (to in database.mail) {
let queued = 0;
for (let i = 0, len = database.mail[to].length; i < len; i++) {
if (Tools.toId(database.mail[to][i].from) === user.id) queued++;
}
if (queued >= 3) return this.say("You have too many messages queued for " + Users.add(targets[0]).name + ".");
} else {
database.mail[to] = [];
}
database.mail[to].push({time: Date.now(), from: user.name, text: message});
Storage.exportDatabase('global');
this.say("Your message has been sent to " + Users.add(targets[0]).name + "!");
},
// Game commands
signups: 'creategame',
games: 'creategame',
creategame: function (target, room, user) {
if (room instanceof Users.User) return;
if (!user.hasRank(room, '+')) return;
//if (!Config.games || !Config.games.includes(room.id)) return this.say("Games are not enabled for this room.");
let format = Games.getFormat(target);
if (!format || format.inheritOnly) return this.say("The game '" + target + "' was not found.");
if (format.internal) return this.say(format.name + " cannot be started manually.");
Games.createGame(format, room);
if (!room.game) return;
room.game.signups();
},
start: 'startgame',
startgame: function (target, room, user) {
if (!(room instanceof Users.User) && !user.hasRank(room, '+')) return;
if (room.game) room.game.start();
},
cap: 'capgame',
capgame: function (target, room, user) {
if (room instanceof Users.User || !room.game || !user.hasRank(room, '+')) return;
let cap = parseInt(target);
if (isNaN(cap)) return this.say("Please enter a valid player cap.");
if (cap < room.game.minPlayers) return this.say(room.game.name + " must have at least " + room.game.minPlayers + " players.");
if (room.game.maxPlayers && cap > room.game.maxPlayers) return this.say(room.game.name + " cannot have more than " + room.game.maxPlayers + " players.");
room.game.playerCap = cap;
this.say("The game will automatically start at **" + cap + "** players!");
},
mp: 'maxpoints',
maxpoints: function (target, room, user) {
if (room instanceof Users.User || !room.game || !user.hasRank(room, '+')) return;
let mp = parseInt(target);
if (isNaN(mp)) return this.say("Please enter a valid value.");
//if (cap < room.game.minPlayers) return this.say(room.game.name + " must have at least " + room.game.minPlayers + " players.");
//if (room.game.maxPlayers && cap > room.game.maxPlayers) return this.say(room.game.name + " cannot have more than " + room.game.maxPlayers + " players.");
room.game.maxPoints = mp;
this.say("Player with **" + mp + "** points wins the game!");
},
players: 'pl',
pl: function (target, room, user) {
if ((!user.isDeveloper() && !user.hasRank(room, '+')) || !room.game) return;
if (typeof room.game.pl === 'function') room.game.pl();
},
end: 'endgame',
endgame: function (target, room, user) {
if (!(room instanceof Users.User) && !user.hasRank(room, '+')) return;
if (room.game) room.game.forceEnd();
},
answer: 'a',
a: function (target, room, user) {
if (!room.game) return;
if (typeof room.game.guess === 'function') room.game.guess(target, user);
},
join: 'joingame',
joingame: function (target, room, user) {
if (room instanceof Users.User || !room.game) return;
room.game.join(user);
},
leave: 'leavegame',
leavegame: function (target, room, user) {
if (room instanceof Users.User || !room.game) return;
room.game.leave(user);
},
elim: 'eliminate',
eliminate: function (target, room, user) {
if (room instanceof Users.User || !room.game || !user.hasRank(room, '@')) return;
room.game.elim(target);
},
// Storage commands
bits: 'points',
points: function (target, room, user) {
if (room !== user) return;
let targetUserid = target ? Tools.toId(target) : user.id;
/**@type {Array<string>} */
let points = [];
user.rooms.forEach((rank, room) => {
if (!(room.id in Storage.databases) || !('leaderboard' in Storage.databases[room.id])) return;
if (targetUserid in Storage.databases[room.id].leaderboard) points.push("**" + room.id + "**: " + Storage.databases[room.id].leaderboard[targetUserid].points);
});
if (!points.length) return this.say((target ? target.trim() + " does not" : "You do not") + " have points on any leaderboard.");
this.say(points.join(" | "));
},
choose: function (target, room, user) {
for (room in Rooms.rooms) {
let realRoom = Rooms.rooms[room];
if (realRoom.game && typeof realRoom.game.choose === 'function') realRoom.game.choose(user, target);
}
},
suspect: function (target, room, user) {
if (room.name !== user.name) return;
let firstComma = target.indexOf(',');
if (firstComma === -1) {
user.say("The correct syntax is " + Config.commandCharacter + "suspect user, pokemon, room");
return;
}
let userID = target.substr(0, firstComma);
target = target.substr(firstComma + 1);
if (target.charAt(0) === ' ') {
target = target.substr(1);
}
for (room in Rooms.rooms) {
let realRoom = Rooms.rooms[room];
if (realRoom.game && typeof realRoom.game.suspect === 'function') realRoom.game.suspect(user, userID, target);
}
},
steal: function (target, room, user) {
if (!room.game) return;
if (typeof room.game.steal === 'function') room.game.steal(target, user);
},
count: function (target, room, user) {
if (!room.game) {
if (!user.hasRank(room, '+') || Tools.toId(target) !== "start") {
return;
}
Games.createGame("count", room)
} else if (typeof room.game.count === 'function') {
room.game.count(target,user);
}
},
// Tournament commands
tour: 'tournament',
tournament: function (target, room, user) {
if (room instanceof Users.User || !Config.tournaments || !Config.tournaments.includes(room.id)) return;
if (!target) {
if (!user.hasRank(room, '+')) return;
if (!room.tour) return this.say("I am not currently tracking a tournament in this room.");
let info = "``" + room.tour.name + " tournament info``";
if (room.tour.startTime) {
return this.say(info + ": **Time**: " + Tools.toDurationString(Date.now() - room.tour.startTime) + " | **Remaining players**: " + room.tour.getRemainingPlayerCount() + '/' + room.tour.totalPlayers);
} else if (room.tour.started) {
return this.say(info + ": **Remaining players**: " + room.tour.getRemainingPlayerCount() + '/' + room.tour.totalPlayers);
} else {
return this.say(info + ": " + room.tour.playerCount + " player" + (room.tour.playerCount > 1 ? "s" : ""));
}
} else {
if (!user.hasRank(room, '%')) return;
let targets = target.split(',');
let cmd = Tools.toId(targets[0]);
let format;
switch (cmd) {
case 'end':
this.say("/tour end");
break;
case 'start':
this.say("/tour start");
break;
default:
format = Tools.getFormat(cmd);
if (!format) return this.say('**Error:** invalid format.');
if (!format.playable) return this.say(format.name + " cannot be played, please choose another format.");
let cap;
if (targets[1]) {
cap = parseInt(Tools.toId(targets[1]));
if (cap < 2 || cap > Tournaments.maxCap || isNaN(cap)) return this.say("**Error:** invalid participant cap.");
}
this.say("/tour new " + format.id + ", elimination, " + (cap ? cap + ", " : "") + (targets.length > 2 ? ", " + targets.slice(2).join(", ") : ""));
}
}
},
settour: 'settournament',
settournament: function (target, room, user) {
if (room instanceof Users.User || !Config.tournaments || !Config.tournaments.includes(room.id) || !user.hasRank(room, '%')) return;
if (room.id in Tournaments.tournamentTimers) {
let warned = overwriteWarnings.has(room.id) && overwriteWarnings.get(room.id) === user.id;
if (!warned) {
overwriteWarnings.set(room.id, user.id);
return this.say("A tournament has already been scheduled in this room. To overwrite it, please reuse this command.");
}
overwriteWarnings.delete(room.id);
}
let targets = target.split(',');
if (targets.length < 2) return this.say(Config.commandCharacter + "settour - tier, time, cap (optional)");
let format = Tools.getFormat(targets[0]);
if (!format) return this.say('**Error:** invalid format.');
if (!format.playable) return this.say(format.name + " cannot be played, please choose another format.");
let date = new Date();
let currentTime = (date.getHours() * 60 * 60 * 1000) + (date.getMinutes() * (60 * 1000)) + (date.getSeconds() * 1000) + date.getMilliseconds();
let targetTime = 0;
if (targets[1].includes(':')) {
let parts = targets[1].split(':');
let hours = parseInt(parts[0]);
let minutes = parseInt(parts[1]);
if (isNaN(hours) || isNaN(minutes)) return this.say("Please enter a valid time.");
targetTime = (hours * 60 * 60 * 1000) + (minutes * (60 * 1000));
} else {
let hours = parseFloat(targets[1]);
if (isNaN(hours)) return this.say("Please enter a valid time.");
targetTime = currentTime + (hours * 60 * 60 * 1000);
}
let timer = targetTime - currentTime;
if (timer <= 0) timer += 24 * 60 * 60 * 1000;
Tournaments.setTournamentTimer(room, timer, format.id, targets[2] ? parseInt(targets[2]) : 0);
this.say("The " + format.name + " tournament is scheduled for " + Tools.toDurationString(timer) + ".");
},
canceltour: 'canceltournament',
canceltournament: function (target, room, user) {
if (room instanceof Users.User || !Config.tournaments || !Config.tournaments.includes(room.id) || !user.hasRank(room, '%')) return;
if (!(room.id in Tournaments.tournamentTimers)) return this.say("There is no tournament scheduled for this room.");
clearTimeout(Tournaments.tournamentTimers[room.id]);
this.say("The scheduled tournament was canceled.");
},
};
module.exports = commands;