-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrewBot.js
More file actions
1883 lines (1669 loc) · 110 KB
/
crewBot.js
File metadata and controls
1883 lines (1669 loc) · 110 KB
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
/* COPYRIGHT KALEB WASMUTH, 2017. ALL RIGHTS RESERVED.
ORIGINALLY DESIGNED FOR USE BY THE LIFEBOAT NETWORK ™
*/
// Global Variables
// Root Panel. Enable/Disable commands here.
// Default User Commands
const testEn = true;
const helpEn = true;
const menuEn = true;
const getPermEn = true;
const startEn = true;
const adminsEn = true;
// Moderator Admin Commands
const addModeratorEn = true;
const addTraineeEn = true;
// Builder Admin Commands
const addBuilderEn = true;
// Artist Admin Commands
const addArtistEn = true;
// Multi-Admin Commands
const addSrModeratorEn = true;
const editMemberEn = true;
const addRoleEn = true;
const delRoleEn = true;
const viewMemberEn = true;
const addNoteEn = true;
const editNoteEn = true;
const delNoteEn = true;
const getDirectoryEn = true;
const getTraineesEn = true;
const searchEn = true;
const renameEn = true;
// Global Admin Commands
const setPermEn = true;
const delPermEn = true;
const delMemberEn = true;
const getLogsEn = true;
const addBlackIPEn = true;
const searchLogsEn = true;
// Constants
const versionNumber = '1.5.3';
const versionMsg = 'Patched a bug with roles that come before Builder role';
const logMaxCount = 100;
const doDelOldLogs = false;
const keepDeletedProfiles = true;
const logCommands = true;
// This permission can only be hard-coded.
const globalAdminPerm = ['kaleb', 'luke_hoffman', 'jiselleangeles', 'ciamouse', 'brandonvalencia'];
// Global Object Constructors
// New Note
function Note(text, sender, dateSent, isHidden, ID){
this.text = text;
this.sender = sender;
this.dateSent = dateSent;
this.isHidden = isHidden;
this.ID = ID;
}
// New Member
function Member(name, IGN, IP, adder, dateAdded, lastUpdated, allNotes, publicNotes, noteNumber, role, username, logs){
this.public = {
name: name,
IGN: IGN,
adder: adder,
dateAdded: dateAdded,
publicNotes: publicNotes
};
this.private = {
IP: IP,
allNotes: allNotes
};
this.backend = {
lastUpdated: lastUpdated,
noteNumber: noteNumber,
role: role,
username: username,
logs: logs
};
}
// Global Functions
// Get Current Date
function getDate(dateObj){
var dateUpdated = (dateObj.getMonth() + 1) + '/' + (dateObj.getDate()) + '/' + (dateObj.getFullYear());
return dateUpdated;
}
// Get Current Full Date
function getFullDate(dateObj){
if(dateObj.getMinutes() < 10){
var minutes = '0' + (dateObj.getMinutes()).toString();
}else{
var minutes = (dateObj.getMinutes()).toString();
}
var dateUpdated = (dateObj.getMonth() + 1) + '/' + (dateObj.getDate()) + '/' + (dateObj.getFullYear()) + ' ' + (dateObj.getHours() + 1) + ':' + minutes;
return dateUpdated;
}
// Check if a value exists in an array, and return an array with true/false and the index (null if false)
function isInArray(value, array){
var isInThis = false;
for(var x in array){
if(value === array[x]){
isInThis = true;
break;
}else{
// Do Nothing
}
}
if(isInThis){
var returnedIndexOfValue = array.indexOf(value);
}else{
var returnedIndexOfValue = null;
}
return [isInThis, returnedIndexOfValue];
}
// Get User's Permission, Returns Number 0-5
function getPermNode(user){
/*
PERMISSIONS:
0 :: Global Admin
1 :: Moderator Admin
2 :: Builder Admin
3 :: Artist Admin
4 :: Moderator
5 :: Default User
*/
// Global Admin Permission
if((isInArray(user, globalAdminPerm))[0]){
return 0;
}
// Moderator Admin Permission
else if((isInArray(user, context.simpledb.botleveldata.modAdminPerm))[0]){
return 1;
}
// Builder Admin Permission
else if((isInArray(user, context.simpledb.botleveldata.builderAdminPerm))[0]){
return 2;
}
// Artist Admin Permission
else if((isInArray(user, context.simpledb.botleveldata.artistAdminPerm))[0]){
return 3;
}
// Moderator Permission
else if((isInArray(user, context.simpledb.botleveldata.modPerm))[0]){
return 4;
}
// Default User Permission
else{
return 5;
}
}
// Gets user's permission node in words.
function getLetterNode(userPerm){
switch(userPerm){
case 0: // Global Admin
var permInLetters = 'Global Admin';
break;
case 1: // Moderator Admin
var permInLetters = 'Moderator Admin';
break;
case 2: // Builder Admin
var permInLetters = 'Builder Admin';
break;
case 3: // Artist Admin
var permInLetters = 'Artist Admin';
break;
case 4: // Moderator
var permInLetters = 'Moderator';
break;
default: // Default User
var permInLetters = 'Default User';
}
return permInLetters;
}
// Get User's perm in literal form
function getLiteralPerm(userPerm){
switch(userPerm){
case 0: // Global Admin
var literalPerm = 'globalAdminPerm';
break;
case 1: // Moderator Admin
var literalPerm = 'modAdminPerm';
break;
case 2: // Builder Admin
var literalPerm = 'builderAdminPerm';
break;
case 3: // Artist Admin
var literalPerm = 'artistAdminPerm';
break;
case 4: // Moderator
var literalPerm = 'modPerm';
break;
default: // Default User
var literalPerm = 'defaultUser';
}
return literalPerm;
}
// Send Permission Error
function permError(userPerm){
var permWords = getLetterNode(userPerm);
context.sendResponse(':warning: Error: Incorrect Permissions. Your permission node is *' + userPerm + ' (' + permWords + ')*. Please contact KaIeb if you think this is in error.');
}
// Send Disabled Command Error
function enError(){
context.sendResponse(':warning: Error: This command has been disabled.');
}
// Add Log
function addLog(event/*BECAUSE EVENT IS NOT YET DEFINED*/, sender, text, timeSent){
var logList = context.simpledb.botleveldata.logs;
logList.unshift('*' + sender + ' at ' + timeSent + ':* ' + text);
context.simpledb.botleveldata.logs = logList;
return true;
}
// Delete Last Log
function delLastLog(event/*BECAUSE EVENT IS NOT YET DEFINED*/){
// IF MORE THAN MAX COUNT LOGS
if(context.simpledb.botleveldata.logs.length > logMaxCount){
var logList = context.simpledb.botleveldata.logs;
logList.length = logMaxCount; // Remove logs after max count length
context.simpledb.botleveldata.logs = logList;
return true;
}else{
// Do Nothing
return false;
}
}
// Update Log List
function updateLogs(event/*BECAUSE EVENT IS NOT YET DEFINED*/){
if(logCommands){
addLog(event, event.senderobj.subdisplay, event.message, getFullDate(new Date()));
if(doDelOldLogs){
delLastLog(event);
}
}
return true;
}
// Loop Through Command To Return Parsed Value And Return Last Known Conditional Text Index
function parseCommand(thingToParse, startingNum, conditionalNum, defaultReturn, conditionalText){
var makeListVar = defaultReturn;
var i = startingNum;
for(; i < conditionalNum; i++){
if(thingToParse[i] !== conditionalText){
makeListVar = makeListVar + thingToParse[i];
}else{
break;
}
}
return [makeListVar, i];
}
// Return all permission nodes a user is in (should just be one unless a bug occured or we are checking roles of a profile)
function getAllNodes(user){
var allNodes = [];
var isGlobalAdmin = false;
var isModAdmin = false;
var isBuilderAdmin = false;
var isArtistAdmin = false;
var isModerator = false;
var isDefaultUser = false;
if((isInArray(user, globalAdminPerm))[0]){
var isGlobalAdmin = true;
allNodes.push('Global Admin');
}
if((isInArray(user, context.simpledb.botleveldata.modAdminPerm))[0]){
var isModAdmin = true;
allNodes.push('Moderator Admin');
}
if((isInArray(user, context.simpledb.botleveldata.builderAdminPerm))[0]){
var isBuilderAdmin = true;
allNodes.push('Builder Admin');
}
if((isInArray(user, context.simpledb.botleveldata.artistAdminPerm))[0]){
var isArtistAdmin = true;
allNodes.push('Artist Admin');
}
if((isInArray(user, context.simpledb.botleveldata.modPerm))[0]){
var isModerator = true;
allNodes.push('Moderator');
}
if((!isGlobalAdmin) && (!isModAdmin) && (!isBuilderAdmin) && (!isArtistAdmin) && (!isModerator)){
var isDefaultUser = true;
allNodes.push('Default User');
}
return allNodes;
}
function updateCounts(resultOfPermCheck){
switch(resultOfPermCheck){
case 0:
context.simpledb.botleveldata.timesused++;
context.simpledb.botleveldata.timesadminused++;
break;
case 1:
context.simpledb.botleveldata.timesused++;
context.simpledb.botleveldata.timesmodadminused++;
break;
case 2:
context.simpledb.botleveldata.timesused++;
context.simpledb.botleveldata.timesbuilderadminused++;
break;
case 3:
context.simpledb.botleveldata.timesused++;
context.simpledb.botleveldata.timesartistadminused++;
break;
case 4:
context.simpledb.botleveldata.timesused++;
context.simpledb.botleveldata.timesmodused++;
break;
default:
context.simpledb.botleveldata.timesused++;
context.simpledb.botleveldata.timestraineeused++;
break;
}
}
// Returns true if sender can edit the target's profile
function canEdit(senderPerm, target){
var targetPerm = getPermNode(target);
var targetObj = context.simpledb.botleveldata.members[target];
if(senderPerm !== 0){
if((isInArray('Moderator', targetObj.backend.role))[0]){
if(senderPerm === 1 || senderPerm === 0){
return true;
}
}
if((isInArray('Trainee', targetObj.backend.role))[0]){
if(senderPerm === 1 || senderPerm === 0){
return true;
}
}
if((isInArray('Builder', targetObj.backend.role))[0]){
if(senderPerm === 2 || senderPerm === 0){
return true;
}
}
if((isInArray('Artist', targetObj.backend.role))[0]){
if(senderPerm === 3 || senderPerm === 0){
return true;
}
}
}else{
return true;
}
}
function presentArray(array){
var makeListVar = '';
for(var x in array){
if(x !== 0){
makeListVar = makeListVar + '\n>' + array[x];
}else{
makeListVar = makeListVar + array[x];
}
}
return makeListVar;
}
function getSrModerators(){
var makeListVar = [];
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
if((isInArray('Senior Moderator', abc.backend.role))[0]){
makeListVar.push(abc.backend.username);
}
}
return makeListVar;
}
function getModerators(){
var makeListVar = [];
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
if((isInArray('Moderator', abc.backend.role))[0]){
makeListVar.push(abc.backend.username);
}
}
return makeListVar;
}
function getTrainees(){
var makeListVar = [];
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
if((isInArray('Trainee', abc.backend.role))[0]){
makeListVar.push(abc.backend.username);
}
}
return makeListVar;
}
function getBuilders(){
var makeListVar = [];
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
if((isInArray('Builder', abc.backend.role))[0]){
makeListVar.push(abc.backend.username);
}
}
return makeListVar;
}
function getArtists(){
var makeListVar = [];
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
if((isInArray('Artist', abc.backend.role))[0]){
makeListVar.push(abc.backend.username);
}
}
return makeListVar;
}
function searchField(field, value, resultOfPermCheck /*BECAUSE RESULTOFPERMCHECK IS NOT YET DEFINED*/){
var makeListVar = [];
if(field === 'IP'){
// Search private
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
var newDef = abc.private.IP.toLowerCase();
if(newDef.includes(value.toLowerCase())){
if(canEdit(resultOfPermCheck, abc.backend.username)){
makeListVar.push('*' + abc.backend.username + '*' + '\n>*Value:* ' + abc.private.IP);
}
}
}
return makeListVar;
}
else if(field === 'name' || field === 'IGN'){
// Search public
for(var x in context.simpledb.botleveldata.members){
var abc = context.simpledb.botleveldata.members[x];
var def = abc.public[field];
newDef = def.toLowerCase();
if(newDef.includes(value.toLowerCase())){
makeListVar.push('*' + abc.backend.username + '*' + '\n>*Value:* ' + def);
}
}
return makeListVar;
}else{
context.sendResponse(':warning: Error: Please specify a valid subcommand (name, IGN, IP).');
return null;
}
}
function getIPAlert(userObj){
var blackIPList = context.simpledb.botleveldata.blackIPs;
var queuedIP = userObj.private.IP;
var isBlackIP = false;
for(var x in blackIPList){
if(queuedIP === blackIPList[x]){
var isBlackIP = true;
break;
}
}
if(isBlackIP){
return '\n\n\n\n*Warning: The IP of this member matches a known blacklisted IP. Please be cautious of this user.*';
}else{
return '';
}
}
function MessageHandler(context, event) {
const resultOfPermCheck = getPermNode(event.senderobj.subdisplay);
if(event.message !== undefined){
if(event.message[0] === '$'){
if(event.message === '$test' || event.message === '$$'){
if(testEn){
updateLogs(event);
context.sendResponse('Test successful! Message handler is responsive!\n\n*Times Used:* ' + context.simpledb.botleveldata.timesused + '\n*Times Global Admin Used:* ' + context.simpledb.botleveldata.timesadminused + '\n*Times Moderator Admin Used:* ' + context.simpledb.botleveldata.timesmodadminused + '\n*Times Builder Admin Used:* ' + context.simpledb.botleveldata.timesbuilderadminused + '\n*Times Moderator Used:* ' + context.simpledb.botleveldata.timesmodused + '\n*Times Default User Used:* ' + context.simpledb.botleveldata.timestraineeused + '\n\n*Current Version:* ' + versionNumber + ' (' + versionMsg + ')' + '\n\nThis bot was created and published by <@U1JT6HNE5>. Contact him for any questions or concerns you may have.');
}else{
enError();
}
}
// --------------------
else if(event.message === '$help'){
if(helpEn){
updateLogs(event);
updateCounts(resultOfPermCheck);
context.sendResponse('Hello, ' + event.senderobj.display + '. Glad I could help. My name is Crew Bot. My job is to help you learn more about the Lifeboat crew. To get started, send me `$menu`.\n*This bot was created by <@U1JT6HNE5>.*');
}else{
enError();
}
}
// --------------------
else if(event.message === '$menu'){
if(menuEn){
updateLogs(event);
updateCounts(resultOfPermCheck);
const defaultUserPermList = 'Test Bot : : `$test`\nHelp Message : : `$help`\nMain Menu : : `$menu`\nGet Started : : `$start`\nView Admins : : `$admins`\n\nGet Permissions : : `$getPerm`';
const moderatorPermList = 'Test Bot : : `$test`\nHelp Message : : `$help`\nMain Menu : : `$menu`\nGet Started : : `$start`\nView Admins : : `$admins`\n\nGet Permissions : : `$getPerm`\n\nGet Directory : : `$getDirectory`\nGet Trainees : : `$getTrainees`\nSearch Directory : : `$search`\nView Profile : : `$viewMember`';
const artistAdminPermList = 'Test Bot : : `$test`\nHelp Message : : `$help`\nMain Menu : : `$menu`\nGet Started : : `$start`\nView Admins : : `$admins`\n\nGet Permissions : : `$getPerm`\n\nAdd Artist : : `$addArtist`\nEdit Member : : `$editMember`\nRename Member : : `$rename`\nGet Directory : : `$getDirectory`\nGet Trainees : : `$getTrainees`\nSearch Directory : : `$search`\nView Profile : : `$viewMember`\n\nAdd Role : : `$addRole`\nDelete Role : : `$delRole`\n\nAdd Note : : `$addNote`\nEdit Note : : `$editNote`\nDelete Note : : `$delNote`';
const builderAdminPermList = 'Test Bot : : `$test`\nHelp Message : : `$help`\nMain Menu : : `$menu`\nGet Started : : `$start`\nView Admins : : `$admins`\n\nGet Permissions : : `$getPerm`\n\nAdd Builder : : `$addBuilder`\nEdit Member : : `$editMember`\nRename Member : : `$rename`\nGet Directory : : `$getDirectory`\nGet Trainees : : `$getTrainees`\nSearch Directory : : `$search`\nView Profile : : `$viewMember`\n\nAdd Role : : `$addRole`\nDelete Role : : `$delRole`\n\nAdd Note : : `$addNote`\nEdit Note : : `$editNote`\nDelete Note : : `$delNote`';
const modAdminPermList = 'Test Bot : : `$test`\nHelp Message : : `$help`\nMain Menu : : `$menu`\nGet Started : : `$start`\nView Admins : : `$admins`\n\nGet Permissions : : `$getPerm`\n\nAdd Moderator : : `$addModerator`\nAdd Trainee : : `$addTrainee`\nGet Directory : : `$getDirectory`\nGet Trainees : : `$getTrainees`\nEdit Member : : `$editMember`\nRename Member : : `$rename`\nSearch Directory : : `$search`\nView Profile : : `$viewMember`\n\nAdd Note : : `$addNote`\nEdit Note : : `$editNote`\nDelete Note : : `$delNote`\n\nAdd Role : : `$addRole`\nDelete Role : : `$delRole`';
const globalAdminPermList = 'Test Bot : : `$test`\nHelp Message : : `$help`\nMain Menu : : `$menu`\nGet Started : : `$start`\nView Admins : : `$admins`\n\nGet Permissions : : `$getPerm`\nAdd Permissions : : `$setPerm`\nDelete Permissions : : `$delPerm`\n\nAdd Senior Moderator : : `$addSrModerator`\nAdd Moderator : : `$addModerator`\nAdd Trainee : : `$addTrainee`\nAdd Builder : : `$addBuilder`\nEdit Member : : `$editMember`\nRename Member : : `$rename`\nGet Directory : : `$getDirectory`\nGet Trainees : : `$getTrainees`\nSearch Directory : : `$search`\nView Profile : : `$viewMember`\n\nAdd Role : : `$addRole`\nDelete Role : : `$delRole`\n\nAdd Note : : `$addNote`\nEdit Note : : `$editNote`\nDelete Note : : `$delNote`\n\nGet Logs : : `$getLogs`\nSearch Logs : : `$findLogs`\n\nAdd Blacklisted IP : : `$addBlackIP`';
// Send commands that are related to permissionNode
switch(resultOfPermCheck){
case 0: // Global Admin
context.sendResponse(globalAdminPermList);
break;
case 1: // Moderator Admin
context.sendResponse(modAdminPermList);
break;
case 2: // Builder Admin
context.sendResponse(builderAdminPermList);
break;
case 3: // Artist Admin
context.sendResponse(artistAdminPermList);
break;
case 4: // Moderator
context.sendResponse(moderatorPermList);
break;
default: // Default User (5)
context.sendResponse(defaultUserPermList)
break;
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 8) === '$getPerm'){
if(getPermEn){
if(event.message === '$getPerm'){
updateLogs(event);
updateCounts(resultOfPermCheck);
context.sendResponse('*Permission node for ' + event.senderobj.subdisplay + ':* ' + resultOfPermCheck + ' (' + getLetterNode(resultOfPermCheck) + ')');
}
if(event.message[8] === ' ' && event.message[9] === '"'){
// Check that user isn't default user.
if(resultOfPermCheck < 5){
updateLogs(event);
updateCounts(resultOfPermCheck);
var firstParse = parseCommand(event.message, 10, event.message.length, '', '"');
var firstArg = firstParse[0];
if(event.message[event.message.length - 1] === '"'){
context.sendResponse('*Permission node for ' + firstArg + ':* ' + getPermNode(firstArg) + ' (' + getLetterNode(getPermNode(firstArg)) + ')');
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$getPerm`\n*OR*\n`$getPerm "username"`');
}
}else{
permError(resultOfPermCheck);
}
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 6) === '$start'){
if(startEn){
updateLogs(event);
updateCounts(resultOfPermCheck);
if(event.message === '$start'){
context.sendResponse('Please specify a tag, -t for trainee and -b for builder. Example: `$start -t`');
}else{
if(event.message === '$start -t'){
context.sendResponse('Hey there! I would like to welcome you to a program that you will be involved in for the next 1-3 weeks of your Lifeboat experience. Here at Lifeboat, we strive to provide the best server experience possible. We have a player base of 29 million accounts, ranging from very young children to adults and parents. We have over 100 different servers, and over 10 gamemodes to choose from. We are the largest *Minecraft: Pocket Edition* server community, and have been the largest Minecraft network community above all Minecraft servers, PE and PC. Of course, with this huge player fanbase, there comes a huge responsibility. Part of that responsibility is making sure our players are enjoying their time on our servers, and aren\'t experiencing problems. Thus we introduced moderators to our servers.\n\nSomething we must be exceptionally clear on: Moderators do *NOT* exist to boss players around. They do not exist to tell players what to do. They do not exist to make a Lifeboat player\'s experience miserable. They are our line of defense against players who refuse to follow rules. Another thing we try to tell our moderators often is that we must *always* warn with correction before punishment. What good is punishing a player if they don\'t learn anything? We strive to verbally warn and correct a player when they are breaking our rules, so that they learn from their mistakes. Moderator tools are only necessary when a player defies a moderator\'s request to play by the rules of our servers. Then, and only then, are we to use the necessary force, and only in incremental amounts, usually starting with a mute, then working the way up to a 10 minute ban, and so on, if the player refuses to obey after the mute. However, a moderator should never be afraid to use his or her tools at their disposal. If a player continously disobeys correction, we must act according to the severity of the punishment. There are two exceptions to this rule: Hacking and inappropriate names. If you encounter a hacker or a user with a swear word in his name, please ban him for a full day (/lbban <player> 1440), and report him on Redmine.\n\nHere\'s a checklist for you to use, please make sure you complete all of these things before you move on:\n\n- Sign the volunteer agreement form.\n- Have the crew tag added to your Lifeboat account.\n- Have an admin set up a Redmine account for you.\n\n*If you need help with any of the above things, please talk to an administrator. You can see all admins by sending `$admins`.*\n\nHere are the moderator tools you\'ll be working with once you become a full moderator. *Please note:* Trainees do *NOT* have access to these tools; they are here for you to learn them and know how to use them for when you graduate.\n\n`/lbban` - Used to ban a player. Maximum ban time is 1440 minutes (1 day). Usage: `/lbban <player> <time in minutes> <reason>`\n\n`/lbmute` - Used to mute a player. Maximum mute time is 60 minutes. Usage: `/lbmute <player> <time in minutes> <reason>`\n\n`/lbskin` - Used to change the skin of a player to the Alex or Steve counterparts. Usage: `/lbskin <player> [reason]`\n\n`/lbwarn` - Sends a warning to a player. Warning sent: _This is an official warning: We have detected inappropriate behavior from you. Please refrain from breaking the rules, we don’t want to have to ban you!_ Usage: `/lbwarn <player>`\n\n`/lbkick` - Used to disconnect a player from the server. Usage: `/lbkick <player> <reason>`\n\n`/lbunban` Unbans a player. Usage: `/lbunban <player>`\n\n`/lbunmute` - Unmutes a player. Usage: `/lbunmute <player>`\n\n`/mod fly` - Toggles flying and invisibility. Usage: `/mod fly`\n\n`/move` - Teleports you to the specified player. Usage: `/move <player>`\n\n`/separate` - Bounces two players away from eachother and blocks their chat messages from eachother. Usage: `/separate <player1> <player2>`\n\n`/lbrod` - Gives you a rod, which, when used on a player, shows their true IGN. Usage: `/lbrod`\n\n`/lbstick` - Gives you a rod, which, when used on a player, asks you for a ban time, then bans the player the rod was used on for the specified time in chat. Usage: `/lbstick`\n\nPlease note that the only command you\'ll have when you\'re a trainee is `/d`, which hides your skin and name from others.\n\nTo report players in-game, please use Redmine (crew.lbsg.net). If you need help with reporting, let an administrator know.\n\nLast, but not least, have fun! We\'re glad to have you as part of the volunteer team here, and have high hopes for you. Feel free to watch this introductory greeting, if you wish. <Missing Link>');
}
else if(event.message === '$start -b'){
context.sendResponse('Hello, and welcome to the Lifeboat build team! Here at Lifeboat, we strive to provide the best server experience possible. We have a player base of 29 million accounts, ranging from very young children to adults and parents. We have over 100 different servers, and over 10 gamemodes to choose from. We are the largest *Minecraft: Pocket Edition* server community, and have been the largest Minecraft network community above all Minecraft servers, PE and PC. Of course, with this huge player fanbase, there comes a huge responsibility. Part of that responsibility is making sure our players get new and awesome maps to play on frequently. Thus we introduced the build team!\n\nLifeboat’s build team at its core is, well, a team! We work together with the common goal to create awesome environments for our players to experience. Even though there some may have one specific build style that they are good at, or one specific game they make maps for, we all work to improve both the network and our teammates. Creativity and the ability to build well are extremely important for members of the build team, however the ability to work with others is of utmost importance.\n\nWe put a lot of effort into giving our build team the tools to make their lives easier and create an environment where their creativity is not limited. We have both a PE map building server and a PC map building server. You as a builder are welcome to use either server to your liking. We also use Trello for project organization. It is both a web-based and app-based platform so feel free to download it on your phone or just go to https://trello.com.\n\nHere are the action points that you should follow after reading this message.\n\n- Sign the volunteer agreement form.\n- Have the “Map” tag added to your Lifeboat account.\n- Have a Lead Builder introduce you to Trello.\n\n*If you need help with any of the above things, please talk to an administrator. You can see all admins by sending `$admins`.*\n\nFinally, have fun! We are here to create awesome maps for our players to experience and it feels amazing getting to watch people play on your creations. We hope you enjoy it here! ');
}
/*else if(event.message === '$start -a'){
context.sendResponse('Hello! Welcome to the Lifeboat artists team. Here is a checklist for you to complete to get set up:\n\n- Sign the volunteer agreement form.\n- Have the crew tag added to your Lifeboat account.\n- Have an admin set up a Redmine (crew.lbsg.net) account for you.\n\nIf you have any trouble completing these things, feel free to ask an administrator for help. Send `$admins` to view the admins.');
}*/
else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$start`\n*OR*\n`$start <tag>`');
}
}
}else{
enError();
}
}
// --------------------
else if(event.message === '$admins'){
if(adminsEn){
updateLogs(event);
updateCounts(resultOfPermCheck);
context.sendResponse('Rein Teder (<@U1K133MFC>) - *President of Hydreon Corp.*\nBen Gryskiewicz (<@U3L62DW31>) - *Staff Manager*\nLuke Hoffman (<@U1EFX07SP>) - *Volunteer Leader*\nJiselle Angeles (<@U1JTSR0AK>) - *Volunteer Leader*\nKaleb Wasmuth (<@U1JT6HNE5>) - *Volunteer Leader*\nDave Diaz (<@U1JUW26US>) - *Volunteer Leader*\nBrandon Valencia (<@U1U1DA7V5>) - *Lead Moderator*\nSpencer Steiner (<@U1EH7HNF6>) - *Website Developer*\nJacob Gates (<@U1T9NN6LX>) - *Quality Assurance*\nRiley French (<@U4RDX13BM>) - *Quality Assurance*\nLuca Kermas (<@U31GN6CE9>) - *Software Developer*\nHenry Eason (<@U1SPW9BKJ>) - *Software Developer*\nAnthony Tagliaferri (<@U4317SEAK>) - *Build Coordinator*\nVraj Patel (<@U211PRWCC>) - *Video & Stream Leader*\nStephanie Rodriguez (<@U23SRASER>) - *Social Media Coordinator*\nJose Ruiz (<@U3Q06UMCN>) - *Social Media Coordinator*\nTrevor Rodriguez (<@U20TRH9G8>) - *Customer Support*\n\n*If you have any questions, feel free to DM any of these people.*');
}else{
enError();
}
}
// --------------------
// Multi-Admin Permissions
else if(event.message === '$getDirectory'){
if(getDirectoryEn){
if(resultOfPermCheck !== 5){
// Sender is not a default user
updateLogs(event);
updateCounts(resultOfPermCheck);
context.sendResponse('*Senior Moderators:*\n' + presentArray(getSrModerators().sort()) + '\n\n*Moderators:*\n' + presentArray(getModerators().sort()) + '\n\n*Trainees:*\n' + presentArray(getTrainees().sort()) + '\n\n*Builders:*\n' + presentArray(getBuilders().sort())/* + '\n\n*Artists:*\n' + presentArray(getArtists().sort())*/);
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message === '$getTrainees'){
if(getTraineesEn){
if(resultOfPermCheck !== 5){
// Sender is not a default user
updateLogs(event);
updateCounts(resultOfPermCheck);
context.sendResponse('*Trainees:*\n' + presentArray(getTrainees().sort()));
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 7) === '$search'){
if(searchEn){
if(resultOfPermCheck !== 5){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[7] === ' ' && event.message[8] === '"') && event.message[event.message.length - 1] === '"'){
var firstParse = parseCommand(event.message, 9, event.message.length, '', '"');
var firstArg = firstParse[0];
var LNC = firstParse[1];
if(event.message[LNC + 1] === ' ' && event.message[LNC + 2] === '"'){
var secondParse = parseCommand(event.message, LNC + 3, event.message.length, '', '"');
var secondArg = secondParse[0];
if(firstArg !== 'IP'){
// firstArg is IP
var returnedResultsOfSearch = searchField(firstArg, secondArg, resultOfPermCheck);
if(returnedResultsOfSearch !== null){
// firstArg is IP (we already knew this)
if(returnedResultsOfSearch.length !== 0){
context.sendResponse('Showing search results for *' + secondArg + '* in the field *' + firstArg + '*.\n\n' + returnedResultsOfSearch.join('\n\n'));
}else{
context.sendResponse('Showing search results for *' + secondArg + '* in the field *' + firstArg + '*.\n\n' + '>No Results');
}
}else{
context.sendResponse(':warning: Error: Please specify a valid field (name, IGN, IP).');
}
}else{
// firstArg is something other than IP (could be invalid)
var returnedResultsOfSearch = searchField(firstArg, secondArg, resultOfPermCheck);
if(returnedResultsOfSearch !== null){
// firstArg is name or IGN
if(returnedResultsOfSearch.length !== 0){
context.sendResponse('Showing search results for *' + secondArg + '* in the field *' + firstArg + '*.\n\n' + returnedResultsOfSearch.join('\n\n'));
}else{
context.sendResponse('Showing search results for *' + secondArg + '* in the field *' + firstArg + '*.\n\n' + '>No Results');
}
}else{
context.sendResponse(':warning: Error: Please specify a valid field (name, IGN, IP).');
}
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$search "field" "value"`');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$search "field" "value"`');
}
}else{
permError(returnedResultsOfSearch);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 8) === '$addRole'){
if(addRoleEn){
if(resultOfPermCheck !== 5){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[8] === ' ' && event.message[9] === '"') && event.message[event.message.length - 1] === '"'){
var firstParse = parseCommand(event.message, 10, event.message.length, '', '"');
var firstArg = firstParse[0];
var LNC = firstParse[1];
if(event.message[LNC + 1] === ' ' && event.message[LNC + 2] === '"'){
if(context.simpledb.botleveldata.members[firstArg] !== undefined){
var secondParse = parseCommand(event.message, LNC + 3, event.message.length, '', '"');
var secondArg = secondParse[0];
if(canEdit(resultOfPermCheck, firstArg)){
if(((secondArg === 'Senior Moderator' || secondArg === 'Moderator') || (secondArg === 'Trainee' || secondArg === 'Builder')) || secondArg === 'Artist'){
var targetObj = context.simpledb.botleveldata.members[firstArg];
if(!((isInArray(secondArg, targetObj.backend.role))[0])){
targetObj.backend.role.push(secondArg);
targetObj.backend.logs.push({oldValue: null, newValue: secondArg, editor: event.senderobj.subdisplay, dateEdited: getFullDate(new Date()), action: '$addRole'});
context.sendResponse('Added the role *' + secondArg + '* to the profile *' + firstArg + '*.');
}else{
context.sendResponse(':warning: Error: That profile already has the role *' + secondArg + '*.');
}
}else{
context.sendResponse(':warning: Error: Please use a valid role (Senior Moderator, Moderator, Trainee, Builder).');
}
}else{
context.sendResponse(':warning: Error: You cannot edit the role of this profile.');
}
}else{
context.sendResponse(':warning: Error: The profile *' + firstArg + '* does not exist.');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$addRole "username" "role"`');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$addRole "username" "role"`');
}
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 8) === '$delRole'){
if(delRoleEn){
if(resultOfPermCheck !== 5){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[8] === ' ' && event.message[9] === '"') && event.message[event.message.length - 1] === '"'){
var firstParse = parseCommand(event.message, 10, event.message.length, '', '"');
var firstArg = firstParse[0];
var LNC = firstParse[1];
if(event.message[LNC + 1] === ' ' && event.message[LNC + 2] === '"'){
var secondParse = parseCommand(event.message, LNC + 3, event.message.length, '', '"');
var secondArg = secondParse[0];
if(context.simpledb.botleveldata.members[firstArg] !== undefined){
if(canEdit(resultOfPermCheck, firstArg)){
var targetObj = context.simpledb.botleveldata.members[firstArg];
if((isInArray(secondArg, targetObj.backend.role))[0]){
targetObj.backend.role.splice(targetObj.backend.role.indexOf(secondArg), 1);
targetObj.backend.logs.push({oldValue: secondArg, newValue: null, editor: event.senderobj.subdisplay, dateEdited: getFullDate(new Date()), action: '$delRole'});
context.sendResponse('Removed role *' + secondArg + '* from the profile *' + firstArg + '*.');
}else{
context.sendResponse(':warning: Error: That profile does not have a role of *' + secondArg + '*.');
}
}else{
context.sendResponse(':warning: Error: You cannot edit the role of this profile.');
}
}else{
context.sendResponse(':warning: Error: The profile *' + firstArg + '* does not exist.');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$delRole "username" "role"`');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$delRole "username" "role"`');
}
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 15) === '$addSrModerator'){
if(addSrModeratorEn){
if(resultOfPermCheck === 0){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[15] === ' ' && event.message[16] === '"') && event.message[event.message.length - 1] === '"'){
var firstParse = parseCommand(event.message, 17, event.message.length, '', '"');
var firstArg = firstParse[0];
if(!((isInArray(firstArg, context.simpledb.botleveldata.allProfilesList))[0])){
// Profile does not exist, which is good
if(getPermNode(firstArg) === 1){
// Person to be added has mod admin perms
// Constructor Format: (name, IGN, IP, adder, dateAdded, lastUpdated, allNotes, publicNotes, noteNumber, role, username)
// Remove user from deleted profs if necessary
if(context.simpledb.botleveldata.deletedProfs[firstArg] !== undefined){
delete context.simpledb.botleveldata.deletedProfs[firstArg];
}
// Add name of profile to profile list
context.simpledb.botleveldata.allProfilesList.push(firstArg);
// Make profile
var newProfile = new Member('Unknown', 'Unknown', 'Unknown', event.senderobj.display, getDate(new Date()), getDate(new Date()), {}, {}, 1, ['Senior Moderator'], firstArg, []);
// Add profile
context.simpledb.botleveldata.members[firstArg] = newProfile;
context.sendResponse('Created the profile *' + firstArg + '*.');
}else{
context.sendResponse(':warning: Error: *' + firstArg + '* is a *' + getLetterNode(firstArg) + '*. Please use `$addModerator`, `$addTrainee`, or `$addBuilder` to add this profile.');
}
}else{
context.sendResponse(':warning: Error: The profile *' + firstArg + '* already exists.');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$addSrModerator "username"`');
}
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 13) === '$addModerator'){
if(addModeratorEn){
if(resultOfPermCheck === 0 || resultOfPermCheck === 1){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[13] === ' ' && event.message[14] === '"') && event.message[event.message.length - 1] === '"'){
// Command is valid and sender is allowed
var firstParse = parseCommand(event.message, 15, event.message.length, '', '"');
var firstArg = firstParse[0];
if(!((isInArray(firstArg, context.simpledb.botleveldata.allProfilesList))[0])){
// Profile does not exist, which is good
if(getPermNode(firstArg) === 5 || getPermNode(firstArg) === 4){
// Target is a default user or moderator
// Constructor Format: (name, IGN, IP, adder, dateAdded, lastUpdated, allNotes, publicNotes, noteNumber, role, username)
// Remove user from deleted profs if necessary
if(context.simpledb.botleveldata.deletedProfs[firstArg] !== undefined){
delete context.simpledb.botleveldata.deletedProfs[firstArg];
}
// Add name of profile to profile list
context.simpledb.botleveldata.allProfilesList.push(firstArg);
// Add profile
var newProfile = new Member('Unknown', 'Unknown', 'Unknown', event.senderobj.display, getDate(new Date()), getDate(new Date()), {}, {}, 1, ['Moderator'], firstArg, []);
context.simpledb.botleveldata.members[firstArg] = newProfile;
context.sendResponse('Created the profile *' + firstArg + '*.');
}else{
context.sendResponse(':warning: Error: *' + firstArg + '* is a *' + getLetterNode(getPermNode(firstArg)) + '*. Please use `$addSrModerator`, `$addTrainee`, or `$addBuilder` to add this profile.');
}
}else{
context.sendResponse(':warning: Error: The profile *' + firstArg + '* already exists.');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$addModerator "username"`');
}
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 11) === '$addTrainee'){
if(addTraineeEn){
if(resultOfPermCheck === 0 || resultOfPermCheck === 1){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[11] === ' ' && event.message[12] === '"') && event.message[event.message.length - 1] === '"'){
// Command is valid and sender is allowed
var firstParse = parseCommand(event.message, 13, event.message.length, '', '"');
var firstArg = firstParse[0];
if(!((isInArray(firstArg, context.simpledb.botleveldata.allProfilesList))[0])){
// Profile does not exist, which is good
if(getPermNode(firstArg) === 5){
// Target is a default user
// Constructor Format: (name, IGN, IP, adder, dateAdded, lastUpdated, allNotes, publicNotes, noteNumber, role, username)
// Remove user from deleted profs if necessary
if(context.simpledb.botleveldata.deletedProfs[firstArg] !== undefined){
delete context.simpledb.botleveldata.deletedProfs[firstArg];
}
// Add name of profile to profile list
context.simpledb.botleveldata.allProfilesList.push(firstArg);
// Add profile
var newProfile = new Member('Unknown', 'Unknown', 'Unknown', event.senderobj.display, getDate(new Date()), getDate(new Date()), {}, {}, 1, ['Trainee'], firstArg, []);
context.simpledb.botleveldata.members[firstArg] = newProfile;
context.sendResponse('Created the profile *' + firstArg + '*.');
}else{
context.sendResponse(':warning: Error: *' + firstArg + '* is a *' + getLetterNode(getPermNode(firstArg)) + '*. Please use `$addSrModerator`, `$addModerator`, or `$addBuilder` to add this profile.');
}
}else{
context.sendResponse(':warning: Error: The profile *' + firstArg + '* already exists.');
}
}else{
context.sendResponse(':warning: Error: Can\'t parse command. Correct syntax:\n`$addTrainee "username"`');
}
}else{
permError(resultOfPermCheck);
}
}else{
enError();
}
}
// --------------------
else if(event.message.substring(0, 11) === '$addBuilder'){
if(addBuilderEn){
if(resultOfPermCheck === 0 || resultOfPermCheck === 2){
updateLogs(event);
updateCounts(resultOfPermCheck);
if((event.message[11] === ' ' && event.message[12] === '"') && event.message[event.message.length - 1] === '"'){
// Command is valid and sender is allowed
var firstParse = parseCommand(event.message, 13, event.message.length, '', '"');
var firstArg = firstParse[0];
if(!((isInArray(firstArg, context.simpledb.botleveldata.allProfilesList))[0])){
// Profile does not exist, which is good
if(getPermNode(firstArg) === 5){
// Target is a default user
// Constructor Format: (name, IGN, IP, adder, dateAdded, lastUpdated, allNotes, publicNotes, noteNumber, role, username)
// Remove user from deleted profs if necessary
if(context.simpledb.botleveldata.deletedProfs[firstArg] !== undefined){
delete context.simpledb.botleveldata.deletedProfs[firstArg];
}
// Add name of profile to profile list
context.simpledb.botleveldata.allProfilesList.push(firstArg);
// Add profile
var newProfile = new Member('Unknown', 'Unknown', 'Unknown', event.senderobj.display, getDate(new Date()), getDate(new Date()), {}, {}, 1, ['Builder'], firstArg, []);
context.simpledb.botleveldata.members[firstArg] = newProfile;
context.sendResponse('Created the profile *' + firstArg + '*.');
}else{
context.sendResponse(':warning: Error: *' + firstArg + '* is a *' + getLetterNode(getPermNode(firstArg)) + '*. Please use `$addSrModerator`, `$addModerator`, of `$addTrainee` to add this profile.');
}