forked from smogon/pokemon-showdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.js
2385 lines (2111 loc) · 93.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
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
*/
var crypto = require('crypto');
var fs = require('fs');
const MAX_REASON_LENGTH = 300;
const MUTE_LENGTH = 7 * 60 * 1000;
const HOURMUTE_LENGTH = 60 * 60 * 1000;
var commands = exports.commands = {
version: function (target, room, user) {
if (!this.canBroadcast()) return;
this.sendReplyBox("Server version: <b>" + CommandParser.package.version + "</b>");
},
auth: 'authority',
stafflist: 'authority',
globalauth: 'authority',
authlist: 'authority',
authority: function (target, room, user, connection) {
var rankLists = {};
var ranks = Object.keys(Config.groups);
for (var u in Users.usergroups) {
var 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.indexOf(rank) >= 0) {
var name = Users.usergroups[u].substr(1);
if (!rankLists[rank]) rankLists[rank] = [];
if (name) rankLists[rank].push(name);
}
}
var buffer = [];
Object.keys(rankLists).sort(function (a, b) {
return (Config.groups[b] || {rank: 0}).rank - (Config.groups[a] || {rank: 0}).rank;
}).forEach(function (r) {
buffer.push((Config.groups[r] ? Config.groups[r].name + "s (" + r + ")" : r) + ":\n" + rankLists[r].sortBy(toId).join(", "));
});
if (!buffer.length) buffer = "This server has no global authority.";
connection.popup(buffer.join("\n\n"));
},
me: function (target, room, user, connection) {
// By default, /me allows a blank message
if (target) target = this.canTalk(target);
if (!target) return;
return '/me ' + target;
},
mee: function (target, room, user, connection) {
// By default, /mee allows a blank message
if (target) target = this.canTalk(target);
if (!target) return;
return '/mee ' + target;
},
avatar: function (target, room, user) {
if (!target) return this.parse('/avatars');
var parts = target.split(',');
var avatar = parseInt(parts[0]);
if (parts[0] === '#bw2elesa') {
avatar = parts[0];
}
if (typeof avatar === 'number' && (!avatar || avatar > 294 || avatar < 1)) {
if (!parts[1]) {
this.sendReply("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."],
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.sendReply("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."],
pm: 'msg',
whisper: 'msg',
w: 'msg',
msg: function (target, room, user, connection) {
if (!target) return this.parse('/help msg');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!target) {
this.sendReply("You forgot the comma.");
return this.parse('/help msg');
}
this.pmTarget = (targetUser || this.targetUsername);
if (!targetUser || !targetUser.connected) {
if (targetUser && !targetUser.connected) {
this.errorReply("User " + this.targetUsername + " is offline.");
return;
} else {
this.errorReply("User " + this.targetUsername + " not found. Did you misspell their name?");
return this.parse('/help msg');
}
return;
}
if (Config.pmmodchat) {
var userGroup = user.group;
if (Config.groupsranking.indexOf(userGroup) < Config.groupsranking.indexOf(Config.pmmodchat)) {
var groupName = Config.groups[Config.pmmodchat].name || Config.pmmodchat;
this.errorReply("Because moderated chat is set, you must be of rank " + groupName + " or higher to PM users.");
return false;
}
}
if (user.locked && !targetUser.can('lock')) {
return this.errorReply("You can only private message members of the moderation team (users marked by %, @, &, or ~) when locked.");
}
if (targetUser.locked && !user.can('lock')) {
return this.errorReply("This user is locked and cannot PM.");
}
if (targetUser.ignorePMs && targetUser.ignorePMs !== user.group && !user.can('lock')) {
if (!targetUser.can('lock')) {
return this.errorReply("This user is blocking private messages right now.");
} else if (targetUser.can('bypassall')) {
return this.errorReply("This admin is too busy to answer private messages right now. Please contact a different staff member.");
}
}
if (user.ignorePMs && user.ignorePMs !== targetUser.group && !targetUser.can('lock')) {
return this.errorReply("You are blocking private messages right now.");
}
target = this.canTalk(target, null, targetUser);
if (!target) return false;
if (target.charAt(0) === '/' && target.charAt(1) !== '/') {
// PM command
var innerCmdIndex = target.indexOf(' ');
var innerCmd = (innerCmdIndex >= 0 ? target.slice(1, innerCmdIndex) : target.slice(1));
var innerTarget = (innerCmdIndex >= 0 ? target.slice(innerCmdIndex + 1) : '');
switch (innerCmd) {
case 'me':
case 'mee':
case 'announce':
break;
case 'invite':
case 'inv':
var targetRoom = Rooms.search(innerTarget);
if (!targetRoom || targetRoom === Rooms.global) return this.errorReply('The room "' + innerTarget + '" does not exist.');
if (targetRoom.staffRoom && !targetUser.isStaff) return this.errorReply('User "' + this.targetUsername + '" requires global auth to join room "' + targetRoom.id + '".');
if (targetRoom.isPrivate === true && targetRoom.modjoin && targetRoom.auth) {
if (Config.groupsranking.indexOf(targetRoom.auth[targetUser.userid] || ' ') < Config.groupsranking.indexOf(targetRoom.modjoin) && !targetUser.can('bypassall')) {
return this.errorReply('The room "' + innerTarget + '" does not exist.');
}
}
target = '/invite ' + targetRoom.id;
break;
default:
return this.errorReply("The command '/" + innerCmd + "' was unrecognized or unavailable in private messages. To send a message starting with '/" + innerCmd + "', type '//" + innerCmd + "'.");
}
}
var message = '|pm|' + user.getIdentity() + '|' + targetUser.getIdentity() + '|' + target;
user.send(message);
if (targetUser !== user) targetUser.send(message);
targetUser.lastPM = user.userid;
user.lastPM = targetUser.userid;
},
msghelp: ["/msg OR /whisper OR /w [username], [message] - Send a private message."],
blockpm: 'ignorepms',
blockpms: 'ignorepms',
ignorepm: 'ignorepms',
ignorepms: function (target, room, user) {
if (user.ignorePMs === (target || true)) return this.sendReply("You are already blocking private messages! To unblock, use /unblockpms");
if (user.can('lock') && !user.can('bypassall')) return this.sendReply("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."],
unblockpm: 'unignorepms',
unblockpms: 'unignorepms',
unignorepm: 'unignorepms',
unignorepms: function (target, room, user) {
if (!user.ignorePMs) return this.sendReply("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."],
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."],
unaway: 'back',
unafk: 'back',
back: function () {
this.parse('/unblockpms');
this.parse('/unblockchallenges');
},
backhelp: ["/back - Unblocks challenges and/or private messages, if either are blocked."],
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.sendReply("Room titles can't contain any of: ,|[-");
}
var 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.sendReply("The room '" + target + "' already exists.");
if (Rooms.global.addChatRoom(target)) {
if (cmd === 'makeprivatechatroom') {
var targetRoom = Rooms.search(target);
targetRoom.isPrivate = true;
targetRoom.chatRoomData.isPrivate = true;
Rooms.global.writeChatRoomData();
if (Rooms('upperstaff')) {
Rooms('upperstaff').add('|raw|<div class="broadcast-green">Private chat room created: <b>' + Tools.escapeHTML(target) + '</b></div>').update();
}
return this.sendReply("The private chat room '" + target + "' was created.");
} else {
if (Rooms('staff')) {
Rooms('staff').add('|raw|<div class="broadcast-green">Public chat room created: <b>' + Tools.escapeHTML(target) + '</b></div>').update();
}
if (Rooms('upperstaff')) {
Rooms('upperstaff').add('|raw|<div class="broadcast-green">Public chat room created: <b>' + Tools.escapeHTML(target) + '</b></div>').update();
}
return this.sendReply("The chat room '" + target + "' was created.");
}
}
return this.sendReply("An error occurred while trying to create the room '" + target + "'.");
},
makechatroomhelp: ["/makechatroom [roomname] - Creates a new room named [roomname]. Requires: ~"],
deregisterchatroom: function (target, room, user) {
if (!this.can('makeroom')) return;
var id = toId(target);
if (!id) return this.parse('/help deregisterchatroom');
var targetRoom = Rooms.search(id);
if (!targetRoom) return this.sendReply("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.sendReply("The room '" + target + "' isn't registered.");
},
deregisterchatroomhelp: ["/deregisterchatroom [roomname] - Deletes room [roomname] after the next server restart. Requires: ~"],
hideroom: 'privateroom',
hiddenroom: 'privateroom',
secretroom: 'privateroom',
privateroom: function (target, room, user, connection, cmd) {
var setting;
switch (cmd) {
case 'privateroom':
case 'secretroom':
if (!this.can('makeroom')) return;
setting = true;
break;
default:
if (!this.can('privateroom', null, room)) return;
if (room.isPrivate === true && target !== 'force') {
return this.sendReply("This room is a secret room. Use /privateroom to toggle, or /hiddenroom force to force hidden.");
}
setting = 'hidden';
break;
}
if (target === 'off') {
delete room.isPrivate;
this.addModCommand("" + user.name + " made this room public.");
if (room.chatRoomData) {
delete room.chatRoomData.isPrivate;
Rooms.global.writeChatRoomData();
}
} else {
if (room.isPrivate === setting) {
return this.errorReply("This room is already " + (setting === true ? 'secret' : setting) + ".");
}
room.isPrivate = setting;
this.addModCommand("" + user.name + " made this room " + (setting === true ? 'secret' : setting) + ".");
if (room.chatRoomData) {
room.chatRoomData.isPrivate = setting;
Rooms.global.writeChatRoomData();
}
}
},
privateroomhelp: ["/privateroom [on/off] - Makes or unmakes a room private. Requires: ~",
"/hiddenroom [on/off] - Makes or unmakes a room hidden. Hidden rooms will maintain global ranks of users. Requires: \u2605 ~"],
modjoin: function (target, room, user) {
if (!this.can('privateroom', null, room)) return;
if (target === 'off' || target === 'false') {
delete room.modjoin;
this.addModCommand("" + user.name + " turned off modjoin.");
if (room.chatRoomData) {
delete room.chatRoomData.modjoin;
Rooms.global.writeChatRoomData();
}
} else {
if ((target === 'on' || target === 'true' || !target) || !user.can('privateroom')) {
room.modjoin = true;
this.addModCommand("" + user.name + " turned on modjoin.");
} else if (target in Config.groups) {
room.modjoin = target;
this.addModCommand("" + user.name + " set modjoin to " + target + ".");
} else {
this.sendReply("Unrecognized modjoin setting.");
return false;
}
if (room.chatRoomData) {
room.chatRoomData.modjoin = room.modjoin;
Rooms.global.writeChatRoomData();
}
if (!room.modchat) this.parse('/modchat ' + Config.groupsranking[1]);
if (!room.isPrivate) this.parse('/hiddenroom');
}
},
officialchatroom: 'officialroom',
officialroom: function (target, room, user) {
if (!this.can('makeroom')) return;
if (!room.chatRoomData) {
return this.sendReply("/officialroom - This room can't be made official");
}
if (target === 'off') {
delete room.isOfficial;
this.addModCommand("" + user.name + " made this chat room unofficial.");
delete room.chatRoomData.isOfficial;
Rooms.global.writeChatRoomData();
} else {
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.canBroadcast()) return;
if (!room.desc) return this.sendReply("This room does not have a description set.");
this.sendReplyBox("The room description is: " + Tools.escapeHTML(room.desc));
return;
}
if (!this.can('declare')) return false;
if (target.length > 80) return this.sendReply("Error: Room description is too long (must be at most 80 characters).");
var normalizedTarget = ' ' + target.toLowerCase().replace('[^a-zA-Z0-9]+', ' ').trim() + ' ';
if (normalizedTarget.includes(' welcome ')) {
return this.sendReply("Error: Room description must not contain the word 'welcome'.");
}
if (normalizedTarget.slice(0, 9) === ' discuss ') {
return this.sendReply("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.sendReply("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) {
if (!target) {
if (!this.canBroadcast()) 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 + '</div>');
if (!this.broadcasting && user.can('declare', null, room)) {
this.sendReply('Source:');
this.sendReplyBox('<code>/roomintro ' + Tools.escapeHTML(room.introMessage) + '</code>');
}
return;
}
target = target.trim();
if (!this.can('declare', null, room)) return false;
if (!this.canHTML(target)) return;
if (!/</.test(target)) {
// not HTML, do some simple URL linking
var 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;
this.sendReply("(The room introduction has been changed to:)");
this.sendReply('|raw|<div class="infobox infobox-limited">' + target + '</div>');
this.privateModCommand("(" + user.name + " changed the roomintro.)");
if (room.chatRoomData) {
room.chatRoomData.introMessage = room.introMessage;
Rooms.global.writeChatRoomData();
}
},
roomalias: function (target, room, user) {
if (!target) {
if (!this.canBroadcast()) 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('setalias')) return false;
var alias = toId(target);
if (!alias.length) return this.sendReply("Only alphanumeric characters are valid in an alias.");
if (Rooms.get(alias) || Rooms.aliases[alias]) return this.sendReply("You cannot set an alias to an existing room or alias.");
Rooms.aliases[alias] = room.id;
this.privateModCommand("(" + user.name + " added the room alias '" + target + "'.)");
if (!room.aliases) room.aliases = [];
room.aliases.push(alias);
if (room.chatRoomData) {
room.chatRoomData.aliases = room.aliases;
Rooms.global.writeChatRoomData();
}
},
removeroomalias: function (target, room, user) {
if (!room.aliases) return this.sendReply("This room does not have any aliases.");
if (!this.can('setalias')) return false;
var alias = toId(target);
if (!alias.length || !Rooms.aliases[alias]) return this.sendReply("Please specify an existing alias.");
if (Rooms.aliases[alias] !== room.id) return this.sendReply("You may only remove an alias from the current room.");
this.privateModCommand("(" + user.name + " removed the room alias '" + target + "'.)");
var aliasIndex = room.aliases.indexOf(alias);
if (aliasIndex >= 0) {
room.aliases.splice(aliasIndex, 1);
delete Rooms.aliases[alias];
Rooms.global.writeChatRoomData();
}
},
roomowner: function (target, room, user) {
if (!room.chatRoomData) {
return this.sendReply("/roomowner - This room isn't designed for per-room moderation to be added");
}
if (!target) return this.parse('/help roomowner');
target = this.splitTarget(target, true);
var targetUser = this.targetUser;
if (!targetUser) return this.sendReply("User '" + this.targetUsername + "' is not online.");
if (!this.can('makeroom')) return false;
if (!room.auth) room.auth = room.chatRoomData.auth = {};
var name = targetUser.name;
room.auth[targetUser.userid] = '#';
this.addModCommand("" + name + " was appointed Room Owner by " + user.name + ".");
room.onUpdateIdentity(targetUser);
Rooms.global.writeChatRoomData();
},
roomownerhelp: ["/roomowner [username] - Appoints [username] as a room owner. Removes official status. Requires: ~"],
roomdeowner: 'deroomowner',
deroomowner: function (target, room, user) {
if (!room.auth) {
return this.sendReply("/roomdeowner - This room isn't designed for per-room moderation");
}
if (!target) return this.parse('/help roomdeowner');
target = this.splitTarget(target, true);
var targetUser = this.targetUser;
var name = this.targetUsername;
var userid = toId(name);
if (!userid || userid === '') return this.sendReply("User '" + name + "' does not exist.");
if (room.auth[userid] !== '#') return this.sendReply("User '" + name + "' is not a room owner.");
if (!this.can('makeroom')) return false;
delete room.auth[userid];
this.sendReply("(" + name + " is no longer Room Owner.)");
if (targetUser) targetUser.updateIdentity();
if (room.chatRoomData) {
Rooms.global.writeChatRoomData();
}
},
deroomownerhelp: ["/roomdeowner [username] - Removes [username]'s status as a room owner. Requires: ~"],
roomdemote: 'roompromote',
roompromote: function (target, room, user, connection, cmd) {
if (!room.auth) {
this.sendReply("/roompromote - This room isn't designed for per-room moderation");
return this.sendReply("Before setting room mods, you need to set it up with /roomowner");
}
if (!target) return this.parse('/help roompromote');
target = this.splitTarget(target, true);
var targetUser = this.targetUser;
var userid = toId(this.targetUsername);
var name = targetUser ? targetUser.name : this.targetUsername;
if (!userid) return this.parse('/help roompromote');
if (!room.auth || !room.auth[userid]) {
if (!targetUser) {
return this.sendReply("User '" + name + "' is offline and unauthed, and so can't be promoted.");
}
if (!targetUser.registered) {
return this.sendReply("User '" + name + "' is unregistered, and so can't be promoted.");
}
}
var currentGroup = ((room.auth && room.auth[userid]) || (room.isPrivate !== true && targetUser.group) || ' ');
var nextGroup = target;
if (target === 'deauth') nextGroup = Config.groupsranking[0];
if (!nextGroup) {
return this.sendReply("Please specify a group such as /roomvoice or /roomdeauth");
}
if (!Config.groups[nextGroup]) {
return this.sendReply("Group '" + nextGroup + "' does not exist.");
}
if (Config.groups[nextGroup].globalonly || (Config.groups[nextGroup].battleonly && !room.battle)) {
return this.sendReply("Group 'room" + Config.groups[nextGroup].id + "' does not exist as a room rank.");
}
var groupName = Config.groups[nextGroup].name || "regular user";
if ((room.auth[userid] || Config.groupsranking[0]) === nextGroup) {
return this.sendReply("User '" + name + "' is already a " + groupName + " in this room.");
}
if (!user.can('makeroom')) {
if (currentGroup !== ' ' && !user.can('room' + (Config.groups[currentGroup] ? Config.groups[currentGroup].id : 'voice'), null, room)) {
return this.sendReply("/" + cmd + " - Access denied for promoting/demoting from " + (Config.groups[currentGroup] ? Config.groups[currentGroup].name : "an undefined group") + ".");
}
if (nextGroup !== ' ' && !user.can('room' + Config.groups[nextGroup].id, null, room)) {
return this.sendReply("/" + cmd + " - Access denied for promoting/demoting to " + Config.groups[nextGroup].name + ".");
}
}
if (nextGroup === ' ') {
delete room.auth[userid];
} else {
room.auth[userid] = nextGroup;
}
if (Config.groups[nextGroup].rank < Config.groups[currentGroup].rank) {
this.privateModCommand("(" + name + " was demoted to Room " + groupName + " by " + user.name + ".)");
if (targetUser && Rooms.rooms[room.id].users[targetUser.userid]) targetUser.popup("You were demoted to Room " + groupName + " by " + user.name + ".");
} else if (nextGroup === '#') {
this.addModCommand("" + name + " was promoted to " + groupName + " by " + user.name + ".");
} else {
this.addModCommand("" + name + " was promoted to Room " + groupName + " by " + user.name + ".");
}
if (targetUser) targetUser.updateIdentity(room.id);
if (room.chatRoomData) Rooms.global.writeChatRoomData();
},
roompromotehelp: ["/roompromote OR /roomdemote [username], [group symbol] - Promotes/demotes the user to the specified room rank. Requires: @ # & ~",
"/room[group] [username] - Promotes/demotes the user to the specified room rank. Requires: @ # & ~",
"/roomdeauth [username] - Removes all room rank from the user. Requires: @ # & ~"],
roomstaff: 'roomauth',
roomauth: function (target, room, user, connection) {
var targetRoom = room;
if (target) targetRoom = Rooms.search(target);
var unavailableRoom = targetRoom && (targetRoom !== room && (targetRoom.modjoin || targetRoom.staffRoom) && !user.can('makeroom'));
if (!targetRoom || unavailableRoom) return this.sendReply("The room '" + target + "' does not exist.");
if (!targetRoom.auth) return this.sendReply("/roomauth - The room '" + (targetRoom.title ? targetRoom.title : target) + "' isn't designed for per-room moderation and therefore has no auth list.");
var rankLists = {};
for (var u in targetRoom.auth) {
if (!rankLists[targetRoom.auth[u]]) rankLists[targetRoom.auth[u]] = [];
rankLists[targetRoom.auth[u]].push(u);
}
var buffer = [];
Object.keys(rankLists).sort(function (a, b) {
return (Config.groups[b] || {rank:0}).rank - (Config.groups[a] || {rank:0}).rank;
}).forEach(function (r) {
buffer.push((Config.groups[r] ? Config.groups[r] .name + "s (" + r + ")" : r) + ":\n" + rankLists[r].sort().join(", "));
});
if (!buffer.length) {
connection.popup("The room '" + targetRoom.title + "' has no auth.");
return;
}
if (targetRoom !== room) buffer.unshift("" + targetRoom.title + " room auth:");
connection.popup(buffer.join("\n\n"));
},
userauth: function (target, room, user, connection) {
var targetId = toId(target) || user.userid;
var targetUser = Users.getExact(targetId);
var targetUsername = (targetUser ? targetUser.name : target);
var buffer = [];
var innerBuffer = [];
var group = Users.usergroups[targetId];
if (group) {
buffer.push('Global auth: ' + group.charAt(0));
}
for (var i = 0; i < Rooms.global.chatRooms.length; i++) {
var curRoom = Rooms.global.chatRooms[i];
if (!curRoom.auth || curRoom.isPrivate) continue;
group = curRoom.auth[targetId];
if (!group) continue;
innerBuffer.push(group + curRoom.id);
}
if (innerBuffer.length) {
buffer.push('Room auth: ' + innerBuffer.join(', '));
}
if (targetId === user.userid || user.can('alts')) {
innerBuffer = [];
for (var i = 0; i < Rooms.global.chatRooms.length; i++) {
var curRoom = Rooms.global.chatRooms[i];
if (!curRoom.auth || !curRoom.isPrivate) continue;
if (curRoom.isPrivate === true) continue;
var auth = curRoom.auth[targetId];
if (!auth) continue;
innerBuffer.push(auth + curRoom.id);
}
if (innerBuffer.length) {
buffer.push('Hidden room auth: ' + innerBuffer.join(', '));
}
}
if (targetId === user.userid || user.can('makeroom')) {
innerBuffer = [];
for (var i = 0; i < Rooms.global.chatRooms.length; i++) {
var curRoom = Rooms.global.chatRooms[i];
if (!curRoom.auth || !curRoom.isPrivate) continue;
if (curRoom.isPrivate !== true) continue;
var auth = curRoom.auth[targetId];
if (!auth) continue;
innerBuffer.push(auth + curRoom.id);
}
if (innerBuffer.length) {
buffer.push('Private room auth: ' + innerBuffer.join(', '));
}
}
if (!buffer.length) {
buffer.push("No global or room auth.");
}
buffer.unshift("" + targetUsername + " user auth:");
connection.popup(buffer.join("\n\n"));
},
rb: 'roomban',
roomban: function (target, room, user, connection) {
if (!target) return this.parse('/help roomban');
if (room.isMuted(user) && !user.can('bypassall')) return this.sendReply("You cannot do this while unable to talk.");
target = this.splitTarget(target);
var targetUser = this.targetUser;
var name = this.targetUsername;
var userid = toId(name);
if (!userid || !targetUser) return this.sendReply("User '" + name + "' does not exist.");
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply("The reason is too long. It cannot exceed " + MAX_REASON_LENGTH + " characters.");
}
if (!this.can('ban', targetUser, room)) return false;
if (!room.bannedUsers || !room.bannedIps) {
return this.sendReply("Room bans are not meant to be used in room " + room.id + ".");
}
if (room.bannedUsers[userid] && room.bannedIps[targetUser.latestIp]) return this.sendReply("User " + targetUser.name + " is already banned from room " + room.id + ".");
if (targetUser in room.users) {
targetUser.popup(
"|html|<p>" + Tools.escapeHTML(user.name) + " has banned you from the room " + room.id + ".</p>" + (target ? "<p>Reason: " + Tools.escapeHTML(target) + "</p>" : "") +
"<p>To appeal the ban, PM the staff member that banned you" + (room.auth ? " or a room owner. </p><p><button name=\"send\" value=\"/roomauth " + room.id + "\">List Room Staff</button></p>" : ".</p>")
);
}
this.addModCommand("" + targetUser.name + " was banned from room " + room.id + " by " + user.name + "." + (target ? " (" + target + ")" : ""));
var acAccount = (targetUser.autoconfirmed !== targetUser.userid && targetUser.autoconfirmed);
var alts = room.roomBan(targetUser);
if (alts.length) {
this.privateModCommand("(" + targetUser.name + "'s " + (acAccount ? " ac account: " + acAccount + ", " : "") + "roombanned alts: " + alts.join(", ") + ")");
for (var i = 0; i < alts.length; ++i) {
this.add('|unlink|' + toId(alts[i]));
}
} else if (acAccount) {
this.privateModCommand("(" + targetUser.name + "'s ac account: " + acAccount + ")");
}
this.add('|unlink|' + this.getLastIdOf(targetUser));
},
roombanhelp: ["/roomban [username] - Bans the user from the room you are in. Requires: @ # & ~"],
unroomban: 'roomunban',
roomunban: function (target, room, user, connection) {
if (!target) return this.parse('/help roomunban');
if (!room.bannedUsers || !room.bannedIps) {
return this.sendReply("Room bans are not meant to be used in room " + room.id + ".");
}
if (room.isMuted(user) && !user.can('bypassall')) return this.sendReply("You cannot do this while unable to talk.");
this.splitTarget(target, true);
var targetUser = this.targetUser;
var userid = room.isRoomBanned(targetUser) || toId(target);
if (!userid) return this.sendReply("User '" + target + "' is an invalid username.");
if (targetUser && !this.can('ban', targetUser, room)) return false;
var unbannedUserid = room.unRoomBan(userid);
if (!unbannedUserid) return this.sendReply("User " + userid + " is not banned from room " + room.id + ".");
this.addModCommand("" + unbannedUserid + " was unbanned from room " + room.id + " by " + user.name + ".");
},
roomunbanhelp: ["/roomunban [username] - Unbans the user from the room you are in. Requires: @ # & ~"],
autojoin: function (target, room, user, connection) {
Rooms.global.autojoinRooms(user, connection);
var targets = target.split(',');
var autojoins = [];
if (targets.length > 9 || Object.keys(connection.rooms).length > 1) return;
for (var i = 0; i < targets.length; i++) {
if (user.tryJoinRoom(targets[i], connection) === null) {
autojoins.push(targets[i]);
}
}
connection.autojoins = autojoins.join(',');
},
joim: 'join',
j: 'join',
join: function (target, room, user, connection) {
if (!target) return false;
if (user.tryJoinRoom(target, connection) === null) {
connection.sendTo(target, "|noinit|namerequired|The room '" + target + "' does not exist or requires a login to join.");
}
},
leave: 'part',
part: function (target, room, user, connection) {
if (room.id === 'global') return false;
var targetRoom = Rooms.search(target);
if (target && !targetRoom) {
return this.sendReply("The room '" + target + "' does not exist.");
}
user.leaveRoom(targetRoom || room, connection);
},
/*********************************************************
* Moderating: Punishments
*********************************************************/
kick: 'warn',
k: 'warn',
warn: function (target, room, user) {
if (!target) return this.parse('/help warn');
if (room.isMuted(user) && !user.can('bypassall')) return this.sendReply("You cannot do this while unable to talk.");
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser || !targetUser.connected) return this.sendReply("User '" + this.targetUsername + "' does not exist.");
if (!(targetUser in room.users)) {
return this.sendReply("User " + this.targetUsername + " is not in the room " + room.id + ".");
}
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply("The reason is too long. It cannot exceed " + MAX_REASON_LENGTH + " characters.");
}
if (!this.can('warn', targetUser, room)) return false;
this.addModCommand("" + targetUser.name + " was warned by " + user.name + "." + (target ? " (" + target + ")" : ""));
targetUser.send('|c|~|/warn ' + target);
this.add('|unlink|' + this.getLastIdOf(targetUser));
},
warnhelp: ["/warn OR /k [username], [reason] - Warns a user showing them the Pok\u00e9mon Showdown Rules and [reason] in an overlay. Requires: % @ # & ~"],
redirect: 'redir',
redir: function (target, room, user, connection) {
if (!target) return this.parse('/help redirect');
target = this.splitTarget(target);
var targetUser = this.targetUser;
var targetRoom = Rooms.search(target);
if (!targetRoom) {
return this.sendReply("The room '" + target + "' does not exist.");
}
if (!this.can('warn', targetUser, room) || !this.can('warn', targetUser, targetRoom)) return false;
if (!targetUser || !targetUser.connected) {
return this.sendReply("User " + this.targetUsername + " not found.");
}
if (targetRoom.id === "global") return this.sendReply("Users cannot be redirected to the global room.");
if (targetRoom.isPrivate) {
return this.errorReply("Do not redirect users to private rooms. Use /invite if you must, but honestly, the room probably wants to be kept private.");
}
if (Rooms.rooms[targetRoom.id].users[targetUser.userid]) {
return this.sendReply("User " + targetUser.name + " is already in the room " + targetRoom.title + "!");
}
if (!Rooms.rooms[room.id].users[targetUser.userid]) {
return this.sendReply("User " + this.targetUsername + " is not in the room " + room.id + ".");
}
if (targetUser.joinRoom(targetRoom.id) === false) return this.sendReply("User " + targetUser.name + " could not be joined to room " + targetRoom.title + ". They could be banned from the room.");
this.addModCommand("" + targetUser.name + " was redirected to room " + targetRoom.title + " by " + user.name + ".");
targetUser.leaveRoom(room);
},
redirhelp: ["/redirect OR /redir [username], [roomname] - Attempts to redirect the user [username] to the room [roomname]. Requires: % @ & ~"],
m: 'mute',
mute: function (target, room, user, connection, cmd) {
if (!target) return this.parse('/help mute');
if (room.isMuted(user) && !user.can('bypassall')) return this.sendReply("You cannot do this while unable to talk.");
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) return this.sendReply("User '" + this.targetUsername + "' does not exist.");
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply("The reason is too long. It cannot exceed " + MAX_REASON_LENGTH + " characters.");
}
var muteDuration = ((cmd === 'hm' || cmd === 'hourmute') ? HOURMUTE_LENGTH : MUTE_LENGTH);
if (!this.can('mute', targetUser, room)) return false;
var canBeMutedFurther = ((room.getMuteTime(targetUser) || 0) <= (muteDuration * 5 / 6));
if ((room.isMuted(targetUser) && !canBeMutedFurther) || targetUser.locked || !targetUser.connected) {
var problem = " but was already " + (!targetUser.connected ? "offline" : targetUser.locked ? "locked" : "muted");
if (!target) {
return this.privateModCommand("(" + targetUser.name + " would be muted by " + user.name + problem + ".)");
}
return this.addModCommand("" + targetUser.name + " would be muted by " + user.name + problem + "." + (target ? " (" + target + ")" : ""));
}
if (targetUser in room.users) targetUser.popup("|modal|" + user.name + " has muted you in " + room.id + " for " + muteDuration.duration() + ". " + target);
this.addModCommand("" + targetUser.name + " was muted by " + user.name + " for " + muteDuration.duration() + "." + (target ? " (" + target + ")" : ""));
if (targetUser.autoconfirmed && targetUser.autoconfirmed !== targetUser.userid) this.privateModCommand("(" + targetUser.name + "'s ac account: " + targetUser.autoconfirmed + ")");
this.add('|unlink|' + this.getLastIdOf(targetUser));
room.mute(targetUser, muteDuration, false);
},
mutehelp: ["/mute OR /m [username], [reason] - Mutes a user with reason for 7 minutes. Requires: % @ # & ~"],
hm: 'hourmute',
hourmute: function (target) {
if (!target) return this.parse('/help hourmute');
this.run('mute');
},
hourmutehelp: ["/hourmute OR /hm [username], [reason] - Mutes a user with reason for an hour. Requires: % @ # & ~"],
um: 'unmute',
unmute: function (target, room, user) {
if (!target) return this.parse('/help unmute');
target = this.splitTarget(target);
if (room.isMuted(user) && !user.can('bypassall')) return this.sendReply("You cannot do this while unable to talk.");
if (!this.can('mute', null, room)) return false;
var targetUser = this.targetUser;
var successfullyUnmuted = room.unmute(targetUser ? targetUser.userid : this.targetUsername);
if (successfullyUnmuted) {
this.addModCommand("" + (targetUser ? targetUser.name : successfullyUnmuted) + " was unmuted by " + user.name + ".");
} else {
this.sendReply("" + (targetUser ? targetUser.name : this.targetUsername) + " is not muted.");
}
},
unmutehelp: ["/unmute [username] - Removes mute from user. Requires: % @ # & ~"],
forcelock: 'lock',
l: 'lock',
ipmute: 'lock',
lock: function (target, room, user, connection, cmd) {
if (!target) return this.parse('/help lock');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) return this.sendReply("User '" + this.targetUsername + "' does not exist.");
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply("The reason is too long. It cannot exceed " + MAX_REASON_LENGTH + " characters.");
}
if (!this.can('lock', targetUser)) return false;
if ((targetUser.locked || Users.checkBanned(targetUser.latestIp)) && !target) {
var problem = " but was already " + (targetUser.locked ? "locked" : "banned");
return this.privateModCommand("(" + targetUser.name + " would be locked by " + user.name + problem + ".)");
}
if (targetUser.confirmed) {
if (cmd === 'forcelock') {
var from = targetUser.deconfirm();
ResourceMonitor.log("[CrisisMonitor] " + targetUser.name + " was locked by " + user.name + " and demoted from " + from.join(", ") + ".");
} else {
return this.sendReply("" + targetUser.name + " is a confirmed user. If you are sure you would like to lock them use /forcelock.");
}
} else if (cmd === 'forcelock') {
return this.sendReply("Use /lock; " + targetUser.name + " is not a confirmed user.");
}
targetUser.popup("|modal|" + user.name + " has locked you from talking in chats, battles, and PMing regular users." + (target ? "\n\nReason: " + target : "") + "\n\nIf you feel that your lock was unjustified, you can still PM staff members (%, @, &, and ~) to discuss it" + (Config.appealurl ? " or you can appeal:\n" + Config.appealurl : ".") + "\n\nYour lock will expire in a few days.");
this.addModCommand("" + targetUser.name + " was locked from talking by " + user.name + "." + (target ? " (" + target + ")" : ""));
var alts = targetUser.getAlts();
var acAccount = (targetUser.autoconfirmed !== targetUser.userid && targetUser.autoconfirmed);
if (alts.length) {
this.privateModCommand("(" + targetUser.name + "'s " + (acAccount ? " ac account: " + acAccount + ", " : "") + "locked alts: " + alts.join(", ") + ")");
} else if (acAccount) {
this.privateModCommand("(" + targetUser.name + "'s ac account: " + acAccount + ")");
}
var userid = this.getLastIdOf(targetUser);
this.add('|unlink|hide|' + userid);
if (userid !== toId(this.inputUsername)) this.add('|unlink|hide|' + toId(this.inputUsername));
this.globalModlog("LOCK", targetUser, " by " + user.name + (target ? ": " + target : ""));
targetUser.lock(false, userid);
return true;
},
lockhelp: ["/lock OR /l [username], [reason] - Locks the user from talking in all chats. Requires: % @ & ~"],
unlock: function (target, room, user) {
if (!target) return this.parse('/help unlock');
if (!this.can('lock')) return false;
var targetUser = Users.get(target);
var reason = '';
if (targetUser && targetUser.locked && targetUser.locked.charAt(0) === '#') {
reason = ' (' + targetUser.locked + ')';
}
var unlocked = Users.unlock(target);
if (unlocked) {
var names = Object.keys(unlocked);
this.addModCommand(names.join(", ") + " " + ((names.length > 1) ? "were" : "was") +
" unlocked by " + user.name + "." + reason);
if (!reason) this.globalModlog("UNLOCK", target, " by " + user.name);
if (targetUser) targetUser.popup("" + user.name + " has unlocked you.");
} else {
this.sendReply("User '" + target + "' is not locked.");
}
},
unlockhelp: ["/unlock [username] - Unlocks the user. Requires: % @ & ~"],
forceban: 'ban',
b: 'ban',
ban: function (target, room, user, connection, cmd) {
if (!target) return this.parse('/help ban');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) return this.sendReply("User '" + this.targetUsername + "' does not exist.");
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply("The reason is too long. It cannot exceed " + MAX_REASON_LENGTH + " characters.");
}
if (!this.can('ban', targetUser)) return false;
if (Users.checkBanned(targetUser.latestIp) && !target && !targetUser.connected) {
var problem = " but was already banned";
return this.privateModCommand("(" + targetUser.name + " would be banned by " + user.name + problem + ".)");