forked from WerewolvesRevamped/Werewolves-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroles.js
1620 lines (1536 loc) · 74.5 KB
/
roles.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
/*
Module for roles / role info
- Set role name & aliases
- Get role info
- Create / Manage SCs
- Distribute roles
*/
module.exports = function() {
/* Variables */
this.cachedAliases = [];
this.cachedRoles = [];
this.cachedSCs = [];
this.scCatCount = 0;
this.iconLUT = {};
/* Handle roles command */
this.cmdRoles = function(message, args, argsX) {
// Check subcommand
if(!args[0]) {
message.channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Find subcommand
switch(args[0]) {
// Role Subcommand
case "set1": cmdRolesSet1(message.channel, args, argsX); break;
case "set2": cmdRolesSet2(message.channel, args, argsX); break;
case "set": cmdRolesSet(message.channel, args, argsX); break;
case "get": cmdRolesGet(message.channel, args); break;
case "remove": cmdRolesRemove(message.channel, args); break;
case "list": cmdRolesList(message.channel); break;
case "list_names": cmdRolesListNames(message.channel); break;
case "clear": cmdConfirm(message, "roles clear"); break;
// Alias Subcommands
case "set_alias": cmdRolesSetAlias(message.channel, args); break;
case "remove_alias": cmdRolesRemoveAlias(message.channel, args); break;
case "list_alias": cmdRolesListAlias(message.channel); break;
case "clear_alias": cmdConfirm(message, "roles clear_alias"); break;
default: message.channel.send("⛔ Syntax error. Invalid parameter `" + args[0] + "`!"); break;
}
}
this.cmdChannels = function(message, args, argsX) {
// Check subcommand
if(!args[0]) {
message.channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Find subcommand
switch(args[0]) {
// Ind SC Subcommands
case "set_ind": cmdRolesSetIndsc(message.channel, args); break;
case "get_ind": cmdRolesGetIndsc(message.channel, args); break;
case "list_ind": cmdRolesListIndsc(message.channel); break;
// Extra/Multi SC Subcommands
case "set_extra": cmdRolesAddSc(message.channel, "extra", args, argsX); break;
case "set_multi": cmdRolesAddSc(message.channel, "multi", args, argsX); break;
case "set_public": cmdRolesAddSc(message.channel, "public", args, argsX); break;
case "get": cmdRolesGetSc(message.channel, args); break;
case "raw": cmdRolesRawSc(message.channel, args); break;
case "remove": cmdRolesRemoveSc(message.channel, args); break;
case "list": cmdRolesListSc(message.channel); break;
case "elected": cmdRolesElectedSc(message.channel, args); break;
// SC Info Subcommands
case "info": cmdRolesScInfo(message.channel, args, false); break;
case "infopin": cmdRolesScInfo(message.channel, args, true); break;
case "info_set": cmdRolesScInfoSet(message.channel, args, argsX); break;
case "info_get": cmdRolesScInfoGet(message.channel, args); break;
case "info_remove": cmdRolesScInfoRemove(message.channel, args); break;
case "info_list": cmdRolesScInfoList(message.channel); break;
// SC Cleanup Subcommands
case "cleanup": cmdConfirm(message, "roles sc_cleanup"); break;
default: message.channel.send("⛔ Syntax error. Invalid parameter `" + args[0] + "`!"); break;
}
}
/* Help for this module */
this.helpRoles = function(member, args) {
let help = "";
switch(args[0]) {
case "":
if(isGameMaster(member)) help += stats.prefix + "roles [set|set1|set2|get|remove|list|list_names|clear] - Manages roles\n";
if(isGameMaster(member)) help += stats.prefix + "roles [set_alias|remove_alias|list_alias|clear_alias] - Manages role aliases\n";
if(isGameMaster(member)) help += stats.prefix + "channels [set_ind|get_ind|list_ind] - Manages individual SCs\n";
if(isGameMaster(member)) help += stats.prefix + "channels [set_extra|set_multi|set_public|get|raw|remove|list|elected] - Manages Extra/Public/Multi SCs\n";
if(isGameMaster(member)) help += stats.prefix + "channels [info|infopin|info_set|info_get|info_remove|info_list] - Manages SC Info\n";
if(isGameMaster(member)) help += stats.prefix + "channels cleanup - Cleans up SCs\n";
if(isGameMaster(member)) help += stats.prefix + "infopin - Returns role info & pins the message\n";
if(isGameMaster(member)) help += stats.prefix + "info_fancy - Returns role info (fancy)\n";
if(isGameMaster(member)) help += stats.prefix + "info_fancy_simplified - Returns role info (fancy, simplified)\n";
if(isGameMaster(member)) help += stats.prefix + "info_classic - Returns role info (classic)\n";
if(isGameMaster(member)) help += stats.prefix + "info_classic_simplified - Returns role info (classic, simplified)\n";
help += stats.prefix + "info - Returns role info\n";
break;
case "info":
help += "```yaml\nSyntax\n\n" + stats.prefix + "info <Role Name>\n```";
help += "```\nFunctionality\n\nShows the description of a role.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "info citizen\n< Citizen | Townsfolk\n Basics\n The Citizen has no special abilities.\n All the innocents vote during the day on whomever they suspect to be an enemy,\n and hope during the night that they won’t get killed.\n```";
help += "```diff\nAliases\n\n- i\n```";
break;
case "info_fancy":
help += "```yaml\nSyntax\n\n" + stats.prefix + "info_fancy <Role Name>\n```";
help += "```\nFunctionality\n\nShows the description of a role in the fancy view.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "info_fancy citizen\n```";
help += "```diff\nAliases\n\n- if\n```";
break;
case "info_fancy_simplified":
help += "```yaml\nSyntax\n\n" + stats.prefix + "info_fancy_simplified <Role Name>\n```";
help += "```\nFunctionality\n\nShows the description of a role in the fancy view and simplified.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "info_fancy_simplified citizen\n```";
help += "```diff\nAliases\n\n- ifs\n```";
break;
case "info_classic":
help += "```yaml\nSyntax\n\n" + stats.prefix + "info_classic <Role Name>\n```";
help += "```\nFunctionality\n\nShows the description of a role in the classic view.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "info_classic citizen\n```";
help += "```diff\nAliases\n\n- ic\n```";
break;
case "info_classic_simplified":
help += "```yaml\nSyntax\n\n" + stats.prefix + "info_classic_simplified <Role Name>\n```";
help += "```\nFunctionality\n\nShows the description of a role in the classic view and simplified.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "info_classic_simplified citizen\n```";
help += "```diff\nAliases\n\n- ics\n```";
break;
case "infopin":
if(!isGameMaster(member)) break;
help += "```yaml\nSyntax\n\n" + stats.prefix + "infopin <Role Name>\n```";
help += "```\nFunctionality\n\nShows the description of a role, pins it and deletes the pinning message.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "infopin citizen\n< Citizen | Townsfolk\n Basics\n The Citizen has no special abilities\n All the innocents vote during the day on whomever they suspect to be an enemy,\n and hope during the night that they won’t get killed.\n```";
help += "```diff\nAliases\n\n- ip\n```";
break;
case "roles":
if(!isGameMaster(member)) break;
switch(args[1]) {
default:
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles [set|get|remove|list|list_names|clear]\n" + stats.prefix + "roles [set_alias|remove_alias|list_alias|clear_alias]\n```";
help += "```\nFunctionality\n\nGroup of commands to handle roles and aliases. " + stats.prefix + "help roles <sub-command> for detailed help.```";
help += "```diff\nAliases\n\n- role\n- r\n```";
break;
case "set":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles set <Role Name> <Role Description>\n```";
help += "```\nFunctionality\n\nSets or updates the description of a role called <Role Name> to <Role Description>. <Role Description> can contain several new lines.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles set citizen \"**Citizen** | Townsfolk \n __Basics__\n The Citizen has no special abilities.\n All the innocents vote during the day on whomever they suspect to be an enemy,\n and hope during the night that they won’t get killed.\"\n< ✅ Set Citizen! Preview:\n Citizen | Townsfolk \n Basics\n The Citizen has no special abilities\n All the innocents vote during the day on whomever they suspect to be an enemy,\n and hope during the night that they won’t get killed. \n ---------------------------------------------------------------------------\n```";
break;
case "set_alias":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles set_alias <Alias Name> <Role Name>\n```";
help += "```\nFunctionality\n\nSets an alias for a role.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles set_alias citizen-alias citizen\n< ✅ Alias Citizen-Alias set to Citizen!\n```";
break;
case "set1":
case "set2":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles set2 <Role Name> <Role Description>\n```";
help += "```\nFunctionality\n\nCan be used to set very large role descriptions that do not fit in one message. Use set1 for the first half and set2 for the second half. Otherwise works just like set. For technical reasons, the first character of the description in set2 is ignored.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles set1 long_citizen long_text_part_1\n> " + stats.prefix + "roles set2 long_citizen long_text_part_2\n```";
break;
case "get":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles get <Role Name>\n```";
help += "```\nFunctionality\n\nReturns the raw description of a role called <Role Name> to allow easy editing.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles get citizen\n< ✅ Getting raw Citizen description!\n **Citizen** | Townsfolk \n __Basics__\n The Citizen has no special abilities\n All the innocents vote during the day on whomever they suspect to be an enemy,\n and hope during the night that they won’t get killed.\n```";
break;
case "remove":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles remove <Role Name>\n```";
help += "```\nFunctionality\n\nRemoves a role.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles remove citizen\n< ✅ Removed Citizen!\n```";
break;
case "remove_alias":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles remove_alias <Alias Name>\n```";
help += "```\nFunctionality\n\nRemoves a role alias.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles remove_alias citizen-alias\n< ✅ Removed Citizen-Alias!\n```";
break;
case "list":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles list\n```";
help += "```\nFunctionality\n\nLists all roles and a short part of their description.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles list\n```";
break;
case "list_names":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles list_names\n```";
help += "```\nFunctionality\n\nLists all role names.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles list_names\n```";
break;
case "list_alias":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles list_alias\n```";
help += "```\nFunctionality\n\nLists all role aliases and their role.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles list_alias\n```";
break;
case "clear":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles clear\n```";
help += "```\nFunctionality\n\nDeletes all roles.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles clear\n```";
break;
case "clear_alias":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roles clear_alias\n```";
help += "```\nFunctionality\n\nDeletes all role aliases.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roles clear_alias\n```";
break;
}
break;
case "channels":
if(!isGameMaster(member)) break;
switch(args[1]) {
default:
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels [set_ind|get_ind|list_ind]\n" + stats.prefix + "channels [set_extra|set_multi|set_public|get|raw|remove|list|elected]\n" + stats.prefix + "channels [info|infopin|info_set|info_get|info_remove|info_list]\n```";
help += "```\nFunctionality\n\nGroup of commands to handle individual, extra, multi and public channels as well as channel information. " + stats.prefix + "help channels <sub-command> for detailed help.```";
help += "```diff\nAliases\n\n- channel\n```";
break;
case "set_ind":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels set_ind <Role Name> <0|1>\n```";
help += "```\nFunctionality\n\nSets if a certain role gets an individual channel. Set to 1 if true.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels set_ind citizen 1\n< ✅ Set Indsc of Citizen to 1!\n```";
break;
case "get_ind":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels get_ind <Role Name>\n```";
help += "```\nFunctionality\n\nReturns if a certain role gets an individual channel. Returns 1 if true.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels get_ind citizen\n< ✅ Indsc of Citizen is set to 1!\n```";
break;
case "list_ind":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels list_ind\n```";
help += "```\nFunctionality\n\nReturns a list of all roles that have ind set to 1.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels list_ind\n```";
break;
case "set_extra":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels set_extra <Channel Name> <Role> [%r|\" \"] [Setup Commands]\n```";
help += "```\nFunctionality\n\nCreates a new extra channel called <Channel Name> for each player with the role <Role>, adds that player if the third argument is %r, otherwise set it to a quoted space. On creation of the channel executes all commands of the comma seperated <Setup Commands> list. %n can be used within the setup commands and will be replaced with a number unique to the player, which however is shared between all extra channels of the same role for that specific player.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels set_extra \"stalker_talk\" \"stalker\" \"%r\" \"connection add stalker%n stalker,delay 1 delete 1\"\n\n> " + stats.prefix + "channels set_extra \"stalker_selected\" \"stalker\" \" \" \"channels infopin stalker,connection add stalker%n,delay 1 delete 1\"\n```";
break;
case "set_multi":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels set_multi <Channel Name> <Condition> <Members> [Setup Commands]\n```";
help += "```\nFunctionality\n\nCreates a new multi channel called <Channel Name> if at least one player exists that has a role that is part of the comma seperated role list <Condition>, then adds all players that have a role that is part of the comma seperated role list <Members> to it. On creation of the channel executes all commands of the comma seperated <Setup Commands> list. If no <Condition> is given, the channel is always created.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels set_multi \"wolfpack\" \"bloody butcher,hellhound,infected wolf,psychic wolf,scared wolf,werewolf,white werewolf,wolfs cub,alpha wolf\" \"bloody butcher,hellhound,infected wolf,psychic wolf,scared wolf,werewolf,white werewolf,wolfs cub,alpha wolf\" \"infopin werewolf\"\n\n> " + stats.prefix + "channels set_multi \"hell\" \"demon\" \"demon,devil\" \"channels infopin hell\"\n```";
break;
case "set_public":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels set_multi <Channel Name> <Position> <Members> [Setup Commands]\n```";
help += "```\nFunctionality\n\nCreates a new public channel called <Channel Name> with position <Position> in the public category. Position is an integer, and the lower the value, the higher up the channel. <Members> defines who has access to this channel and can have the following options: mayor (mayor can write), alive (participants can write), info (nobody can write), dead (Dead/Specator can see/write). On creation of the channel executes all commands of the comma seperated <Setup Commands> list.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels set_public \"town_square\" 3 \"alive\" \"channels infopin town-square\"\n\n> " + stats.prefix + "channels set_public \"story_time\" 2 \"mayor\"\n```";
break;
case "get":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels get <Channel Name>\n```";
help += "```\nFunctionality\n\nReturns information about a channel by channel name.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels get flute_players\n\n< Flute_Players [Multi]\n Condition: Flute Player\n Members: Flute Player\n Setup Commands: infopin flute_player\n```";
break;
case "raw":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels raw <Channel Name>\n```";
help += "```\nFunctionality\n\nReturns information about a channel in the same way as it was inputted.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels raw flute_players\n```";
break;
case "remove":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels remove <Channel Name>\n```";
help += "```\nFunctionality\n\Removes a channel by channel name.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels remove flute_players\n```";
break;
case "list":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels list\n```";
help += "```\nFunctionality\n\Lists all channels and their type.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels list\n```";
break;
case "elected":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels elected <Mayor|Reporter|Guardian>\n```";
help += "```\nFunctionality\n\nGives the Mayor, Reporter or Guardian role access to the channel the command was executed in.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels elected mayor\n```";
break;
case "info":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels info <Channel Info Name>\n```";
help += "```\nFunctionality\n\nShows a channel info.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels info hell\n```";
break;
case "infopin":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels infopin <Channel Info Name>\n```";
help += "```\nFunctionality\n\nShows a channel info, pins it and deletes the pinning message.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels infopin hell\n```";
break;
case "info_set":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels info_set <Channel Info Name> <Channel Info>\n```";
help += "```\nFunctionality\n\nSet or updates a channel info.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels info_set example \"Example Text\"\n```";
break;
case "info_get":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels info_get <Channel Info Name>\n```";
help += "```\nFunctionality\n\nReturns raw channel info.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels info_get example\n```";
break;
case "info_remove":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels info_remove <Channel Info Name>\n```";
help += "```\nFunctionality\n\nRemoves channel info.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels info_remove example\n```";
break;
case "info_list":
help += "```yaml\nSyntax\n\n" + stats.prefix + "channels info_list\n```";
help += "```\nFunctionality\n\nLists all channel infos.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "channels info_list\n```";
break;
}
break;
}
return help;
}
this.getSCCats = function() {
// Get SC Cats
sql("SELECT id FROM sc_cats", result => {
// Cache SC Cats
cachedSCs = result.map(el => el.id);
}, () => {
// Db error
log("CC > Database error. Could not cache sc cat list!");
});
}
/* Sets permissions for an elected role */
this.cmdRolesElectedSc = function(channel, args) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return
}
// Find name
switch(args[1]) {
case "mayor":
channel.permissionOverwrites.create(stats.mayor, { VIEW_CHANNEL: true, SEND_MESSAGES: true }).catch(err => {
logO(err);
sendError(channel, err, "Could not setup channel permissions");
});
channel.permissionOverwrites.create(stats.mayor2, { VIEW_CHANNEL: true, SEND_MESSAGES: true }).catch(err => {
logO(err);
sendError(channel, err, "Could not setup channel permissions");
});
break;
case "reporter":
channel.permissionOverwrites.create(stats.reporter, { VIEW_CHANNEL: true, SEND_MESSAGES: true }).catch(err => {
logO(err);
sendError(channel, err, "Could not setup channel permissions");
});
break;
case "guardian":
channel.permissionOverwrites.create(stats.guardian, { VIEW_CHANNEL: true, SEND_MESSAGES: true }).catch(err => {
logO(err);
sendError(channel, err, "Could not setup channel permissions");
});
break;
default:
channel.send("⛔ Syntax error. `" + args[1] + "` is not a valid elected role!");
break;
}
}
/* Prints SC Info */
this.cmdRolesScInfo = function(channel, args, pin) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return
}
sql("SELECT info FROM sc_info WHERE name = " + connection.escape(args[1]), result => {
if(result.length > 0) {
var desc = result[0].info.replace(/~/g,"\n");
desc = applyTheme(desc);
desc = applyEmoji(desc);
let cMsg = desc;
// fancy variant
if(stats.fancy_mode) {
let descSplit = desc.split(/\n/);
let title = descSplit.shift();
let embed = {
"title": title,
"description": descSplit.join("\n"),
"color": 10921638,
"footer": {
"icon_url": `${channel.guild.iconURL()}`,
"text": `${channel.guild.name} - ${stats.game}`
}
};
let cRole = getCategoryRole(title);
if(cRole) embed.thumbnail = {url: repoBaseUrl + "/" + cRole + ".png"};
cMsg = {embeds: [ embed ]};
}
channel.send(cMsg).then(m => {
// Pin if pin is true
if(pin) {
m.pin().then(mp => {
mp.channel.messages.fetch().then(messages => {
mp.channel.bulkDelete(messages.filter(el => el.type === "CHANNEL_PINNED_MESSAGE"));
});
}).catch(err => {
logO(err);
sendError(channel, err, "Could not pin SC info message");
});
}
// Couldnt send message
}).catch(err => {
logO(err);
sendError(channel, err, "Could not send SC info message");
});
} else {
// Empty result
channel.send("⛔ Database error. Could not find SC `" + args[1] + "`!");
}
}, () => {
// DB error
channel.send("⛔ Database error. Couldn't look for SC information!");
});
}
/* Creates a SC Info entry */
this.cmdRolesScInfoSet = function(channel, args, argsX) {
// Check arguments
if(!args[1] || !args[2]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Remove entries with same name
sql("DELETE FROM sc_info WHERE name = " + connection.escape(args[1]), result => {
// Insert Entry & Preview it
sql("INSERT INTO sc_info (name, info) VALUES (" + connection.escape(args[1]) + "," + connection.escape(argsX[2]) + ")", result => {
channel.send("✅ Set `" + toTitleCase(args[1]) + "`! Preview:\n" + argsX[2].replace(/~/g,"\n") + "\n---------------------------------------------------------------------------------");
getRoles();
}, () => {
// Couldn't add to database
channel.send("⛔ Database error. Could not set SC info!");
});
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not prepare setting SC info!");
});
}
/* Removes a SC Info entry */
this.cmdRolesScInfoRemove = function(channel, args) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
sql("DELETE FROM sc_info WHERE name = " + connection.escape(args[1]), result => {
channel.send("✅ Removed `" + toTitleCase(args[1]) + "`!");
getAliases();
}, () => {
channel.send("⛔ Database error. Could not remove SC info!");
});
}
/* Deletes a cc category */
this.cmdRolesScCleanup = function(channel) {
for(let i = 0; i < cachedSCs.length; i++) {
cleanupCat(channel, cachedSCs[i], "SC #" + (i+1));
}
// Reset SC Cat Database
sql("DELETE FROM sc_cats", result => {
channel.send("✅ Successfully reset sc cat list!");
getCCCats();
}, () => {
channel.send("⛔ Database error. Could not reset sc cat list!");
});
}
/* Check if a channel is a SC */
this.isSC = function(channel) {
return !channel.parent ? true : cachedSCs.includes(channel.parentId);
}
/* Check if a channel is a SC */
this.isPublic = function(channel) {
return channel.parentId === cachedPublic;
}
/* Creates secret channels */
this.createSCs = function(channel, debug) {
let callback = ((arg1,arg3,arg2) => createSCStartInd(arg1, arg2, arg3)).bind(null,channel,debug);
createNewSCCat(channel, callback);
}
this.createNewSCCat = function(channel, callback, childChannel = false) {
scCatCount++;
let scName = "🕵 " + toTitleCase(stats.game) + " Secret Channels";
if(scCatCount > 1) scName += " #" + scCatCount;
channel.guild.channels.create(scName, { type: "GUILD_CATEGORY", permissionOverwrites: getSCCatPerms(channel.guild) })
.then(cc => {
sql("INSERT INTO sc_cats (id) VALUES (" + connection.escape(cc.id) + ")", result => {
if(childChannel) { // sets the new category as a channel parent - for the first channel that failed to fit in the previous category
childChannel.setParent(cc, { lockPermissions: false }).catch(err => {
logO(err);
sendError(channel, err, "Could not assign parent to SC!");
});
}
callback(cc);
getSCCats();
}, () => {
channel.send("⛔ Database error. Unable to save SC category!");
});
}).catch(err => {
logO(err);
sendError(channel, err, "Could not create SC category");
});
}
/* Starts the creation of individual scs */
this.createSCStartInd = function(channel, cc, debug) {
sql("SELECT id,role FROM players ORDER BY role ASC", result => {
createOneIndSC(channel, cc, result, 0, debug);
}, () => {
channel.send("⛔ Database error. Unable to get a list of player roles.");
});
}
/* Starts the creation of extra scs */
this.createSCStartExtra = function(channel, cc) {
sql("SELECT name,cond,members,setup FROM sc WHERE type = 'extra' ORDER BY name ASC", result => {
createOneExtraSC(channel, cc, result, 0);
}, () => {
channel.send("⛔ Database error. Unable to get a list extra SCs.");
});
}
/* Starts the creation of multi scs */
this.createSCStartMulti = function(channel, cc) {
sql("SELECT name,cond,members,setup FROM sc WHERE type = 'multi' ORDER BY name ASC", result => {
createOneMultiSC(channel, cc, result, 0);
}, () => {
channel.send("⛔ Database error. Unable to get a list extra SCs.");
});
}
/* Returns default sc permissions */
this.getSCCatPerms = function(guild) {
return [ getPerms(guild.id, [], ["read"]), getPerms(stats.bot, ["manage", "read", "write"], []), getPerms(stats.gamemaster, ["manage", "read", "write"], []), getPerms(stats.dead_participant, ["read"], ["write"]), getPerms(stats.spectator, ["read"], ["write"]), getPerms(stats.participant, ["write"], ["read"]) ];
}
this.createOneMultiSC = function(channel, category, multi, index) {
// Checks
if(index >= multi.length) {
channel.send("✅ Finished creating SCs!");
return;
}
// Check if multi sc condition is met
sql("SELECT id,role FROM players ORDER BY role ASC", result => {
result = result.filter(el => el.role.split(",").some(el => multi[index].cond.split(",").includes(el)));
if(result.length > 0 || multi[index].cond === " ") {
// Find members of multisc
sql("SELECT id,role FROM players ORDER BY role ASC", result2 => {
result2 = result2.filter(el => el.role.split(",").some(el => multi[index].members.split(",").includes(el)));
// Create permissions
let ccPerms = getCCCatPerms(channel.guild);
if(result2.length > 0) {
let members = result2.map(el => channel.guild.members.cache.get(el.id).displayName).join(", ");
channel.send("✅ Creating `" + toTitleCase(multi[index].name) + "` Multi SC for `" + (members ? members : "❌") + "`!");
result2.forEach(el => ccPerms.push(getPerms(el.id, ["history", "read"], [])));
}
// Create channel
var name = multi[index].name;
name = applyTheme(name);
channel.guild.channels.create(name, { type: "text", permissionOverwrites: ccPerms })
.then(sc => {
// Send info message
multi[index].setup.split(",").forEach(el => sc.send(stats.prefix + el));
// Move into sc category
sc.setParent(category,{ lockPermissions: false }).then(m => {
createOneMultiSC(channel, category, multi, ++index);
}).catch(err => {
logO(err);
sendError(channel, err, "Could not set category. Creating new SC category");
let callback = ((arg1,arg3,arg4,arg2) => createOneMultiSC(arg1, arg2, arg3, arg4)).bind(null,channel,multi,++index);
createNewSCCat(channel, callback, sc);
});
}).catch(err => {
// Couldn't create channel
logO(err);
sendError(channel, err, "Could not create channel");
});
}, () => {
channel.send("⛔ Database error. Unable to get a list of players with an multi SC role.");
});
} else {
// Continue
createOneMultiSC(channel, category, multi, ++index);
}
}, () => {
channel.send("⛔ Database error. Unable to get a list of players of SC condition.");
});
}
/* Creates a single type of extra secret channel */
this.createOneExtraSC = function(channel, category, extra, index) {
// Checks
if(index >= extra.length) {
createSCStartMulti(channel, category);
return;
}
// Verify Role
if(!verifyRole(extra[index].cond)) {
channel.send("✅ Skipping `" + extra[index].name +"`! Invalid role condition!");
createOneExtraSC(channel, category, extra, ++index);
}
// Get players with that role
sql("SELECT id,role FROM players ORDER BY role ASC", result => {
result = result.filter(el => el.role.split(",").includes(parseRole(extra[index].cond)));
if(result.length > 0) {
// Create SCs
createOneOneExtraSC(channel, category, extra, index, result, 0);
} else {
// Continue
createOneExtraSC(channel, category, extra, ++index);
}
}, () => {
channel.send("⛔ Database error. Unable to get a list of players with an extra SC role.");
});
}
/* Creates a single extra secret channel of a single type of extra secret channel */
this.createOneOneExtraSC = function(channel, category, extra, index, result, resultIndex) {
if(resultIndex >= result.length) {
createOneExtraSC(channel, category, extra, ++index);
return;
}
channel.send("✅ Creating `" + toTitleCase(extra[index].name) + "` Extra SC for `" + channel.guild.members.cache.get(result[resultIndex].id).displayName + "` (`" + toTitleCase(extra[index].cond) + "`)!");
// Create permissions
let ccPerms = getCCCatPerms(channel.guild);
if(extra[index].members === "%r") ccPerms.push(getPerms(result[resultIndex].id, ["history", "read"], []));
// Create channel
var name = extra[index].name;
name = name.replace("%r", channel.guild.members.cache.get(result[resultIndex].id).user.username);
name = applyTheme(name);
channel.guild.channels.create(name, { type: "text", permissionOverwrites: ccPerms })
.then(sc => {
// Send info message
if(extra[index].setup.length > 1) extra[index].setup.replace(/%r/g, result[resultIndex].id + "").replace(/%n/g, resultIndex).split(",").forEach(el => sc.send(stats.prefix + el));
// Move into sc category
sc.setParent(category,{ lockPermissions: false }).then(m => {
createOneOneExtraSC(channel, category, extra, index, result, ++resultIndex);
}).catch(err => {
logO(err);
sendError(channel, err, "Could not set category. Creating new SC category");
let callback = ((arg1,arg3,arg4,arg5,arg6,arg2) => createOneOneExtraSC(arg1, arg2, arg3, arg4, arg5, arg6)).bind(null,channel,extra,index,result,++resultIndex);
createNewSCCat(channel, callback, sc);
});
}).catch(err => {
// Couldn't create channel
logO(err);
sendError(channel, err, "Could not create channel");
});
}
/* Creates a single individual secret channel */
this.createOneIndSC = function(channel, category, players, index, debug) {
if(index >= players.length) {
createSCStartExtra(channel, category);
return;
}
let roleListD = players[index].role.split(",");
var customRole = false;
if(roleListD[0] === "custom") customRole = JSON.parse(roleListD[1].replace(/'/g,"\"").replace(/;/g,","));
let roleList = roleListD.map(el => "name = " + connection.escape(el)).join(" OR ");
sql("SELECT name,description,ind_sc FROM roles WHERE " + roleList, result => {
result = result.filter(role => verifyRoleVisible(role.name));
var rolesArray = result.map(el => toTitleCase(el.name));
let disName = channel.guild.members.cache.get(players[index].id).displayName;
if(!debug) {
if(!customRole) {
let roles = rolesArray.join("` + `");
roles = applyTheme(roles);
if(!stats.fancy_mode) { // default DM
channel.guild.members.cache.get(players[index].id).user.send("This message is giving you your role" + (result.length != 1 ? "s" : "") + " for the next game of Werewolves: Revamped!\n\n\nYour role" + (result.length != 1 ? "s are" : " is") + " `" + roles + "`.\n\nYou are __not__ allowed to share a screenshot of this message! You can claim whatever you want about your role, but you may under __NO__ circumstances show this message in any way to any other participants.\n\nIf you're confused about your role at all, then check #announcements on the discord, which contains a role book with information on all the roles in this game.").catch(err => {
logO(err);
sendError(channel, err, "Could not send role message to " + disName);
});
} else { // fancy DM
let roleData = getRoleData(rolesArray[0], result.find(el => toTitleCase(el.name) == rolesArray[0]).description);
if(!roleData) {
sendError(channel, err, "Could not find role for " + disName);
} else {
let embed = {
"title": "The game has started!",
"description": "This message is giving you your role for the next game of Werewolves: Revamped!\n\nYour role" + (result.length != 1 ? "s are" : " is") + " `" + roles + "`.\n\nYou are __not__ allowed to share a screenshot of this message! You can claim whatever you want about your role, but you may under __NO__ circumstances show this message in any way to any other participants.\n\nIf you're confused about your role at all, then check #how-to-play on the discord, which contains a role book with information on all the roles in this game. If you have any questions about the game, ping @Host.",
"color": roleData.color,
"footer": {
"icon_url": `${channel.guild.iconURL()}`,
"text": `${channel.guild.name} - ${stats.game}`
},
"thumbnail": {
"url": roleData.url
}
};
channel.guild.members.cache.get(players[index].id).user.send({embeds: [ embed ]}).catch(err => {
logO(err);
sendError(channel, err, "Could not send role message to " + disName);
});
}
}
} else {
channel.guild.members.cache.get(players[index].id).user.send("This message is giving you your custom role for the next game of Werewolves: Revamped!\n\n\nYour role is `" + toTitleCase(customRole.name) + "` (" + customRole.id + ").\n\nYou are __not__ allowed to share a screenshot of this message! You can claim whatever you want about your role, but you may under __NO__ circumstances show this message in any way to any other participants.").catch(err => {
logO(err);
sendError(channel, err, "Could not send role message to " + channel.guild.members.cache.get(players[index].id).displayName);
});
}
}
let indscRoles = result.filter(el => el.ind_sc).map(el => el.name);
if(customRole) indscRoles = [ customRole.name ];
// Check if ind sc
if(indscRoles.length) {
channel.send("✅ Creating `" + toTitleCase(indscRoles.join("-")) + "` Ind SC for `" + channel.guild.members.cache.get(players[index].id).displayName + "` (`" + result.map(el => toTitleCase(el.name)).join("` + `") + "`)!");
// Create permissions
let ccPerms = getCCCatPerms(channel.guild);
ccPerms.push(getPerms(players[index].id, ["history", "read"], []));
// Create channel
var name = indscRoles.join("-");
name = applyTheme(name);
channel.guild.channels.create(name.substr(0, 100), { type: "text", permissionOverwrites: ccPerms })
.then(sc => {
// Send info message
if(!customRole) indscRoles.forEach(el => cmdInfoEither(sc, [ el ], true, false));
else {
var desc = "";
desc += "**" + toTitleCase(customRole.name) + "** | " + toTitleCase(customRole.team);
desc += "\n__Basics__\n" + toSentenceCase(customRole.basics.replace(/%n/g,toTitleCase(customRole.name)));
desc += "\n__Details__\n" + toSentenceCase(customRole.details.replace(/%n/g,toTitleCase(customRole.name)));
desc += "\n__Win Condition__\n" + toSentenceCase(customRole.win.replace(/%n/g,toTitleCase(customRole.name)));
desc = applyTheme(desc);
sc.send(desc).then(m => {
m.pin().then(mp => {
mp.channel.messages.fetch().then(messages => {
mp.channel.bulkDelete(messages.filter(el => el.type === "CHANNEL_PINNED_MESSAGE"));
});
}).catch(err => {
logO(err);
sendError(channel, err, "Could not pin info message");
});
// Couldnt send message
}).catch(err => {
logO(err);
sendError(channel, err, "Could not send info message");
});
if(customRole.setup != "") customRole.setup.replace(/%p/g,players[index].id).replace(/%c/g,sc.id).split(",").forEach(el => sc.send(stats.prefix + el));
}
// Move into sc category
sc.setParent(category,{ lockPermissions: false }).then(m => {
createOneIndSC(channel, category, players, ++index, debug);
}).catch(err => {
logO(err);
sendError(channel, err, "Could not set category. Creating new SC category");
let callback = ((arg1,arg3,arg4,arg5,arg2) => createOneIndSC(arg1, arg2, arg3, arg4, arg5)).bind(null,channel,players,++index,debug);
createNewSCCat(channel, callback, sc);
});
}).catch(err => {
// Couldn't create channel
logO(err);
sendError(channel, err, "Could not create channel");
});
} else {
// No ind sc
channel.send("✅ Skipping `" + channel.guild.members.cache.get(players[index].id).displayName + "` (`" + result.map(el => toTitleCase(el.name)).join("` + `") + "`)!");
createOneIndSC(channel, category, players, ++index, debug);
}
}, () => {
// Couldn't delete
channel.send("⛔ Database error. Could not get role info!");
});
}
/* Cache Role Info */
this.cacheRoleInfo = function() {
getAliases();
getRoles();
getSCCats();
}
/* Cache role aliases */
this.getAliases = function() {
sql("SELECT alias,name FROM roles_alias", result => {
cachedAliases = result;
}, () => {
log("Roles > ❗❗❗ Unable to cache role aliases!");
});
}
/* Caches valid roles */
this.getRoles = function() {
sql("SELECT name FROM roles", result => {
cachedRoles = result.map(el => el.name);
}, () => {
log("Roles > ❗❗❗ Unable to cache role!");
});
}
/* Cache Public category */
this.getPublicCat = function() {
sqlGetStat(15, result => {
cachedPublic = result;
}, () => {
log("Roles > ❗❗❗ Unable to cache Public Category!");
});
}
/* Converts a role/alias to role */
this.parseRole = function(input) {
//console.log(input);
input = input.toLowerCase();
let alias = cachedAliases.find(el => el.alias === input);
if(alias) return parseRole(alias.name);
else return input;
}
/* Verify role */
this.verifyRole = function(input) {
let inputRole = parseRole(input);
let role = cachedRoles.find(el => el === inputRole);
return role ? true : false;
}
/* Verifies roles, but removes technical roles */
this.verifyRoleVisible = function(input) {
return !~input.search("!_") ? parseRole(input) : false;
}
/* Creates/Sets an Extra or Multi SC */
this.cmdRolesAddSc = function(channel, type, args, argsX) {
// Check arguments
if(!args[1] || !args[2]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
if(!args[3] || args[3] === "") {
args[3] = " ";
}
if(!argsX[4] || argsX[4] === "") {
argsX[4] = " ";
}
// Remove entries with same name
sql("DELETE FROM sc WHERE name = " + connection.escape(args[1]), result => {
// Insert Entry & Preview it
sql("INSERT INTO sc (name, type, cond, members, setup) VALUES (" + connection.escape(args[1].replace(/'/g,'"')) + ", " + connection.escape(type) + "," + connection.escape(args[2].replace(/'/g,'"')) + "," + connection.escape(args[3].replace(/'/g,'"')) + "," + connection.escape(argsX[4].replace(/'/g,'"')) + ")", result => {
if(args[2] === " ") args[2] = "none";
if(args[3] === " " && argsX[4] === " ") channel.send("✅ Created " + type + " SC `" + toTitleCase(args[1]) + "` with conditions `" + args[2] + "`, and no members or setup commands!");
else if(args[3] === " " && argsX[4] != " ") channel.send("✅ Created " + type + " SC `" + toTitleCase(args[1]) + "` with conditions `" + args[2] + "`, and setup commands `" + argsX[4] + "`, and no members!");
else if(args[3] != " " && argsX[4] === " ") channel.send("✅ Created " + type + " SC `" + toTitleCase(args[1]) + "` with conditions `" + args[2] + "`, and members `" + args[3] + "`, and no setup commands!");
else channel.send("✅ Created " + type + " SC `" + toTitleCase(args[1]) + "` with conditions `" + args[2] + "`, members `" + args[3] + "`, and setup commands `" + argsX[4] + "`!");
}, () => {
// Couldn't add to database
channel.send("⛔ Database error. Could not set SC!");
});
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not prepare SC database!");
});
}
/* Deletes a SC */
this.cmdRolesRemoveSc = function(channel, args) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Remove entries with same name
sql("DELETE FROM sc WHERE name = " + connection.escape(args[1]), result => {
// Insert Entry & Preview it
channel.send("✅ Deleted SC");
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not get values from SC database!");
});
}
/* Lists all SCs */
this.cmdRolesListSc = function(channel) {
// Remove entries with same name
sql("SELECT name,type,cond,members,setup FROM sc", result => {
if(result.length <= 0) {
channel.send("⛔ Database error. Could not find any SCs!");
return;
}
channel.send("✳ Sending a list of currently existing multi/extra SCs:");
chunkArray(result.map(el => "**" + toTitleCase(el.name) + "** [" + toTitleCase(el.type) + "]"), 50).map(el => el.join("\n")).forEach(el => channel.send(el));
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not get values from SC database!");
});
}
/* Gets a SC */
this.cmdRolesGetSc = function(channel, args) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Remove entries with same name
sql("SELECT name,type,cond,members,setup FROM sc WHERE name = " + connection.escape(args[1]), result => {
if(result.length <= 0) {
channel.send("⛔ Database error. Coult not find any matching SCs!");
return;
}
result.forEach(el => channel.send("**" + toTitleCase(el.name) + "** [" + toTitleCase(el.type) + "]\nCondition: " + toTitleCase(el.cond.replace(/,/g,", ")) + "\nMembers: " + toTitleCase(el.members.replace(/,/g,", ")) + "\nSetup Commands: " + (el.setup.length > 0 ? "`" + el.setup.replace(/,/g,"`, `") + "`" : "")));
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not get values from SC database!");
});
}
/* Gets a SC */
this.cmdRolesRawSc = function(channel, args) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Remove entries with same name
sql("SELECT name,type,cond,members,setup FROM sc WHERE name = " + connection.escape(args[1]), result => {
if(result.length <= 0) {
channel.send("⛔ Database error. Coult not find any matching SCs!");
return;
}
result.forEach(el => channel.send("```" + stats.prefix + "channels set_" + el.type + " \"" + el.name + "\" \"" + el.cond + "\" \"" + el.members + "\" \"" + el.setup + "\"```"));
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not get values from SC database!");
});
}
/* Lists all SC Infos */
this.cmdRolesScInfoList = function(channel) {
// Remove entries with same name
sql("SELECT name,info FROM sc_info", result => {
if(result.length <= 0) {
channel.send("⛔ Database error. Coult not find any SC Info!");
return;
}
channel.send("✳ Sending a list of currently existing SC info:");
chunkArray(result.map(el => "**__" + toTitleCase(el.name) + "__**: " + el.info.replace(/~/g,"").substr(0, 100)), 15).map(el => el.join("\n")).forEach(el => channel.send(el));
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not get values from SC Info database!");
});
}
/* Gets SC Info */
this.cmdRolesScInfoGet = function(channel, args) {
// Check arguments
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Remove entries with same name
sql("SELECT name,info FROM sc_info WHERE name = " + connection.escape(args[1]), result => {
if(result.length <= 0) {
channel.send("⛔ Database error. Coult not find any matching SC Info!");
return;
}
result.forEach(el => channel.send("**__" + toTitleCase(el.name) + "__**:\n```" + el.info.replace(/~/g,"\n") + "```"));
}, () => {
// Couldn't delete from database
channel.send("⛔ Database error. Coult not get values from SC Info database!");
});
}
/* Sets the description of a role / creates a role */
var roleTempSegment = "";
this.cmdRolesSet1 = function(channel, args, argsX) {
// Check arguments
if(!args[1] || !args[2]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
roleTempSegment = argsX[2];
}
this.cmdRolesSet2 = function(channel, args, argsX) {
// Check arguments
if(!args[1] || !args[2]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
argsX[2] = roleTempSegment + argsX[2].substr(1);
cmdRolesSet(channel, args, argsX);
}
/* Sets the description of a role / creates a role */
this.cmdRolesSet = function(channel, args, argsX) {
// Check arguments
if(!args[1] || !args[2]) {
channel.send("⛔ Syntax error. Not enough parameters!");
return;
}
// Insert Entry & Preview it
if(!verifyRole(args[1])) {
sql("INSERT INTO roles (name, description) VALUES (" + connection.escape(args[1]) + "," + connection.escape(argsX[2]) + ")", result => {
channel.send("✅ Set `" + toTitleCase(args[1]) + "`! Preview:\n" + argsX[2].replace(/~/g,"\n").substr(0, 1800) + "\n---------------------------------------------------------------------------------");
getRoles();
}, () => {
// Couldn't add to database
channel.send("⛔ Database error. Could not set role!");
});
} else {
sql("UPDATE roles SET description = " + connection.escape(argsX[2]) + " WHERE name = " + connection.escape(parseRole(args[1])), result => {
channel.send("✅ Updated `" + toTitleCase(args[1]) + "`! Preview:\n" + argsX[2].replace(/~/g,"\n").substr(0, 1800) + "\n---------------------------------------------------------------------------------");
getRoles();
}, () => {
// Couldn't add to database
channel.send("⛔ Database error. Could not update role!");