forked from smogon/pokemon-showdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.js
1798 lines (1571 loc) · 61.7 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.
*
* If you'd like to modify commands, please go to config/commands.js,
* which also teaches you how to use commands.
*
* @license MIT license
*/
var crypto = require('crypto');
const MAX_REASON_LENGTH = 300;
var commands = exports.commands = {
version: function(target, room, user) {
if (!this.canBroadcast()) return;
this.sendReplyBox('Server version: <b>'+CommandParser.package.version+'</b>');
},
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 (!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/'+avatar+'.png" alt="" width="80" height="80" />');
}
},
logout: function(target, room, user) {
user.resetName();
},
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);
},
pm: 'msg',
whisper: 'msg',
w: 'msg',
msg: function(target, room, user) {
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');
}
if (!targetUser || !targetUser.connected) {
if (targetUser && !targetUser.connected) {
this.popupReply('User '+this.targetUsername+' is offline.');
} else if (!target) {
this.popupReply('User '+this.targetUsername+' not found. Did you forget a comma?');
} else {
this.popupReply('User '+this.targetUsername+' not found. Did you misspell their name?');
}
return this.parse('/help msg');
}
if (config.pmmodchat) {
var userGroup = user.group;
if (config.groupsranking.indexOf(userGroup) < config.groupsranking.indexOf(config.pmmodchat)) {
var groupName = config.groups[config.pmmodchat].name;
if (!groupName) groupName = config.pmmodchat;
this.popupReply('Because moderated chat is set, you must be of rank ' + groupName +' or higher to PM users.');
return false;
}
}
if (user.locked && !targetUser.can('lock', user)) {
return this.popupReply('You can only private message members of the moderation team (users marked by %, @, &, or ~) when locked.');
}
if (targetUser.locked && !user.can('lock', targetUser)) {
return this.popupReply('This user is locked and cannot PM.');
}
if (targetUser.ignorePMs && !user.can('lock')) {
if (!targetUser.can('lock')) {
return this.popupReply('This user is blocking Private Messages right now.');
} else if (targetUser.can('hotpatch')) {
return this.popupReply('This admin is too busy to answer Private Messages right now. Please contact a different staff member.');
}
}
target = this.canTalk(target, null);
if (!target) return false;
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;
},
blockpm: 'ignorepms',
blockpms: 'ignorepms',
ignorepm: 'ignorepms',
ignorepms: function(target, room, user) {
if (user.ignorePMs) return this.sendReply('You are already blocking Private Messages!');
if (user.can('lock') && !user.can('hotpatch')) return this.sendReply('You are not allowed to block Private Messages.');
user.ignorePMs = true;
return this.sendReply('You are now blocking Private Messages.');
},
unblockpm: 'unignorepms',
unblockpms: 'unignorepms',
unignorepm: 'unignorepms',
unignorepms: function(target, room, user) {
if (!user.ignorePMs) return this.sendReply('You are not blocking Private Messages!');
user.ignorePMs = false;
return this.sendReply('You are no longer blocking Private Messages.');
},
makechatroom: function(target, room, user) {
if (!this.can('makeroom')) return;
var id = toId(target);
if (!id) return this.parse('/help makechatroom');
if (Rooms.rooms[id]) {
return this.sendReply("The room '"+target+"' already exists.");
}
if (Rooms.global.addChatRoom(target)) {
return this.sendReply("The room '"+target+"' was created.");
}
return this.sendReply("An error occurred while trying to create the room '"+target+"'.");
},
deregisterchatroom: function(target, room, user) {
if (!this.can('makeroom')) return;
var id = toId(target);
if (!id) return this.parse('/help deregisterchatroom');
var targetRoom = Rooms.get(id);
if (!targetRoom) return this.sendReply("The room '"+id+"' 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.");
},
privateroom: function(target, room, user) {
if (!this.can('privateroom', null, room)) return;
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 {
room.isPrivate = true;
this.addModCommand(user.name+' made this room private.');
if (room.chatRoomData) {
room.chatRoomData.isPrivate = true;
Rooms.global.writeChatRoomData();
}
}
},
modjoin: function(target, room, user) {
if (!this.can('privateroom', null, room)) return;
if (target === 'off') {
delete room.modjoin;
this.addModCommand(user.name+' turned off modjoin.');
if (room.chatRoomData) {
delete room.chatRoomData.modjoin;
Rooms.global.writeChatRoomData();
}
} else {
room.modjoin = true;
this.addModCommand(user.name+' turned on modjoin.');
if (room.chatRoomData) {
room.chatRoomData.modjoin = true;
Rooms.global.writeChatRoomData();
}
}
},
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();
}
},
roomowner: function(target, room, user) {
if (!room.chatRoomData) {
return this.sendReply("/roomowner - This room isn't designed for per-room moderation to be added");
}
var target = this.splitTarget(target, true);
var targetUser = this.targetUser;
if (!targetUser) return this.sendReply("User '"+this.targetUsername+"' is not online.");
if (!this.can('makeroom', targetUser, room)) 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();
},
roomdeowner: 'deroomowner',
deroomowner: function(target, room, user) {
if (!room.auth) {
return this.sendReply("/roomdeowner - This room isn't designed for per-room moderation");
}
var 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', null, room)) return false;
delete room.auth[userid];
this.sendReply('('+name+' is no longer Room Owner.)');
if (targetUser) targetUser.updateIdentity();
if (room.chatRoomData) {
Rooms.global.writeChatRoomData();
}
},
roomdesc: function(target, room, user) {
if (!target) {
if (!this.canBroadcast()) return;
var re = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/g;
if (!room.desc) return this.sendReply("This room does not have a description set.");
this.sendReplyBox('The room description is: '+room.desc.replace(re, "<a href=\"$1\">$1</a>"));
return;
}
if (!this.can('roommod', null, room)) return false;
if (target.length > 80) {
return this.sendReply('Error: Room description is too long (must be at most 80 characters).');
}
room.desc = target;
this.sendReply('(The room description is now: '+target+')');
if (room.chatRoomData) {
room.chatRoomData.desc = room.desc;
Rooms.global.writeChatRoomData();
}
},
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');
var target = this.splitTarget(target, true);
var targetUser = this.targetUser;
var userid = toUserid(this.targetUsername);
var name = targetUser ? targetUser.name : this.targetUsername;
if (!userid) {
if (target && config.groups[target]) {
var groupid = config.groups[target].id;
return this.sendReply("/room"+groupid+" [username] - Promote a user to "+groupid+" in this room only");
}
return this.parse("/help roompromote");
}
var currentGroup = (room.auth[userid] || ' ');
if (!targetUser && !room.auth[userid]) {
return this.sendReply("User '"+this.targetUsername+"' is offline and unauthed, and so can't be promoted.");
}
var nextGroup = target || Users.getNextGroupSymbol(currentGroup, cmd === 'roomdemote', true);
if (target === 'deauth') nextGroup = config.groupsranking[0];
if (!config.groups[nextGroup]) {
return this.sendReply('Group \'' + nextGroup + '\' does not exist.');
}
if (config.groups[nextGroup].globalonly) {
return this.sendReply('Group \'room' + config.groups[nextGroup].id + '\' does not exist as a room rank.');
}
if (currentGroup !== ' ' && !user.can('room'+config.groups[currentGroup].id, null, room)) {
return this.sendReply('/' + cmd + ' - Access denied for promoting from '+config.groups[currentGroup].name+'.');
}
if (nextGroup !== ' ' && !user.can('room'+config.groups[nextGroup].id, null, room)) {
return this.sendReply('/' + cmd + ' - Access denied for promoting to '+config.groups[nextGroup].name+'.');
}
if (currentGroup === nextGroup) {
return this.sendReply("User '"+this.targetUsername+"' is already a "+(config.groups[nextGroup].name || 'regular user')+" in this room.");
}
if (config.groups[nextGroup].globalonly) {
return this.sendReply("The rank of "+config.groups[nextGroup].name+" is global-only and can't be room-promoted to.");
}
var isDemotion = (config.groups[nextGroup].rank < config.groups[currentGroup].rank);
var groupName = (config.groups[nextGroup].name || nextGroup || '').trim() || 'a regular user';
if (nextGroup === ' ') {
delete room.auth[userid];
} else {
room.auth[userid] = nextGroup;
}
if (isDemotion) {
this.privateModCommand('('+name+' was appointed to Room ' + groupName + ' by '+user.name+'.)');
if (targetUser) {
targetUser.popup('You were appointed to Room ' + groupName + ' by ' + user.name + '.');
}
} else {
this.addModCommand(''+name+' was appointed to Room ' + groupName + ' by '+user.name+'.');
}
if (targetUser) {
targetUser.updateIdentity();
}
if (room.chatRoomData) {
Rooms.global.writeChatRoomData();
}
},
autojoin: function(target, room, user, connection) {
Rooms.global.autojoinRooms(user, connection);
},
join: function(target, room, user, connection) {
if (!target) return false;
var targetRoom = Rooms.get(target) || Rooms.get(toId(target));
if (!targetRoom) {
if (target === 'lobby') return connection.sendTo(target, "|noinit|nonexistent|");
return connection.sendTo(target, "|noinit|nonexistent|The room '"+target+"' does not exist.");
}
if (targetRoom.isPrivate) {
if (targetRoom.modjoin) {
var userGroup = user.group;
if (targetRoom.auth) {
userGroup = targetRoom.auth[user.userid] || ' ';
}
if (config.groupsranking.indexOf(userGroup) < config.groupsranking.indexOf(targetRoom.modchat)) {
return connection.sendTo(target, "|noinit|nonexistent|The room '"+target+"' does not exist.");
}
}
if (!user.named) {
return connection.sendTo(target, "|noinit|namerequired|You must have a name in order to join the room '"+target+"'.");
}
}
if (!user.joinRoom(targetRoom || room, connection)) {
return connection.sendTo(target, "|noinit|joinfailed|The room '"+target+"' could not be joined.");
}
},
rb: 'roomban',
roomban: function(target, room, user, connection) {
if (!target) return this.parse('/help roomban');
target = this.splitTarget(target, true);
var targetUser = this.targetUser;
var name = this.targetUsername;
var userid = toId(name);
if (!userid || !targetUser) return this.sendReply("User '" + name + "' does not exist.");
if (!this.can('ban', targetUser, room)) return false;
if (!Rooms.rooms[room.id].users[userid] && room.isPrivate) {
return this.sendReply('User ' + this.targetUsername + ' is not in the room ' + room.id + '.');
}
if (!room.bannedUsers || !room.bannedIps) {
return this.sendReply('Room bans are not meant to be used in room ' + room.id + '.');
}
room.bannedUsers[userid] = true;
for (var ip in targetUser.ips) {
room.bannedIps[ip] = true;
}
targetUser.popup(user.name+" has banned you from the room " + room.id + ". To appeal the ban, PM the moderator that banned you or a room owner." + (target ? " (" + target + ")" : ""));
this.addModCommand(""+targetUser.name+" was banned from room " + room.id + " by "+user.name+"." + (target ? " (" + target + ")" : ""));
var alts = targetUser.getAlts();
if (alts.length) {
this.addModCommand(""+targetUser.name+"'s alts were also banned from room " + room.id + ": "+alts.join(", "));
for (var i = 0; i < alts.length; ++i) {
var altId = toId(alts[i]);
this.add('|unlink|' + altId);
room.bannedUsers[altId] = true;
}
}
this.add('|unlink|' + targetUser.userid);
targetUser.leaveRoom(room.id);
},
roomunban: function(target, room, user, connection) {
if (!target) return this.parse('/help roomunban');
target = this.splitTarget(target, true);
var targetUser = this.targetUser;
var name = this.targetUsername;
var userid = toId(name);
if (!userid || !targetUser) return this.sendReply("User '"+name+"' does not exist.");
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]) delete room.bannedUsers[userid];
for (var ip in targetUser.ips) {
if (room.bannedIps[ip]) delete room.bannedIps[ip];
}
targetUser.popup(user.name+" has unbanned you from the room " + room.id + ".");
this.addModCommand(""+targetUser.name+" was unbanned from room " + room.id + " by "+user.name+".");
var alts = targetUser.getAlts();
if (alts.length) {
this.addModCommand(""+targetUser.name+"'s alts were also unbanned from room " + room.id + ": "+alts.join(", "));
for (var i = 0; i < alts.length; ++i) {
var altId = toId(alts[i]);
if (room.bannedUsers[altId]) delete room.bannedUsers[altId];
}
}
},
roomauth: function(target, room, user, connection) {
if (!room.auth) return this.sendReply("/roomauth - This room isn't designed for per-room moderation and therefore has no auth list.");
var buffer = [];
for (var u in room.auth) {
buffer.push(room.auth[u] + u);
}
if (buffer.length > 0) {
buffer = buffer.join(', ');
} else {
buffer = 'This room has no auth.';
}
connection.popup(buffer);
},
leave: 'part',
part: function(target, room, user, connection) {
if (room.id === 'global') return false;
var targetRoom = Rooms.get(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');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser || !targetUser.connected) {
return this.sendReply('User '+this.targetUsername+' not found.');
}
if (room.isPrivate && room.auth) {
return this.sendReply('You can\'t warn here: This is a privately-owned room not subject to global rules.');
}
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|' + targetUser.userid);
},
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.get(target) || Rooms.get(toId(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 (Rooms.rooms[targetRoom.id].users[targetUser.userid]) {
return this.sendReply("User " + targetUser.name + " is already in the room " + target + "!");
}
if (!Rooms.rooms[room.id].users[targetUser.userid]) {
return this.sendReply('User '+this.targetUsername+' is not in the room ' + room.id + '.');
}
if (targetUser.joinRoom(target) === false) return this.sendReply('User "' + targetUser.name + '" could not be joined to room ' + target + '. They could be banned from the room.');
var roomName = (targetRoom.isPrivate)? 'a private room' : 'room ' + targetRoom.title;
this.addModCommand(targetUser.name + ' was redirected to ' + roomName + ' by ' + user.name + '.');
targetUser.leaveRoom(room);
},
m: 'mute',
mute: function(target, room, user) {
if (!target) return this.parse('/help mute');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) {
return this.sendReply('User '+this.targetUsername+' not found.');
}
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply('The reason is too long. It cannot exceed ' + MAX_REASON_LENGTH + ' characters.');
}
if (!this.can('mute', targetUser, room)) return false;
if (targetUser.mutedRooms[room.id] || 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 + ")" : ""));
}
targetUser.popup(user.name+' has muted you for 7 minutes. '+target);
this.addModCommand(''+targetUser.name+' was muted by '+user.name+' for 7 minutes.' + (target ? " (" + target + ")" : ""));
var alts = targetUser.getAlts();
if (alts.length) this.addModCommand(""+targetUser.name+"'s alts were also muted: "+alts.join(", "));
this.add('|unlink|' + targetUser.userid);
targetUser.mute(room.id, 7*60*1000);
},
hm: 'hourmute',
hourmute: function(target, room, user) {
if (!target) return this.parse('/help hourmute');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) {
return this.sendReply('User '+this.targetUsername+' not found.');
}
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply('The reason is too long. It cannot exceed ' + MAX_REASON_LENGTH + ' characters.');
}
if (!this.can('mute', targetUser, room)) return false;
if (((targetUser.mutedRooms[room.id] && (targetUser.muteDuration[room.id]||0) >= 50*60*1000) || targetUser.locked) && !target) {
var problem = ' but was already '+(!targetUser.connected ? 'offline' : targetUser.locked ? 'locked' : 'muted');
return this.privateModCommand('('+targetUser.name+' would be muted by '+user.name+problem+'.)');
}
targetUser.popup(user.name+' has muted you for 60 minutes. '+target);
this.addModCommand(''+targetUser.name+' was muted by '+user.name+' for 60 minutes.' + (target ? " (" + target + ")" : ""));
var alts = targetUser.getAlts();
if (alts.length) this.addModCommand(""+targetUser.name+"'s alts were also muted: "+alts.join(", "));
this.add('|unlink|' + targetUser.userid);
targetUser.mute(room.id, 60*60*1000, true);
},
um: 'unmute',
unmute: function(target, room, user) {
if (!target) return this.parse('/help unmute');
var targetUser = Users.get(target);
if (!targetUser) {
return this.sendReply('User '+target+' not found.');
}
if (!this.can('mute', targetUser, room)) return false;
if (!targetUser.mutedRooms[room.id]) {
return this.sendReply(''+targetUser.name+' isn\'t muted.');
}
this.addModCommand(''+targetUser.name+' was unmuted by '+user.name+'.');
targetUser.unmute(room.id);
},
l: 'lock',
ipmute: 'lock',
lock: function(target, room, user) {
if (!target) return this.parse('/help lock');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) {
return this.sendReply('User '+this.targetUser+' not found.');
}
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply('The reason is too long. It cannot exceed ' + MAX_REASON_LENGTH + ' characters.');
}
if (!user.can('lock', targetUser)) {
return this.sendReply('/lock - Access denied.');
}
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+'.)');
}
targetUser.popup(user.name+' has locked you from talking in chats, battles, and PMing regular users.\n\n'+target+'\n\nIf you feel that your lock was unjustified, you can still PM staff members (%, @, &, and ~) to discuss it.');
this.addModCommand(""+targetUser.name+" was locked from talking by "+user.name+"." + (target ? " (" + target + ")" : ""));
var alts = targetUser.getAlts();
if (alts.length) this.addModCommand(""+targetUser.name+"'s alts were also locked: "+alts.join(", "));
this.add('|unlink|' + targetUser.userid);
targetUser.lock();
},
unlock: function(target, room, user) {
if (!target) return this.parse('/help unlock');
if (!this.can('lock')) return false;
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 + '.');
} else {
this.sendReply('User '+target+' is not locked.');
}
},
b: 'ban',
ban: function(target, room, user) {
if (!target) return this.parse('/help ban');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) {
return this.sendReply('User '+this.targetUsername+' not found.');
}
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+'.)');
}
targetUser.popup(user.name+" has banned you." + (config.appealurl ? (" If you feel that your banning was unjustified you can appeal the ban:\n" + config.appealurl) : "") + "\n\n"+target);
this.addModCommand(""+targetUser.name+" was banned by "+user.name+"." + (target ? " (" + target + ")" : ""), ' ('+targetUser.latestIp+')');
var alts = targetUser.getAlts();
if (alts.length) {
this.addModCommand(""+targetUser.name+"'s alts were also banned: "+alts.join(", "));
for (var i = 0; i < alts.length; ++i) {
this.add('|unlink|' + toId(alts[i]));
}
}
this.add('|unlink|' + targetUser.userid);
targetUser.ban();
},
unban: function(target, room, user) {
if (!target) return this.parse('/help unban');
if (!user.can('ban')) {
return this.sendReply('/unban - Access denied.');
}
var name = Users.unban(target);
if (name) {
this.addModCommand(''+name+' was unbanned by '+user.name+'.');
} else {
this.sendReply('User '+target+' is not banned.');
}
},
unbanall: function(target, room, user) {
if (!user.can('ban')) {
return this.sendReply('/unbanall - Access denied.');
}
// we have to do this the hard way since it's no longer a global
for (var i in Users.bannedIps) {
delete Users.bannedIps[i];
}
for (var i in Users.lockedIps) {
delete Users.lockedIps[i];
}
this.addModCommand('All bans and locks have been lifted by '+user.name+'.');
},
banip: function(target, room, user) {
target = target.trim();
if (!target) {
return this.parse('/help banip');
}
if (!this.can('rangeban')) return false;
Users.bannedIps[target] = '#ipban';
this.addModCommand(user.name+' temporarily banned the '+(target.charAt(target.length-1)==='*'?'IP range':'IP')+': '+target);
},
unbanip: function(target, room, user) {
target = target.trim();
if (!target) {
return this.parse('/help unbanip');
}
if (!this.can('rangeban')) return false;
if (!Users.bannedIps[target]) {
return this.sendReply(''+target+' is not a banned IP or IP range.');
}
delete Users.bannedIps[target];
this.addModCommand(user.name+' unbanned the '+(target.charAt(target.length-1)==='*'?'IP range':'IP')+': '+target);
},
/*********************************************************
* Moderating: Other
*********************************************************/
modnote: function(target, room, user, connection, cmd) {
if (!target) return this.parse('/help note');
if (target.length > MAX_REASON_LENGTH) {
return this.sendReply('The note is too long. It cannot exceed ' + MAX_REASON_LENGTH + ' characters.');
}
if (!this.can('mute')) return false;
return this.privateModCommand('(' + user.name + ' notes: ' + target + ')');
},
demote: 'promote',
promote: function(target, room, user, connection, cmd) {
if (!target) return this.parse('/help promote');
var target = this.splitTarget(target, true);
var targetUser = this.targetUser;
var userid = toUserid(this.targetUsername);
var name = targetUser ? targetUser.name : this.targetUsername;
if (!userid) {
if (target && config.groups[target]) {
var groupid = config.groups[target].id;
return this.sendReply("/"+groupid+" [username] - Promote a user to "+groupid+" globally");
}
return this.parse("/help promote");
}
var currentGroup = ' ';
if (targetUser) {
currentGroup = targetUser.group;
} else if (Users.usergroups[userid]) {
currentGroup = Users.usergroups[userid].substr(0,1);
}
var nextGroup = target ? target : Users.getNextGroupSymbol(currentGroup, cmd === 'demote', true);
if (target === 'deauth') nextGroup = config.groupsranking[0];
if (!config.groups[nextGroup]) {
return this.sendReply('Group \'' + nextGroup + '\' does not exist.');
}
if (config.groups[nextGroup].roomonly) {
return this.sendReply('Group \'' + config.groups[nextGroup].id + '\' does not exist as a global rank.');
}
if (!user.canPromote(currentGroup, nextGroup)) {
return this.sendReply('/' + cmd + ' - Access denied.');
}
var isDemotion = (config.groups[nextGroup].rank < config.groups[currentGroup].rank);
if (!Users.setOfflineGroup(name, nextGroup)) {
return this.sendReply('/promote - WARNING: This user is offline and could be unregistered. Use /forcepromote if you\'re sure you want to risk it.');
}
var groupName = (config.groups[nextGroup].name || nextGroup || '').trim() || 'a regular user';
if (isDemotion) {
this.privateModCommand('('+name+' was demoted to ' + groupName + ' by '+user.name+'.)');
if (targetUser) {
targetUser.popup('You were demoted to ' + groupName + ' by ' + user.name + '.');
}
} else {
this.addModCommand(''+name+' was promoted to ' + groupName + ' by '+user.name+'.');
}
if (targetUser) {
targetUser.updateIdentity();
}
},
forcepromote: function(target, room, user) {
// warning: never document this command in /help
if (!this.can('forcepromote')) return false;
var target = this.splitTarget(target, true);
var name = this.targetUsername;
var nextGroup = target ? target : Users.getNextGroupSymbol(' ', false);
if (!Users.setOfflineGroup(name, nextGroup, true)) {
return this.sendReply('/forcepromote - Don\'t forcepromote unless you have to.');
}
var groupName = config.groups[nextGroup].name || nextGroup || '';
this.addModCommand(''+name+' was promoted to ' + (groupName.trim()) + ' by '+user.name+'.');
},
deauth: function(target, room, user) {
return this.parse('/demote '+target+', deauth');
},
modchat: function(target, room, user) {
if (!target) {
return this.sendReply('Moderated chat is currently set to: '+room.modchat);
}
if (!this.can('modchat', null, room)) return false;
if (room.modchat && room.modchat.length <= 1 && config.groupsranking.indexOf(room.modchat) > 1 && !user.can('modchatall', null, room)) {
return this.sendReply('/modchat - Access denied for removing a setting higher than ' + config.groupsranking[1] + '.');
}
target = target.toLowerCase();
switch (target) {
case 'on':
case 'true':
case 'yes':
case 'registered':
this.sendReply("Modchat registered is no longer available.");
return false;
break;
case 'off':
case 'false':
case 'no':
room.modchat = false;
break;
case 'ac':
case 'autoconfirmed':
room.modchat = 'autoconfirmed';
break;
case '*':
case 'player':
target = '\u2605';
// fallthrough
default:
if (!config.groups[target]) {
return this.parse('/help modchat');
}
if (config.groupsranking.indexOf(target) > 1 && !user.can('modchatall', null, room)) {
return this.sendReply('/modchat - Access denied for setting higher than ' + config.groupsranking[1] + '.');
}
room.modchat = target;
break;
}
if (room.modchat === true) {
this.add('|raw|<div class="broadcast-red"><b>Moderated chat was enabled!</b><br />Only registered users can talk.</div>');
} else if (!room.modchat) {
this.add('|raw|<div class="broadcast-blue"><b>Moderated chat was disabled!</b><br />Anyone may talk now.</div>');
} else {
var modchat = sanitize(room.modchat);
this.add('|raw|<div class="broadcast-red"><b>Moderated chat was set to '+modchat+'!</b><br />Only users of rank '+modchat+' and higher can talk.</div>');
}
this.logModCommand(user.name+' set modchat to '+room.modchat);
if (room.chatRoomData) {
room.chatRoomData.modchat = room.modchat;
Rooms.global.writeChatRoomData();
}
},
declare: function(target, room, user) {
if (!target) return this.parse('/help declare');
if (!this.can('declare', null, room)) return false;
if (!this.canTalk()) return;
this.add('|raw|<div class="broadcast-blue"><b>'+target+'</b></div>');
this.logModCommand(user.name+' declared '+target);
},
gdeclare: 'globaldeclare',
globaldeclare: function(target, room, user) {
if (!target) return this.parse('/help globaldeclare');
if (!this.can('gdeclare')) return false;
for (var id in Rooms.rooms) {
if (id !== 'global') Rooms.rooms[id].addRaw('<div class="broadcast-blue"><b>'+target+'</b></div>');
}
this.logModCommand(user.name+' globally declared '+target);
},
cdeclare: 'chatdeclare',
chatdeclare: function(target, room, user) {
if (!target) return this.parse('/help chatdeclare');
if (!this.can('gdeclare')) return false;
for (var id in Rooms.rooms) {
if (id !== 'global') if (Rooms.rooms[id].type !== 'battle') Rooms.rooms[id].addRaw('<div class="broadcast-blue"><b>'+target+'</b></div>');
}
this.logModCommand(user.name+' globally declared (chat level) '+target);
},
wall: 'announce',
announce: function(target, room, user) {
if (!target) return this.parse('/help announce');
if (!this.can('announce', null, room)) return false;
target = this.canTalk(target);
if (!target) return;
return '/announce '+target;
},
fr: 'forcerename',
forcerename: function(target, room, user) {
if (!target) return this.parse('/help forcerename');
target = this.splitTarget(target);
var targetUser = this.targetUser;
if (!targetUser) {
return this.sendReply('User '+this.targetUsername+' not found.');
}
if (!this.can('forcerename', targetUser)) return false;
if (targetUser.userid === toUserid(this.targetUser)) {
var entry = ''+targetUser.name+' was forced to choose a new name by '+user.name+'' + (target ? ": " + target + "" : "");
this.privateModCommand('(' + entry + ')');
Rooms.global.cancelSearch(targetUser);
targetUser.resetName();
targetUser.send('|nametaken||'+user.name+" has forced you to change your name. "+target);
} else {
this.sendReply("User "+targetUser.name+" is no longer using that name.");
}
},
modlog: function(target, room, user, connection) {
var lines = 0;
// Specific case for modlog command. Room can be indicated with a comma, lines go after the comma.
// Otherwise, the text is defaulted to text search in current room's modlog.
var roomId = room.id;
var roomLogs = {};
if (target.indexOf(',') > -1) {
var targets = target.split(',');
target = targets[1].trim();
roomId = toId(targets[0]) || room.id;
}
// Let's check the number of lines to retrieve or if it's a word instead
if (!target.match('[^0-9]')) {
lines = parseInt(target || 15, 10);
if (lines > 100) lines = 100;
}
var wordSearch = (!lines || lines < 0);
// Control if we really, really want to check all modlogs for a word.
var roomNames = '';
var filename = '';
var command = '';
if (roomId === 'all' && wordSearch) {
if (!this.can('modlog')) return;
roomNames = 'all rooms';
// Get a list of all the rooms
var fileList = fs.readdirSync('logs/modlog');
for (var i=0; i<fileList.length; i++) {
filename += 'logs/modlog/' + fileList[i] + ' ';
}
} else {
if (!this.can('modlog', null, Rooms.get(roomId))) return;
roomNames = 'the room ' + roomId;
filename = 'logs/modlog/modlog_' + roomId + '.txt';
}
// Seek for all input rooms for the lines or text
command = 'tail -' + lines + ' ' + filename;
var grepLimit = 100;
if (wordSearch) { // searching for a word instead
if (target.match(/^["'].+["']$/)) target = target.substring(1,target.length-1);
command = "awk '{print NR,$0}' " + filename + " | sort -nr | cut -d' ' -f2- | grep -m"+grepLimit+" -i '"+target.replace(/\\/g,'\\\\\\\\').replace(/["'`]/g,'\'\\$&\'').replace(/[\{\}\[\]\(\)\$\^\.\?\+\-\*]/g,'[$&]')+"'";
}
// Execute the file search to see modlog
require('child_process').exec(command, function(error, stdout, stderr) {
if (error && stderr) {