-
Notifications
You must be signed in to change notification settings - Fork 9
/
chat-commands.js
5856 lines (5354 loc) · 192 KB
/
chat-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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* System commands
* Pokemon Showdown - http://pokemonshowdown.com/
*
* These are system commands - commands required for Pokemon Showdown
* to run. A lot of these are sent by the client.
*
* System commands should not be modified, added, or removed. If you'd
* like to modify or add commands, add or edit files in chat-plugins/
*
* For the API, see chat-plugins/COMMANDS.md
*
* @license MIT license
*/
"use strict";
/* eslint no-else-return: "error" */
const crypto = require("crypto");
const FS = require("./lib/fs");
const MAX_REASON_LENGTH = 300;
const MUTE_LENGTH = 7 * 60 * 1000;
const HOURMUTE_LENGTH = 60 * 60 * 1000;
const MAX_CHATROOM_ID_LENGTH = 225;
/** Require reasons */
const REQUIRE_REASONS = true;
/** @type {ChatCommands} */
const commands = {
"!version": true,
version: function(target, room, user) {
if (!this.runBroadcast()) return;
this.sendReplyBox(`Server version: <b>${Chat.package.version}</b>`);
},
"!authority": true,
auth: "authority",
stafflist: "authority",
globalauth: "authority",
authlist: "authority",
authority: function(target, room, user, connection) {
if (target) {
let targetRoom = Rooms.search(target);
let availableRoom = targetRoom && targetRoom.checkModjoin(user);
if (targetRoom && availableRoom)
return this.parse(`/roomauth1 ${target}`);
return this.parse(`/userauth ${target}`);
}
let rankLists = {};
let ranks = Object.keys(Config.groups);
for (let u in Users.usergroups) {
let rank = Users.usergroups[u].charAt(0);
if (rank === " " || rank === "/") continue;
// In case the usergroups.csv file is not proper, we check for the server ranks.
if (ranks.includes(rank)) {
let name = Users.usergroups[u].substr(1);
if (!rankLists[rank]) rankLists[rank] = [];
if (name) rankLists[rank].push(name);
}
}
let buffer = Object.keys(rankLists)
.sort(
(a, b) =>
(Config.groups[b] || { rank: 0 }).rank -
(Config.groups[a] || { rank: 0 }).rank
)
.map(
r =>
`${
(Config.groups[r] ? `**${Config.groups[r].name}s** (${r})` : r)
}:\n${rankLists[r]
.sort((a, b) => toId(a).localeCompare(toId(b)))
.join(", ")}`
);
if (!buffer.length)
return connection.popup("This server has no global authority.");
connection.popup(buffer.join("\n\n"));
},
authhelp: [
`/auth - Show global staff for the server.`,
`/auth [room] - Show what roomauth a room has.`,
`/auth [user] - Show what global and roomauth a user has.`
],
userlist: function(target, room, user) {
let userList = [];
for (let i in room.users) {
let curUser = Users(room.users[i]);
if (!curUser || !curUser.named) continue;
userList.push(Chat.escapeHTML(curUser.getIdentity(room.id)));
}
let output = `There ${Chat.plural(
userList,
"are",
"is"
)} <strong style="color:#24678d">${Chat.count(
userList,
"</strong> users"
)} in this room:<br />`;
output += userList.join(`, `);
this.sendReplyBox(output);
},
userlisthelp: [
`/userlist - Displays a list of users who are currently in the room.`
],
"!me": true,
mee: "me",
me: function(target, room, user) {
if (this.cmd === "mee" && /[A-Z-a-z0-9/]/.test(target.charAt(0))) {
return this.errorReply(`/mee - must not start with a letter or number`);
}
target = this.canTalk(`/${this.cmd} ${target || ""}`);
if (!target) return;
if (this.message.startsWith(`/ME`)) {
const uppercaseIdentity = user.getIdentity(room).toUpperCase();
if (room) {
this.add(`|c|${uppercaseIdentity}|${target}`);
} else {
let msg = `|pm|${uppercaseIdentity}|${this.pmTarget.getIdentity()}|${target}`;
user.send(msg);
if (this.pmTarget !== user) this.pmTarget.send(msg);
}
return;
}
return target;
},
"!battle": true,
"battle!": "battle",
battle: function(target, room, user, connection, cmd) {
if (cmd === "battle")
return this.sendReply(
"What?! How are you not more excited to battle?! Try /battle! to show me you're ready."
);
if (!target) target = "randombattle";
return this.parse(`/search ${target}`);
},
"!pi": true,
pi: function(target, room, user) {
return this.sendReplyBox(
"Did you mean: 1. 3.1415926535897932384626... (Decimal)<br />" +
"2. 3.184809493B91866... (Duodecimal)<br />" +
"3. 3.243F6A8885A308D... (Hexadecimal)<br /><br />" +
'How many digits of pi do YOU know? Test it out <a href="http://guangcongluo.com/mempi/">here</a>!'
);
},
code: function(target, room, user) {
if (!target) return this.parse("/help code");
if (!this.canTalk()) return;
if (target.startsWith("\n")) target = target.slice(1);
if (target.length >= 30000)
return this.errorReply("Your code must be under 30000 characters long!");
const separator = "\n";
if (target.includes(separator) || target.length > 150) {
const params = target.split(separator);
let output = [];
for (const param of params) {
output.push(Chat.escapeHTML(param));
}
let code = `<div class="chat"><code style="white-space: pre-wrap; display: table">${output.join(
"<br />"
)}</code></div>`;
if (output.length > 3)
code = `<details><summary>See code...</summary>${code}</details>`;
if (!this.canBroadcast(true, "!code")) return;
if (this.broadcastMessage && !this.can("broadcast", null, room))
return false;
if (!this.runBroadcast(true, "!code")) return;
this.sendReplyBox(code);
} else {
return this.errorReply(
"You can simply use ``[code]`` for code messages that are only one line."
);
}
},
codehelp: [
`!code [code] - Broadcasts code to a room. Accepts multi-line arguments. Requires: + % @ $ & # ~`,
`/code [code] - Shows you code. Accepts multi-line arguments.`
],
"!avatar": true,
avatar: function(target, room, user) {
if (!target) return this.parse(`${this.cmdToken}avatars`);
let parts = target.split(",");
let avatarid = toId(parts[0]);
let avatar = 0;
let avatarTable = {
lucas: 1,
dawn: 2,
youngstergen4: 3,
lassgen4dp: 4,
camper: 5,
picnicker: 6,
bugcatcher: 7,
aromalady: 8,
twinsgen4dp: 9,
hikergen4: 10,
battlegirlgen4: 11,
fishermangen4: 12,
cyclistgen4: 13,
cyclistfgen4: 14,
blackbeltgen4dp: 15,
artistgen4: 16,
pokemonbreedergen4: 17,
pokemonbreederfgen4: 18,
cowgirl: 19,
jogger: 20,
pokefangen4: 21,
pokefanfgen4: 22,
pokekid: 23,
youngcouplegen4dp: 24,
acetrainergen4dp: 25,
acetrainerfgen4dp: 26,
waitressgen4: 27,
veterangen4: 28,
ninjaboy: 29,
dragontamer: 30,
birdkeepergen4dp: 31,
doubleteam: 32,
richboygen4: 33,
ladygen4: 34,
gentlemangen4dp: 35,
socialite: 36,
madamegen4dp: 36,
beautygen4dp: 37,
collector: 38,
policemangen4: 39,
pokemonrangergen4: 40,
pokemonrangerfgen4: 41,
scientistgen4dp: 42,
swimmergen4dp: 43,
swimmerfgen4dp: 44,
tuber: 45,
tuberf: 46,
sailor: 47,
sisandbro: 48,
ruinmaniac: 49,
psychicgen4: 50,
psychicfgen4: 51,
gambler: 52,
guitaristgen4: 53,
acetrainersnow: 54,
acetrainersnowf: 55,
skier: 56,
skierfgen4dp: 57,
roughneckgen4: 58,
clown: 59,
workergen4: 60,
schoolkidgen4dp: 61,
schoolkidfgen4: 62,
roark: 63,
barry: 64,
byron: 65,
aaron: 66,
bertha: 67,
flint: 68,
lucian: 69,
cynthiagen4: 70,
bellepa: 71,
rancher: 72,
mars: 73,
galacticgrunt: 74,
gardenia: 75,
crasherwake: 76,
maylene: 77,
fantina: 78,
candice: 79,
volkner: 80,
parasolladygen4: 81,
waitergen4dp: 82,
interviewers: 83,
cameraman: 84,
oli: 84,
reporter: 85,
roxy: 85,
idol: 86,
grace: 86,
cyrus: 87,
jupiter: 88,
saturn: 89,
galacticgruntf: 90,
argenta: 91,
palmer: 92,
thorton: 93,
buck: 94,
darach: 95,
marley: 96,
mira: 97,
cheryl: 98,
riley: 99,
dahlia: 100,
ethan: 101,
lyra: 102,
twinsgen4: 103,
lassgen4: 104,
acetrainergen4: 105,
acetrainerfgen4: 106,
juggler: 107,
sage: 108,
li: 109,
gentlemangen4: 110,
teacher: 111,
beauty: 112,
birdkeeper: 113,
swimmergen4: 114,
swimmerfgen4: 115,
kimonogirl: 116,
scientistgen4: 117,
acetrainercouple: 118,
youngcouple: 119,
supernerd: 120,
medium: 121,
schoolkidgen4: 122,
blackbeltgen4: 123,
pokemaniac: 124,
firebreather: 125,
burglar: 126,
bikergen4: 127,
skierf: 128,
boarder: 129,
rocketgrunt: 130,
rocketgruntf: 131,
archer: 132,
ariana: 133,
proton: 134,
petrel: 135,
mysteryman: 136,
eusine: 136,
lucasgen4pt: 137,
dawngen4pt: 138,
madamegen4: 139,
waitergen4: 140,
falkner: 141,
bugsy: 142,
whitney: 143,
morty: 144,
chuck: 145,
jasmine: 146,
pryce: 147,
clair: 148,
will: 149,
koga: 150,
bruno: 151,
karen: 152,
lance: 153,
brock: 154,
misty: 155,
ltsurge: 156,
erika: 157,
janine: 158,
sabrina: 159,
blaine: 160,
blue: 161,
red2: 162,
red: 163,
silver: 164,
giovanni: 165,
unknownf: 166,
unknownm: 167,
unknown: 168,
hilbert: 169,
hilda: 170,
youngster: 171,
lass: 172,
schoolkid: 173,
schoolkidf: 174,
smasher: 175,
linebacker: 176,
waiter: 177,
waitress: 178,
chili: 179,
cilan: 180,
cress: 181,
nurseryaide: 182,
preschoolerf: 183,
preschooler: 184,
twins: 185,
pokemonbreeder: 186,
pokemonbreederf: 187,
lenora: 188,
burgh: 189,
elesa: 190,
clay: 191,
skyla: 192,
pokeranger: 193,
pokerangerf: 194,
worker: 195,
backpacker: 196,
backpackerf: 197,
fisherman: 198,
musician: 199,
dancer: 200,
harlequin: 201,
artist: 202,
baker: 203,
psychic: 204,
psyhicf: 205,
cheren: 206,
bianca: 207,
plasmagruntgen5bw: 208,
n: 209,
richboy: 210,
lady: 211,
pilot: 212,
workerice: 213,
hoopster: 214,
scientistf: 215,
clerkf: 216,
acetrainerf: 217,
acetrainer: 218,
blackbelt: 219,
scientist: 220,
striker: 221,
brycen: 222,
iris: 223,
drayden: 224,
roughneck: 225,
janitor: 226,
pokefan: 227,
pokefanf: 228,
doctor: 229,
nurse: 230,
hooligans: 231,
battlegirl: 232,
parasollady: 233,
clerk: 234,
clerkboss: 235,
backers: 236,
backersf: 237,
veteran: 238,
veteranf: 239,
biker: 240,
infielder: 241,
hiker: 242,
madame: 243,
gentleman: 244,
plasmagruntfgen5bw: 245,
shauntal: 246,
marshal: 247,
grimsley: 248,
caitlin: 249,
ghetsisgen5bw: 250,
depotagent: 251,
swimmer: 252,
swimmerf: 253,
policeman: 254,
maid: 255,
ingo: 256,
alder: 257,
cyclist: 258,
cyclistf: 259,
cynthia: 260,
emmet: 261,
hilbertdueldisk: 262,
hildadueldisk: 263,
hugh: 264,
rosa: 265,
nate: 266,
colress: 267,
beautygen5bw2: 268,
ghetsis: 269,
plasmagrunt: 270,
plasmagruntf: 271,
irisgen5bw2: 272,
brycenman: 273,
shadowtriad: 274,
rood: 275,
zinzolin: 276,
cherengen5bw2: 277,
marlon: 278,
roxie: 279,
roxanne: 280,
brawly: 281,
wattson: 282,
flannery: 283,
norman: 284,
winona: 285,
tate: 286,
liza: 287,
juan: 288,
guitarist: 289,
steven: 290,
wallace: 291,
magicqueen: 292,
bellelba: 292,
benga: 293,
ash: 294,
bw2elesa: '#bw2elesa',
teamrocket: '#teamrocket',
yellow: '#yellow',
zinnia: '#zinnia',
clemont: '#clemont',
aeonic: '#aeonic',
wally: '#wally',
};
if (avatarTable.hasOwnProperty(avatarid)) {
avatar = avatarTable[avatarid];
} else {
avatar = parseInt(avatarid);
}
if (typeof avatar === "number" && (!avatar || avatar > 294 || avatar < 1)) {
if (!parts[1]) {
this.errorReply("Invalid avatar.");
}
return false;
}
user.avatar = avatar;
if (!parts[1]) {
this.sendReply(
`Avatar changed to:\n|raw|<img src="//play.pokemonshowdown.com/sprites/trainers-custom/${
(typeof avatar === "string" ? avatar.substr(1) : avatar)
}.png" alt="" width="80" height="80" />`
);
}
},
avatarhelp: [
`/avatar [avatar number 1 to 293] - Change your trainer sprite.`
],
"!logout": true,
signout: "logout",
logout: function(target, room, user) {
user.resetName();
},
noreply(target, room, user) {
if (!target.startsWith("/")) return this.parse("/help noreply");
return this.parse(target, true);
},
noreplyhelp: [
`/noreply [command] - Runs the command without displaying the response.`
],
r: "reply",
reply: function(target, room, user) {
if (!target) return this.parse("/help reply");
if (!user.lastPM) {
return this.errorReply("No one has PMed you yet.");
}
return this.parse(`/msg ${user.lastPM || ""}, ${target}`);
},
replyhelp: [
`/reply OR /r [message] - Send a private message to the last person you received a message from, or sent a message to.`
],
"!msg": true,
pm: "msg",
whisper: "msg",
w: "msg",
msg: function(target, room, user, connection) {
if (!target) return this.parse("/help msg");
target = this.splitTarget(target);
let targetUser = this.targetUser;
if (this.targetUsername === "~") {
this.room = Rooms.global;
this.pmTarget = null;
} else if (!target) {
this.errorReply("You forgot the comma.");
return this.parse("/help msg");
} else if (!targetUser) {
let error = `User ${this.targetUsername} not found. Did you misspell their name?`;
error = `|pm|${this.user.getIdentity()}| ${
this.targetUsername
}|/error ${error}`;
connection.send(error);
return;
} else {
this.pmTarget = targetUser;
this.room = undefined;
}
if (targetUser && !targetUser.connected) {
return this.errorReply(`User ${this.targetUsername} is offline.`);
}
this.parse(target);
},
msghelp: [
`/msg OR /whisper OR /w [username], [message] - Send a private message.`
],
"!invite": true,
inv: "invite",
invite: function(target, room, user) {
if (!target) return this.parse("/help invite");
if (!this.canTalk()) return;
if (room) target = this.splitTarget(target) || room.id;
let targetRoom = Rooms.search(target);
if (targetRoom && !targetRoom.checkModjoin(user)) {
targetRoom = undefined;
}
if (room) {
if (!this.targetUser)
return this.errorReply(
`The user "${this.targetUsername}" was not found.`
);
if (!targetRoom)
return this.errorReply(`The room "${target}" was not found.`);
return this.parse(`/pm ${this.targetUsername}, /invite ${targetRoom.id}`);
}
let targetUser = this.pmTarget;
if (!targetRoom || targetRoom === Rooms.global)
return this.errorReply(`The room "${target}" was not found.`);
if (targetRoom.staffRoom && !targetUser.isStaff)
return this.errorReply(
`User "${targetUser.name}" requires global auth to join room "${targetRoom.id}".`
);
if (!targetUser)
return this.errorReply(`The user "${targetUser.name}" was not found.`);
if (!targetRoom.checkModjoin(targetUser)) {
this.room = targetRoom;
this.parse(`/roomvoice ${targetUser.name}`);
if (!targetRoom.checkModjoin(targetUser)) {
return this.errorReply(
`You do not have permission to invite people into this room.`
);
}
}
if (targetUser in targetRoom.users)
return this.errorReply(`This user is already in "${targetRoom.title}".`);
return `/invite ${targetRoom.id}`;
},
invitehelp: [
`/invite [username] - Invites the player [username] to join the room you sent the command to.`,
`(in a PM) /invite [roomname] - Invites the player you're PMing to join the room [roomname].`
],
pminfobox: function(target, room, user, connection) {
if (!this.canTalk()) return;
if (!this.can("addhtml", null, room)) return false;
if (!target) return this.parse("/help pminfobox");
target = this.canHTML(this.splitTarget(target));
if (!target) return;
let targetUser = this.targetUser;
if (!targetUser || !targetUser.connected)
return this.errorReply(
`User ${this.targetUsername} is not currently online.`
);
if (!(targetUser in room.users) && !user.can("addhtml"))
return this.errorReply(
"You do not have permission to use this command to users who are not in this room."
);
if (
targetUser.ignorePMs &&
targetUser.ignorePMs !== user.group &&
!user.can("lock")
)
return this.errorReply("This user is currently ignoring PMs.");
if (targetUser.locked && !user.can("lock"))
return this.errorReply(
"This user is currently locked, so you cannot send them a pminfobox."
);
// Apply the infobox to the message
target = `/raw <div class="infobox">${target}</div>`;
let message = `|pm|${user.getIdentity()}|${targetUser.getIdentity()}|${target}`;
user.send(message);
if (targetUser !== user) targetUser.send(message);
targetUser.lastPM = user.userid;
user.lastPM = targetUser.userid;
},
pminfoboxhelp: [
`/pminfobox [user], [html]- PMs an [html] infobox to [user]. Requires * ~`
],
pmuhtmlchange: "pmuhtml",
pmuhtml: function(target, room, user, connection, cmd) {
if (!this.canTalk()) return;
if (!this.can("addhtml", null, room)) return false;
if (!target) return this.parse("/help " + cmd);
target = this.canHTML(this.splitTarget(target));
if (!target) return;
let targetUser = this.targetUser;
if (!targetUser || !targetUser.connected)
return this.errorReply(
`User ${this.targetUsername} is not currently online.`
);
if (!(targetUser in room.users) && !user.can("addhtml"))
return this.errorReply(
"You do not have permission to use this command to users who are not in this room."
);
if (
targetUser.ignorePMs &&
targetUser.ignorePMs !== user.group &&
!user.can("lock")
)
return this.errorReply("This user is currently ignoring PMs.");
if (targetUser.locked && !user.can("lock"))
return this.errorReply(
"This user is currently locked, so you cannot send them UHTML."
);
let message = `|pm|${user.getIdentity()}|${targetUser.getIdentity()}|/uhtml${
(cmd === "pmuhtmlchange" ? "change" : "")
} ${target}`;
user.send(message);
if (targetUser !== user) targetUser.send(message);
targetUser.lastPM = user.userid;
user.lastPM = targetUser.userid;
},
pmuhtmlhelp: [
`/pmuhtml [user], [name], [html] - PMs [html] that can change to [user]. Requires * ~`
],
pmuhtmlchangehelp: [
`/pmuhtmlchange [user], [name], [html] - Changes html that was previously PMed to [user] to [html]. Requires * ~`
],
"!ignorepms": true,
blockpm: "ignorepms",
blockpms: "ignorepms",
ignorepm: "ignorepms",
ignorepms: function(target, room, user) {
if (user.ignorePMs === (target || true))
return this.errorReply(
"You are already blocking private messages! To unblock, use /unblockpms"
);
user.ignorePMs = true;
if (target in Config.groups) {
user.ignorePMs = target;
return this.sendReply(
`You are now blocking private messages, except from staff and ${target}.`
);
}
return this.sendReply(
"You are now blocking private messages, except from staff."
);
},
ignorepmshelp: [
`/blockpms - Blocks private messages. Unblock them with /unignorepms.`
],
"!unignorepms": true,
unblockpm: "unignorepms",
unblockpms: "unignorepms",
unignorepm: "unignorepms",
unignorepms: function(target, room, user) {
if (!user.ignorePMs)
return this.errorReply(
"You are not blocking private messages! To block, use /blockpms"
);
user.ignorePMs = false;
return this.sendReply("You are no longer blocking private messages.");
},
unignorepmshelp: [
`/unblockpms - Unblocks private messages. Block them with /blockpms.`
],
"!away": true,
idle: "away",
afk: "away",
away: function(target, room, user) {
this.parse("/blockchallenges");
this.parse(`/blockpms ${target}`);
},
awayhelp: [
`/away - Blocks challenges and private messages. Unblock them with /back.`
],
"!back": true,
unaway: "back",
unafk: "back",
back: function() {
this.parse("/unblockpms");
this.parse("/unblockchallenges");
},
backhelp: [
`/back - Unblocks challenges and/or private messages, if either are blocked.`
],
"!rank": true,
rank: function(target, room, user) {
if (!target) target = user.name;
Ladders.visualizeAll(target).then(values => {
let buffer = `<div class="ladder"><table>`;
buffer += `<tr><td colspan="8">User: <strong>${Chat.escapeHTML(
target
)}</strong></td></tr>`;
let ratings = values.join(``);
if (!ratings) {
buffer += `<tr><td colspan="8"><em>This user has not played any ladder games yet.</em></td></tr>`;
} else {
buffer += `<tr><th>Format</th><th><abbr title="Elo rating">Elo</abbr></th><th>W</th><th>L</th><th>Total</th>`;
buffer += ratings;
}
buffer += `</table></div>`;
this.sendReply(`|raw|${buffer}`);
});
},
makeprivatechatroom: "makechatroom",
makechatroom: function(target, room, user, connection, cmd) {
if (!this.can("makeroom")) return;
// `,` is a delimiter used by a lot of /commands
// `|` and `[` are delimiters used by the protocol
// `-` has special meaning in roomids
if (
target.includes(",") ||
target.includes("|") ||
target.includes("[") ||
target.includes("-")
) {
return this.errorReply("Room titles can't contain any of: ,|[-");
}
let id = toId(target);
if (!id) return this.parse("/help makechatroom");
if (id.length > MAX_CHATROOM_ID_LENGTH)
return this.errorReply("The given room title is too long.");
// Check if the name already exists as a room or alias
if (Rooms.search(id))
return this.errorReply(`The room '${target}' already exists.`);
if (!Rooms.global.addChatRoom(target))
return this.errorReply(
`An error occurred while trying to create the room '${target}'.`
);
if (cmd === "makeprivatechatroom") {
let targetRoom = Rooms.search(target);
targetRoom.isPrivate = true;
targetRoom.chatRoomData.isPrivate = true;
Rooms.global.writeChatRoomData();
if (Rooms.get("upperstaff")) {
Rooms.get("upperstaff")
.add(
`|raw|<div class="broadcast-green">Private chat room created: <b>${Chat.escapeHTML(
target
)}</b></div>`
)
.update();
}
this.sendReply(`The private chat room '${target}' was created.`);
} else {
if (Rooms.get("staff")) {
Rooms.get("staff")
.add(
`|raw|<div class="broadcast-green">Public chat room created: <b>${Chat.escapeHTML(
target
)}</b></div>`
)
.update();
}
if (Rooms.get("upperstaff")) {
Rooms.get("upperstaff")
.add(
`|raw|<div class="broadcast-green">Public chat room created: <b>${Chat.escapeHTML(
target
)}</b></div>`
)
.update();
}
this.sendReply(`The chat room '${target}' was created.`);
}
},
makechatroomhelp: [
`/makechatroom [roomname] - Creates a new room named [roomname]. Requires: & ~`
],
subroomgroupchat: "makegroupchat",
makegroupchat: function(target, room, user, connection, cmd) {
if (!user.autoconfirmed) {
return this.errorReply("You must be autoconfirmed to make a groupchat.");
}
if (!user.trusted) {
return this.errorReply(
"You must be global voice or roomdriver+ in some public room to make a groupchat."
);
}
if (cmd === "subroomgroupchat") {
if (!user.can("mute", null, room))
return this.errorReply(
"You can only create subroom groupchats for rooms you're staff in."
);
if (room.battle)
return this.errorReply("You cannot create a subroom of a battle.");
if (room.isPersonal)
return this.errorReply("You cannot create a subroom of a groupchat.");
}
let parent = cmd === "subroomgroupchat" ? room.id : null;
// if (!this.can('makegroupchat')) return false;
// Title defaults to a random 8-digit number.
let title = target.trim();
if (title.length >= 32) {
return this.errorReply("Title must be under 32 characters long.");
} else if (!title) {
title = (`${Math.floor(Math.random() * 100000000)}`);
} else if (Config.chatfilter) {
let filterResult = Config.chatfilter.call(
this,
title,
user,
null,
connection
);
if (!filterResult) return;
if (title !== filterResult) {
return this.errorReply("Invalid title.");
}
}
// `,` is a delimiter used by a lot of /commands
// `|` and `[` are delimiters used by the protocol
// `-` has special meaning in roomids
if (
title.includes(",") ||
title.includes("|") ||
title.includes("[") ||
title.includes("-")
) {
return this.errorReply("Room titles can't contain any of: ,|[-");
}
// Even though they're different namespaces, to cut down on confusion, you
// can't share names with registered chatrooms.
let existingRoom = Rooms.search(toId(title));
if (existingRoom && !existingRoom.modjoin)
return this.errorReply(`The room '${title}' already exists.`);
// Room IDs for groupchats are groupchat-TITLEID
let titleid = toId(title);
if (!titleid) {
titleid = `${Math.floor(Math.random() * 100000000)}`;
}
let roomid = `groupchat-${parent || user.userid}-${titleid}`;
// Titles must be unique.
if (Rooms.search(roomid))
return this.errorReply(`A group chat named '${title}' already exists.`);
// Tab title is prefixed with '[G]' to distinguish groupchats from
// registered chatrooms
if (Monitor.countGroupChat(connection.ip)) {
this.errorReply(
"Due to high load, you are limited to creating 4 group chats every hour."
);
return;
}
let groupChatLink = "<code><<" + roomid + ">></code>";
let groupChatURL = "";
if (Config.serverid) {
groupChatURL = `http://${
(Config.serverid === `showdown`
? `psim.us`
: `${Config.serverid}.psim.us`)
}/${roomid}`;
groupChatLink = `<a href="${groupChatURL}">${groupChatLink}</a>`;
}
let titleHTML = "";
if (/^[0-9]+$/.test(title)) {
titleHTML = groupChatLink;
} else {
titleHTML = `${Chat.escapeHTML(
title
)} <small style="font-weight:normal;font-size:9pt">${groupChatLink}</small>`;
}
let targetRoom = Rooms.createChatRoom(roomid, `[G] ${title}`, {
isPersonal: true,
isPrivate: "hidden",
modjoin: parent ? null : "+",
parentid: parent,
auth: {},
introMessage: `<h2 style="margin-top:0">${titleHTML}</h2><p>To invite people to this groupchat, use <code>/invite USERNAME</code> in the groupchat.<br /></p><p>This room will expire after 40 minutes of inactivity or when the server is restarted.</p><p style="margin-bottom:0"><button name="send" value="/roomhelp">Room management</button>`,
staffMessage: `<p>As creator of this groupchat, <u>you are entirely responsible for what occurs in this chatroom</u>. Global rules apply at all times.</p><p>If you have created this room for someone else, <u>you are still responsible</u> whether or not you choose to actively supervise the room.</p><p style="font-style:italic">For this reason, we strongly recommend that you only create groupchats for users you know and trust.</p><p>If this room is used to break global rules or disrupt other areas of the server, this will be considered irresponsible use of auth privileges on the part of the creator, and <b>you will be globally demoted and barred from public auth.</b></p>`
});
if (targetRoom) {