forked from XpRienzo/DragonHeaven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat-commands.js
3594 lines (3188 loc) · 139 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('fs');
const MAX_REASON_LENGTH = 300;
const MUTE_LENGTH = 7 * 60 * 1000;
const HOURMUTE_LENGTH = 60 * 60 * 1000;
exports.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 unavailableRoom = targetRoom && targetRoom.checkModjoin(user);
if (targetRoom && !unavailableRoom) 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.length, 'are', 'is')} <strong style="color:#24678d">${userList.length}</strong> user${Chat.plural(userList.length)} 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: 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>!');
},
'!avatar': true,
avatar: function (target, room, user) {
if (!target) return this.parse('/avatars');
let parts = target.split(',');
let avatarid = toId(parts[0]);
let avatar = 0;
let avatarTable = {
lucas: 1,
dawn: 2,
youngster: 3,
lass: 4,
camper: 5,
picnicker: 6,
bugcatcher: 7,
aromalady: 8,
twins: 9,
hiker: 10,
battlegirl: 11,
fisherman: 12,
cyclist: 13,
cyclistf: 14,
blackbelt: 15,
artist: 16,
pokemonbreeder: 17,
pokemonbreederf: 18,
cowgirl: 19,
jogger: 20,
pokefan: 21,
pokefanf: 22,
pokekid: 23,
youngcouple: 24,
acetrainer: 25,
acetrainerf: 26,
waitress: 27,
veteran: 28,
ninjaboy: 29,
dragontamer: 30,
birdkeeper: 31,
doubleteam: 32,
richboy: 33,
lady: 34,
gentleman: 35,
socialite: 36,
madame: 36,
beauty: 37,
collector: 38,
policeman: 39,
pokemonranger: 40,
pokemonrangerf: 41,
scientist: 42,
swimmer: 43,
swimmerf: 44,
tuber: 45,
tuberf: 46,
sailor: 47,
sisandbro: 48,
ruinmaniac: 49,
psychic: 50,
psychicf: 51,
gambler: 52,
dppguitarist: 53,
acetrainersnow: 54,
acetrainersnowf: 55,
skier: 56,
skierf: 57,
roughneck: 58,
clown: 59,
worker: 60,
schoolkid: 61,
schoolkidf: 62,
roark: 63,
barry: 64,
byron: 65,
aaron: 66,
bertha: 67,
flint: 68,
lucian: 69,
dppcynthia: 70,
bellepa: 71,
rancher: 72,
mars: 73,
galacticgrunt: 74,
gardenia: 75,
crasherwake: 76,
maylene: 77,
fantina: 78,
candice: 79,
volkner: 80,
parasollady: 81,
waiter: 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,
archer: 132,
ariana: 133,
proton: 134,
petrel: 135,
mysteryman: 136,
eusine: 136,
ptlucas: 137,
ptdawn: 138,
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,
erica: 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,
chili: 179,
cilan: 180,
cress: 181,
lenora: 188,
burgh: 189,
elesa: 190,
clay: 191,
skyla: 192,
cheren: 206,
bianca: 207,
n: 209,
brycen: 222,
iris: 223,
drayden: 224,
shauntal: 246,
marshal: 247,
grimsley: 248,
caitlin: 249,
ghetsis: 250,
ingo: 256,
alder: 257,
cynthia: 260,
emmet: 261,
dueldiskhilbert: 262,
dueldiskhilda: 263,
hugh: 264,
rosa: 265,
nate: 266,
colress: 267,
bw2beauty: 268,
bw2ghetsis: 269,
bw2plasmagrunt: 270,
bw2plasmagruntf: 271,
bw2iris: 272,
brycenman: 273,
shadowtriad: 274,
rood: 275,
zinzolin: 276,
bw2cheren: 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,
bw2elesa: '#bw2elesa',
teamrocket: '#teamrocket',
yellow: '#yellow',
zinnia: '#zinnia',
clemont: '#clemont',
};
if (avatarid in avatarTable) {
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/' + (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();
},
requesthelp: 'report',
report: function (target, room, user) {
if (room.id === 'help') {
this.sendReply("Ask one of the Moderators (@) in the Help room.");
} else {
this.parse('/join help');
}
},
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 (!target) {
this.errorReply("You forgot the comma.");
return this.parse('/help msg');
}
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;
}
this.pmTarget = targetUser;
this.room = undefined;
if (!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 "${this.targetUsername}" requires global auth to join room "${targetRoom.id}".`);
if (!targetUser) return this.errorReply(`The user "${this.targetUsername}" was not found.`);
if (!targetRoom.checkModjoin(targetUser)) {
if (targetRoom.getAuth(targetUser) !== ' ') {
return this.errorReply(`The user "${targetUser.name}" does not have permission to join "${targetRoom.title}".`);
}
this.room = targetRoom;
this.parse(`/roomvoice ${targetUser.name}`);
if (!targetRoom.checkModjoin(targetUser)) {
if (targetRoom.getAuth(targetUser) !== ' ') {
return this.errorReply(`The user "${targetUser.name}" does not have permission to join "${targetRoom.title}".`);
}
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(target);
if (!target) return;
target = this.splitTarget(target);
let targetUser = this.targetUser;
if (!targetUser || !targetUser.connected) return this.errorReply("User " + targetUser + " 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) return this.errorReply("This user is currently ignoring PMs.");
if (targetUser.locked) 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 * ~"],
'!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");
if (user.can('lock') && !user.can('bypassall')) return this.errorReply("You are not allowed to block private messages.");
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');
// 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('theadminchat')) {
Rooms.get('theadminchat').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: & ~"],
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 (!this.can('makegroupchat')) return false;
if (target.length > 64) return this.errorReply("Title must be under 32 characters long.");
let targets = target.split(',', 2);
// Title defaults to a random 8-digit number.
let title = targets[0].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-' + 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;
}
// Privacy settings, default to hidden.
let privacy = (toId(targets[1]) === 'private') ? true : 'hidden';
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: privacy,
auth: {},
introMessage: '<h2 style="margin-top:0">' + titleHTML + '</h2><p>There are several ways to invite people:<br />- in this chat: <code>/invite USERNAME</code><br />- anywhere in PS: link to <code><<' + roomid + '>></code>' + (groupChatURL ? '<br />- outside of PS: link to <a href="' + groupChatURL + '">' + groupChatURL + '</a>' : '') + '</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>',
});
if (targetRoom) {
// The creator is RO.
targetRoom.auth[user.userid] = '#';
// Join after creating room. No other response is given.
user.joinRoom(targetRoom.id);
return;
}
return this.errorReply("An unknown error occurred while trying to create the room '" + title + "'.");
},
makegroupchathelp: ["/makegroupchat [roomname], [hidden|private] - Creates a group chat named [roomname]. Leave off privacy to default to hidden. Requires global voice or roomdriver+ in a public room to make a groupchat."],
deregisterchatroom: function (target, room, user) {
if (!this.can('makeroom')) return;
this.errorReply("NOTE: You probably want to use `/deleteroom` now that it exists.");
let id = toId(target);
if (!id) return this.parse('/help deregisterchatroom');
let targetRoom = Rooms.search(id);
if (!targetRoom) return this.errorReply("The room '" + target + "' doesn't exist.");
target = targetRoom.title || targetRoom.id;
if (Rooms.global.deregisterChatRoom(id)) {
this.sendReply("The room '" + target + "' was deregistered.");
this.sendReply("It will be deleted as of the next server restart.");
return;
}
return this.errorReply("The room '" + target + "' isn't registered.");
},
deregisterchatroomhelp: ["/deregisterchatroom [roomname] - Deletes room [roomname] after the next server restart. Requires: & ~"],
deletechatroom: 'deleteroom',
deletegroupchat: 'deleteroom',
deleteroom: function (target, room, user) {
let roomid = target.trim();
if (!roomid) return this.parse('/help deleteroom');
let targetRoom = Rooms.search(roomid);
if (!targetRoom) return this.errorReply("The room '" + target + "' doesn't exist.");
if (room.isPersonal) {
if (!this.can('editroom', null, targetRoom)) return;
} else {
if (!this.can('makeroom')) return;
}
target = targetRoom.title || targetRoom.id;
if (targetRoom.id === 'global') {
return this.errorReply("This room can't be deleted.");
}
if (targetRoom.chatRoomData) {
if (targetRoom.isPrivate) {
if (Rooms.get('theadminchat')) {
Rooms.get('theadminchat').add(`|raw|<div class="broadcast-red">Private chat room deleted by ${user.userid}: <b>${Chat.escapeHTML(target)}</b></div>`).update();
}
} else {
if (Rooms.get('staff')) {
Rooms.get('staff').add('|raw|<div class="broadcast-red">Public chat room deleted: <b>' + Chat.escapeHTML(target) + '</b></div>').update();
}
if (Rooms.get('upperstaff')) {
Rooms.get('upperstaff').add(`|raw|<div class="broadcast-red">Public chat room deleted by ${user.userid}: <b>${Chat.escapeHTML(target)}</b></div>`).update();
}
}
}
targetRoom.add("|raw|<div class=\"broadcast-red\"><b>This room has been deleted.</b></div>");
targetRoom.update(); // |expire| needs to be its own message
targetRoom.add("|expire|This room has been deleted.");
this.sendReply("The room '" + target + "' was deleted.");
targetRoom.update();
targetRoom.destroy();
},
deleteroomhelp: ["/deleteroom [roomname] - Deletes room [roomname]. Requires: & ~"],
hideroom: 'privateroom',
hiddenroom: 'privateroom',
secretroom: 'privateroom',
publicroom: 'privateroom',
privateroom: function (target, room, user, connection, cmd) {
if (room.battle || room.isPersonal) {
if (!this.can('editroom', null, room)) return;
} else {
// registered chatrooms show up on the room list and so require
// higher permissions to modify privacy settings
if (!this.can('makeroom')) return;
}
let setting;
switch (cmd) {
case 'privateroom':
return this.parse('/help privateroom');
case 'publicroom':
setting = false;
break;
case 'secretroom':
setting = true;
break;
default:
if (room.isPrivate === true && target !== 'force') {
return this.sendReply(`This room is a secret room. Use "/publicroom" to make it public, or "/hiddenroom force" to force it hidden.`);
}
setting = 'hidden';
break;
}
if ((setting === true || room.isPrivate === true) && !room.isPersonal) {
if (!this.can('makeroom')) return;
}
if (target === 'off' || !setting) {
if (!room.isPrivate) {
return this.errorReply(`This room is already public.`);
}
if (room.isPersonal) return this.errorReply(`This room can't be made public.`);
if (room.privacySetter && user.can('nooverride', null, room) && !user.can('makeroom')) {
if (!room.privacySetter.has(user.userid)) {
const privacySetters = Array.from(room.privacySetter).join(', ');
return this.errorReply(`You can't make the room public since you didn't make it private - only ${privacySetters} can.`);
}
room.privacySetter.delete(user.userid);
if (room.privacySetter.size) {
const privacySetters = Array.from(room.privacySetter).join(', ');
return this.sendReply(`You are no longer forcing the room to stay private, but ${privacySetters} also need${Chat.plural(room.privacySetter, '', 's')} to use /publicroom to make the room public.`);
}
}
delete room.isPrivate;
room.privacySetter = null;
this.addModCommand(`${user.name} made this room public.`);
if (room.chatRoomData) {
delete room.chatRoomData.isPrivate;
Rooms.global.writeChatRoomData();
}
} else {
const settingName = (setting === true ? 'secret' : setting);
if (room.isPrivate === setting) {
if (room.privacySetter && !room.privacySetter.has(user.userid)) {
room.privacySetter.add(user.userid);
return this.sendReply(`This room is already ${settingName}, but is now forced to stay that way until you use /publicroom.`);
}
return this.errorReply(`This room is already ${settingName}.`);
}
room.isPrivate = setting;
this.addModCommand(`${user.name} made this room ${settingName}.`);
if (room.chatRoomData) {
room.chatRoomData.isPrivate = setting;
Rooms.global.writeChatRoomData();
}
room.privacySetter = new Set([user.userid]);
}
},
privateroomhelp: ["/secretroom - Makes a room secret. Secret rooms are visible to & and up. Requires: & ~",
"/hiddenroom [on/off] - Makes a room hidden. Hidden rooms are visible to % and up, and inherit global ranks. Requires: \u2605 & ~",
"/publicroom - Makes a room public. Requires: \u2605 & ~"],
officialchatroom: 'officialroom',
officialroom: function (target, room, user) {
if (!this.can('makeroom')) return;
if (!room.chatRoomData) {
return this.errorReply(`/officialroom - This room can't be made official`);
}
if (target === 'off') {
if (!room.isOfficial) return this.errorReply(`This chat room is already unofficial.`);
delete room.isOfficial;
this.addModCommand(`${user.name} made this chat room unofficial.`);
delete room.chatRoomData.isOfficial;
Rooms.global.writeChatRoomData();
} else {
if (room.isOfficial) return this.errorReply(`This chat room is already official.`);
room.isOfficial = true;
this.addModCommand(`${user.name} made this chat room official.`);
room.chatRoomData.isOfficial = true;
Rooms.global.writeChatRoomData();
}
},
roomdesc: function (target, room, user) {
if (!target) {
if (!this.runBroadcast()) return;
if (!room.desc) return this.sendReply(`This room does not have a description set.`);
this.sendReplyBox(Chat.html`The room description is: ${room.desc}`);
return;
}
if (!this.can('declare')) return false;
if (target.length > 80) return this.errorReply(`Error: Room description is too long (must be at most 80 characters).`);
let normalizedTarget = ' ' + target.toLowerCase().replace('[^a-zA-Z0-9]+', ' ').trim() + ' ';
if (normalizedTarget.includes(' welcome ')) {
return this.errorReply(`Error: Room description must not contain the word "welcome".`);
}
if (normalizedTarget.slice(0, 9) === ' discuss ') {
return this.errorReply(`Error: Room description must not start with the word "discuss".`);
}
if (normalizedTarget.slice(0, 12) === ' talk about ' || normalizedTarget.slice(0, 17) === ' talk here about ') {
return this.errorReply(`Error: Room description must not start with the phrase "talk about".`);
}
room.desc = target;
this.sendReply(`(The room description is now: ${target})`);
this.privateModCommand(`(${user.name} changed the roomdesc to: "${target}".)`);
if (room.chatRoomData) {
room.chatRoomData.desc = room.desc;
Rooms.global.writeChatRoomData();
}
},
topic: 'roomintro',
roomintro: function (target, room, user, connection, cmd) {
if (!target) {
if (!this.runBroadcast()) return;
if (!room.introMessage) return this.sendReply("This room does not have an introduction set.");
this.sendReply('|raw|<div class="infobox infobox-limited">' + room.introMessage.replace(/\n/g, '') + '</div>');
if (!this.broadcasting && user.can('declare', null, room) && cmd !== 'topic') {
this.sendReply('Source:');
this.sendReplyBox(
'<code>/roomintro ' + Chat.escapeHTML(room.introMessage).split('\n').map(line => {
return line.replace(/^(\t+)/, (match, $1) => ' '.repeat(4 * $1.length)).replace(/^(\s+)/, (match, $1) => ' '.repeat($1.length));
}).join('<br />') + '</code>'
);
}
return;
}
if (!this.can('declare', null, room)) return false;
if (target === 'off' || target === 'disable' || target === 'delete') return this.errorReply('Did you mean "/deleteroomintro"?');
target = this.canHTML(target);
if (!target) return;
if (!/</.test(target)) {
// not HTML, do some simple URL linking
let re = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g;
target = target.replace(re, '<a href="$1">$1</a>');
}
if (target.substr(0, 11) === '/roomintro ') target = target.substr(11);
room.introMessage = target.replace(/\r/g, '');
this.sendReply("(The room introduction has been changed to:)");
this.sendReply('|raw|<div class="infobox infobox-limited">' + room.introMessage.replace(/\n/g, '') + '</div>');
this.privateModCommand(`(${user.name} changed the roomintro.)`);
this.logEntry(room.introMessage.replace(/\n/g, ''));
if (room.chatRoomData) {
room.chatRoomData.introMessage = room.introMessage;
Rooms.global.writeChatRoomData();
}
},
deletetopic: 'deleteroomintro',
deleteroomintro: function (target, room, user) {
if (!this.can('declare', null, room)) return false;
if (!room.introMessage) return this.errorReply("This room does not have a introduction set.");
this.privateModCommand(`(${user.name} deleted the roomintro.)`);
this.logEntry(target);
delete room.introMessage;
if (room.chatRoomData) {
delete room.chatRoomData.introMessage;
Rooms.global.writeChatRoomData();
}
},
stafftopic: 'staffintro',
staffintro: function (target, room, user, connection, cmd) {
if (!target) {
if (!this.can('mute', null, room)) return false;
if (!room.staffMessage) return this.sendReply("This room does not have a staff introduction set.");
this.sendReply('|raw|<div class="infobox">' + room.staffMessage.replace(/\n/g, '') + '</div>');
if (user.can('ban', null, room) && cmd !== 'stafftopic') {
this.sendReply('Source:');
this.sendReplyBox(
'<code>/staffintro ' + Chat.escapeHTML(room.staffMessage).split('\n').map(line => {
return line.replace(/^(\t+)/, (match, $1) => ' '.repeat(4 * $1.length)).replace(/^(\s+)/, (match, $1) => ' '.repeat($1.length));
}).join('<br />') + '</code>'
);
}
return;
}
if (!this.can('ban', null, room)) return false;
if (!this.canTalk()) return;
if (target === 'off' || target === 'disable' || target === 'delete') return this.errorReply('Did you mean "/deletestaffintro"?');
target = this.canHTML(target);
if (!target) return;
if (!/</.test(target)) {
// not HTML, do some simple URL linking
let re = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g;
target = target.replace(re, '<a href="$1">$1</a>');
}
if (target.substr(0, 12) === '/staffintro ') target = target.substr(12);
room.staffMessage = target.replace(/\r/g, '');
this.sendReply("(The staff introduction has been changed to:)");
this.sendReply('|raw|<div class="infobox">' + target.replace(/\n/g, '') + '</div>');
this.privateModCommand(`(${user.name} changed the staffintro.)`);
this.logEntry(room.staffMessage.replace(/\n/g, ''));
if (room.chatRoomData) {
room.chatRoomData.staffMessage = room.staffMessage;
Rooms.global.writeChatRoomData();
}
},
deletestafftopic: 'deletestaffintro',
deletestaffintro: function (target, room, user) {
if (!this.can('ban', null, room)) return false;
if (!room.staffMessage) return this.errorReply("This room does not have a staff introduction set.");
this.privateModCommand(`(${user.name} deleted the staffintro.)`);
this.logEntry(target);
delete room.staffMessage;
if (room.chatRoomData) {
delete room.chatRoomData.staffMessage;
Rooms.global.writeChatRoomData();
}
},
roomalias: function (target, room, user) {
if (!target) {
if (!this.runBroadcast()) return;
if (!room.aliases || !room.aliases.length) return this.sendReplyBox("This room does not have any aliases.");
return this.sendReplyBox("This room has the following aliases: " + room.aliases.join(", ") + "");
}
if (!this.can('makeroom')) return false;
let alias = toId(target);
if (!alias.length) return this.errorReply("Only alphanumeric characters are valid in an alias.");
if (Rooms(alias) || Rooms.aliases.has(alias)) return this.errorReply("You cannot set an alias to an existing room or alias.");
if (room.isPersonal) return this.errorReply("Personal rooms can't have aliases.");
Rooms.aliases.set(alias, room.id);
this.privateModCommand(`(${user.name} added the room alias '${target}'.)`);
if (!room.aliases) room.aliases = [];