forked from WerewolvesRevamped/Werewolves-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
players.js
1261 lines (1195 loc) · 57.8 KB
/
players.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 handelling users
- Validating a user
- Handelling a list of users
- Checking if a user has a specific role
- Cacheing player emojis
- Converting between emojis and user id
*/
module.exports = function() {
/* Variables */
this.emojiIDs = null;
this.publicValues = null;
this.privateValues = null;
this.publicVotes = null;
this.ccs = null;
this.pRoles = null;
/* Handle players command */
this.cmdPlayers = function(message, args) {
// Check subcommands
if(!args[0] || (!args[1] && args[0] != "list" && args[0] != "log" && args[0] != "log2" && args[0] != "msgs")) {
message.channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `players [get|get_clean|set|resurrect|signup|list|msgs|log|log2]`!");
return;
}
//Find subcommand
switch(args[0]) {
case "get": cmdPlayersGet(message.channel, args, false); break;
case "get_clean": cmdPlayersGet(message.channel, args, true); break;
case "set": cmdPlayersSet(message.channel, args); break;
case "resurrect": cmdPlayersResurrect(message.channel, args); break;
case "signup": cmdPlayersSignup(message.channel, args); break;
case "sub":
case "substitute": cmdPlayersSubstitute(message, args); break;
case "switch": cmdPlayersSwitch(message, args); break;
case "list": cmdConfirm(message, "players list"); break;
case "log": cmdConfirm(message, "players log"); break;
case "log2": cmdConfirm(message, "players log2"); break;
case "messages":
case "msgs": cmdPlayersListMsgs(message.channel, args); break;
default: message.channel.send("⛔ Syntax error. Invalid parameter `" + args[0] + "`!"); break;
}
}
this.cmdRoll = function(message, args) {
// Check subcommands
if(!args[1] && (args[0] && args[0] == "bl" || args[0] == "wl")) {
message.channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `roll [bl|wl] <players>` or `roll`!");
return;
}
//Find subcommand
switch(args[0]) {
case "bl": case "blacklist": cmdRollExe(message.channel, args, false); break;
case "wl": case "whitelist": cmdRollExe(message.channel, args, true); break;
default: cmdRollExe(message.channel, [], false); break;
}
}
this.helpPlayers = function(member, args) {
let help = "";
switch(args[0]) {
case "":
if(isGameMaster(member)) help += stats.prefix + "players [list|msgs|log|log2] - Information about players\n";
if(isGameMaster(member)) help += stats.prefix + "players [get|get_clean|set|resurrect|signup] - Manages players\n";
if(isGameMaster(member)) help += stats.prefix + "players [substitute|switch] - Manages player changes\n";
if(isGameMaster(member)) help += stats.prefix + "killq [add|remove|killall|list|clear] - Manages kill queue\n";
if(isGameMaster(member)) help += stats.prefix + "modrole [add|remove] - Adds/removes roles from users\n";
help += stats.prefix + "list - Lists signed up players\n";
help += stats.prefix + "list_alphabetical - Lists signed up players (alphabetical)\n";
help += stats.prefix + "alive - Lists alive players\n";
help += stats.prefix + "signup - Signs you up for the next game\n";
help += stats.prefix + "emojis - Gives a list of emojis and player ids (Useful for CC creation)\n";
help += stats.prefix + "roll [-|whitelist|blacklist] - Selects a random player\n";
break;
case "modrole":
help += "```yaml\nSyntax\n\n" + stats.prefix + "modrole [add|remove] <user id> <role id>\n```";
help += "```\nFunctionality\n\nAdds or removes a role from a user\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "modrole add 242983689921888256 584770967058776067\n< ✅ Added Bot Developer to @McTsts (Ts)!\n```";
help += "```diff\nAliases\n\n- mr\n```";
break;
case "list_signedup":
help += "```yaml\nSyntax\n\n" + stats.prefix + "list\n```";
help += "```\nFunctionality\n\nLists all signed up players\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "list\n< Signed Up Players | Total: 3\n 🛠 - McTsts (@McTsts)\n 🤔 - marhjo (@marhjo)\n 👌 - federick (@federick)\n```";
help += "```diff\nAliases\n\n- l\n- signedup\n- signedup_list\n- signedup-list\n- listsignedup\n- list-signedup\n- list_signedup\n```";
break;
case "list_alphabetical":
help += "```yaml\nSyntax\n\n" + stats.prefix + "list_alphabetical\n```";
help += "```\nFunctionality\n\nLists all signed up players (alphabetically)\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "list\n< Signed Up Players (Alphabetical) | Total: 3\n 🛠 - McTsts (@McTsts)\n 🤔 - marhjo (@marhjo)\n 👌 - zederick (@zederick)\n```";
help += "```diff\nAliases\n\n- la\n```";
break;
case "list_alive":
help += "```yaml\nSyntax\n\n" + stats.prefix + "alive\n```";
help += "```\nFunctionality\n\nLists all alive players\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "list\n< Alive Players | Total: 3\n 🛠 - McTsts (@McTsts)\n 🤔 - marhjo (@marhjo)\n 👌 - federick (@federick)\n```";
help += "```diff\nAliases\n\n- a\n- alive_list\n- alive-list\n- listalive\n- list-alive\n- list_alive\n```";
break;
case "emojis":
help += "```yaml\nSyntax\n\n" + stats.prefix + "emojis\n```";
help += "```\nFunctionality\n\nGives you a list of emojis and player ids as well as a list of all emojis. Can be used for CC creation.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "emojis\n< 🛠 242983689921888256\n 🤔 102036304845377536\n 👌 203091600283271169\n 🛠 🤔 👌\n```";
help += "```diff\nAliases\n\n- e\n- emoji\n```";
break;
case "signup":
help += "```yaml\nSyntax\n\n" + stats.prefix + "signup <Emoji>\n```";
help += "```\nFunctionality\n\nSigns you up for the next game with emoji <Emoji>, which has to be a valid, not custom, emoji, that is not used by another player yet. If you have already signedup the command changes your emoji. If no emoji is provided, you are signed out.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "signup 🛠\n< ✅ @McTsts signed up with emoji 🛠!\n\n> " + stats.prefix + "signup\n< ✅ Successfully signed out, @McTsts. You will no longer participate in the next game!\n```";
help += "```diff\nAliases\n\n- join\n- sign-up\n- sign_up\n- unsignup\n- signout\n- participate\n- sign-out\n- sign_out\n- leave\n- unjoin```";
break;
case "j":
help += "```yaml\nSyntax\n\n" + stats.prefix + "j\n```";
help += "```\nFunctionality\n\nSigns you up for the next game with your emoji. If you don't have a person emoji this can be considered as an alias of " + stats.prefix + "signup\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "j\n< ✅ @McTsts signed up with emoji 🛠!\n```";
break;
case "roll":
switch(args[1]) {
default:
help += "```yaml\nSyntax\n\n" + stats.prefix + "roll [whitelist|blacklist]\n```";
help += "```\nFunctionality\n\nCommands to randomize a list of players. " + stats.prefix + "help roll <sub-command> for detailed help.\n\nIf used without a subcommand randomizes from the full player list.```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roll\n< ▶️ Selected @McTsts (🛠)\n```";
help += "```diff\nAliases\n\n- rand\n- random\n- randomize\n```";
break;
case "wl": case "whitelist":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roll whitelist <Player List>\n```";
help += "```\nFunctionality\n\nSelects a random player from the <Player List>\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roll whitelist McTsts Vera\n< ▶️ Selected @McTsts (🛠)\n```";
help += "```diff\nAliases\n\n- roll wl\n```";
break;
case "bl": case "blacklist":
help += "```yaml\nSyntax\n\n" + stats.prefix + "roll blacklist <Player List>\n```";
help += "```\nFunctionality\n\nSelects a random player from the game that is not on the <Player List>\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "roll blacklist Vera\n< ▶️ Selected @McTsts (🛠)\n```";
help += "```diff\nAliases\n\n- roll bl\n```";
break;
}
break;
case "players":
if(!isGameMaster(member)) break;
switch(args[1]) {
default:
help += "```yaml\nSyntax\n\n" + stats.prefix + "players [get|get_clean|set|resurrect|signup|list|substitute|switch|messages|log|log2]\n```";
help += "```\nFunctionality\n\nGroup of commands to handle players. " + stats.prefix + "help players <sub-command> for detailed help.\n\nList of Player Properties:\nalive: Whether the player is alive`\nemoji: The emoji the player uses\nrole: The role of the player\npublic_value: The value of the players vote on public polls (Typically 1)\nprivate_value: The value of the players vote on private polls (Typically 1)\npublic_votes: The base value of votes the player has against them on public votes (Typically 0)\nid: The discord id of the player\nccs: the amount of created ccs\npublic_msgs: Amount of messages sent in public channels\nprivate_msgs: Amount of messages sent in private channels```";
help += "```diff\nAliases\n\n- p\n- player\n```";
break;
case "get":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players get <Player Property> <Player>\n```";
help += "```\nFunctionality\n\nReturns the value of <Player Property> for a player indentified with <Player>. For a list of player properties see " + stats.prefix + "help players.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players get alive mctsts\n< ✅ McTsts's alive value is 1!\n```";
help += "```diff\nAliases\n\n- pg\n```";
break;
case "get_clean":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players get_clean <Player Property> <Player>\n```";
help += "```\nFunctionality\n\nSame as get, but shows roles in a more player friendly way.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players get alive mctsts\n< ✅ McTsts's alive value is 1!\n```";
break;
case "set":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players set <Player Property> <Player> <Value>\n```";
help += "```\nFunctionality\n\nSets the value of <Player Property> for a player indentified with <Player> to <Value>. For a list of player properties see " + stats.prefix + "help players.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players set role mctsts baker\n< ✅ McTsts's role value now is baker!\n```";
help += "```diff\nAliases\n\n- ps\n```";
break;
case "resurrect":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players resurrect <Player>\n```";
help += "```\nFunctionality\n\nResurrects a player indentified with <Player>, by setting their alive value to 1, removing the dead participant role, and adding the participant role.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players resurrect mctsts\n< ✳ Resurrecting McTsts!\n< ✅ McTsts's alive value now is 1!\n```";
break;
case "signup":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players signup <Player> <Emoji>\n```";
help += "```\nFunctionality\n\nPretends the player identified with <Player> used the command " + stats.prefix + "signup <Emoji>. This command works even if signups aren't open.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players signup mctsts 🛠\n< ✅ @McTsts signed up with emoji 🛠!\n```";
break;
case "sub":
case "substitute":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players substitute <Old Player> <New Player> <New Emoji>\n```";
help += "```\nFunctionality\n\nReplaces the first player with the second.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players sub 242983689921888256 588628378312114179 🛠\n```";
help += "```diff\nAliases\n\n- players sub\n```";
break;
case "switch":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players switch <Old Player> <New Player>\n```";
help += "```\nFunctionality\n\nSwitches the first player with the second.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players switch 242983689921888256 588628378312114179\n```";
break;
case "list":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players list\n```";
help += "```\nFunctionality\n\nLists all players with their role and alive values.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players list\n< ❗ Click the reaction in the next 20.0 seconds to confirm " + stats.prefix + "players list!\n> Players | Total: 2\n 🛠 - @McTsts (Werewolf); Alive: 1\n 👌 - @federick (Baker); Alive: 1```";
break;
case "log":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players log\n```";
help += "```\nFunctionality\n\nLists all players with their role and nickname in the gamelog format.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players log\n< ❗ Click the reaction in the next 20.0 seconds to confirm " + stats.prefix + "players log!\n> Players | Total: 2\n • 🛠 @McTsts (as `Ts`) is `Werewolf`\n • 👌 @federick (as `fed`) is `Baker`\n```";
break;
case "log2":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players log2\n```";
help += "```\nFunctionality\n\nLists all players with their role and all roles with their player. Can be used to copy into gamelog messages.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players log2\n< ❗ Click the reaction in the next 20.0 seconds to confirm " + stats.prefix + "players log2!```";
break;
case "messages":
help += "```yaml\nSyntax\n\n" + stats.prefix + "players messages\n```";
help += "```\nFunctionality\n\nLists all players and their public and private message count.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "players messages\n< ❗ Click the reaction in the next 20.0 seconds to confirm " + stats.prefix + "players list!\n> Players | Total: 1\n 🛠 - @McTsts (Werewolf); Public Messages: 1; Private Messages: 3```";
help += "```diff\nAliases\n\n- players msgs\n```";
break;
}
break;
case "killq":
if(!isGameMaster(member)) break;
switch(args[1]) {
default:
help += "```yaml\nSyntax\n\n" + stats.prefix + "killq [add|remove|killall|list|clear]\n```";
help += "```\nFunctionality\n\nGroup of commands to handle killing. " + stats.prefix + "help killq <sub-command> for detailed help.```";
help += "```diff\nAliases\n\n- killq\n- killqueue\n- kq\n```";
break;
case "add":
help += "```yaml\nSyntax\n\n" + stats.prefix + "killq add <Player List>\n```";
help += "```\nFunctionality\n\nAdds all players from the <Player List> into the kill queue.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "killq add mctsts\n< ✳ Adding 1 player (McTsts) to the kill queue!\n< ✅ Added McTsts to the kill queue!\n```";
break;
case "remove":
help += "```yaml\nSyntax\n\n" + stats.prefix + "killq remove <Player List>\n```";
help += "```\nFunctionality\n\nRemoves all players from the <Player List> from the kill queue.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "killq remove mctsts\n< ✳ Removing 1 player (McTsts) from the kill queue!\n< ✅ Removed McTsts from the kill queue!\n```";
break;
case "killall":
help += "```yaml\nSyntax\n\n" + stats.prefix + "killq killall\n```";
help += "```\nFunctionality\n\nKills all players that are currently in the kill queue.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "killq killall\n< ❗ Click the reaction in the next 20.0 seconds to confirm " + stats.prefix + "killq killall!\n< Kill Queue | Total: 1\n 🛠 - McTsts (McTsts)\n< ✳ Killing 1 player!\n< ✅ Killed McTsts!\n```";
break;
case "list":
help += "```yaml\nSyntax\n\n" + stats.prefix + "killq list\n```";
help += "```\nFunctionality\n\nLists all players that are currently in the kill queue.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "killq list\n< Kill Queue | Total: 1\n 🛠 - McTsts (McTsts)\n```";
break;
case "clear":
help += "```yaml\nSyntax\n\n" + stats.prefix + "killq clear\n```";
help += "```\nFunctionality\n\nRemoves all players from the kill queue.\n```";
help += "```fix\nUsage\n\n> " + stats.prefix + "killq clear\n< ✅ Successfully cleared kill queue!\n```";
break;
}
break;
}
return help;
}
/* Handles Emoji Get command */
this.cmdEmojis = function(channel) {
channel.send("```\n" + emojiIDs.map(el => el.emoji + " " + el.id).join("\n") + "\n``` ```\n" + emojiIDs.map(el => el.emoji).join(" ") + "\n```");
}
/* Handles killq command */
this.cmdKillq = function(message, args) {
// Check subcommand
if(!args[0]) {
message.channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `killq [list|add|remove|clear|killall]`!");
return;
}
// Find subcommand
switch(args[0]) {
case "list": cmdKillqList(message.channel); break;
case "add": cmdKillqAdd(message.channel, args); break;
case "remove": cmdKillqRemove(message.channel, args); break;
case "clear": cmdKillqClear(message.channel); break;
case "killall": cmdKillqList(message.channel); cmdConfirm(message, "killq killall"); break;
default: message.channel.send("⛔ Syntax error. Invalid parameter `" + args[0] + "`!"); break;
}
}
/* Lists current killq */
this.cmdKillqList = function(channel) {
// Get killq
sql("SELECT id FROM killq", result => {
// Print killq
result = removeDuplicates(result.map(el => el.id));
let playerList = result.map(el => idToEmoji(el) + " - " + channel.guild.members.cache.get(el).displayName + " (" + channel.guild.members.cache.get(el).user.username + ")").join("\n");
channel.send("**Kill Queue** | Total: " + result.length + "\n" + playerList);
}, () => {
// Db error
channel.send("⛔ Database error. Could not list kill queue!");
});
}
/* Add an user to the killq */
this.cmdKillqAdd = function(channel, args) {
// Check parameter
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters! Requires at least 1 player!");
return;
}
// Get users
players = getUserList(channel, args, 1);
if(players) {
let playerList = players.map(el => "`" + channel.guild.members.cache.get(el).displayName + "`").join(", ");
// Add to killq
channel.send("✳ Adding " + players.length + " player" + (players.length != 1 ? "s" : "") + " (" + playerList + ") to the kill queue!");
players.forEach(el => {
sql("INSERT INTO killq (id) VALUES (" + connection.escape(el) + ")", result => {
channel.send("✅ Added `" + channel.guild.members.cache.get(el).displayName + "` to the kill queue!");
}, () => {
// DB Error
channel.send("⛔ Database error. Could not add " + channel.guild.members.cache.get(el) + " to the kill queue!");
});
});
} else {
// No valid players
channel.send("⛔ Syntax error. No valid players!");
}
}
/* Removes an user from the killq */
this.cmdKillqRemove = function(channel, args) {
// Check parameters
if(!args[1]) {
channel.send("⛔ Syntax error. Not enough parameters! Requires at least 1 player!");
return;
}
// Get users
players = getUserList(channel, args, 1);
if(players) {
// Remove from killq
let playerList = players.map(el =>"`" + channel.guild.members.cache.get(el).displayName + "`").join(", ");
channel.send("✳ Removing " + players.length + " player" + (players.length != 1 ? "s" : "") + " (" + playerList + ") from the kill queue!");
players.forEach(el => {
sql("DELETE FROM killq WHERE id = " + connection.escape(el), result => {
channel.send("✅ Removed `" + channel.guild.members.cache.get(el).displayName + "` from the kill queue!");
}, () => {
// DB error
channel.send("⛔ Database error. Could not remove " + channel.guild.members.cache.get(el) + " from the kill queue!");
});
});
} else {
// No valid players
channel.send("⛔ Syntax error. No valid players!");
}
}
/* Kills all players in the killq */
this.cmdKillqKillall = function(channel) {
sql("SELECT id FROM killq", result => {
result = removeDuplicates(result.map(el => el.id));
channel.send("✳ Killing `" + result.length + "` player" + (result.length != 1 ? "s" : "") + "!");
result.forEach(el => {
// Update DB
sql("DELETE FROM killq WHERE id = " + connection.escape(el), result => {
}, () => {
channel.send("⛔ Database error. Could not remove `" + channel.guild.members.cache.get(el).displayName + "` from the kill queue!");
});
sql("UPDATE players SET alive = 0 WHERE id = " + connection.escape(el), result => {
channel.send("✅ Killed `" + channel.guild.members.cache.get(el).displayName + "`!");
updateGameStatus(channel.guild);
}, () => {
channel.send("⛔ Database error. Could not kill `" + channel.guild.members.cache.get(el).displayName + "`!");
});
// Send reporter message
cmdConnectionSend(channel, ["", "reporter2", true, stats.prefix + "players get_clean role " + channel.guild.members.cache.get(el)]);
cmdConnectionSend(channel, ["", "reporter", true, stats.prefix + "players get_clean role " + channel.guild.members.cache.get(el)]);
// Remove roles
channel.guild.members.cache.get(el).roles.remove(stats.participant).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not remove role");
});
channel.guild.members.cache.get(el).roles.remove(stats.mayor).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not remove role");
});
channel.guild.members.cache.get(el).roles.remove(stats.mayor2).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not remove role");
});
channel.guild.members.cache.get(el).roles.remove(stats.reporter).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not remove role");
});
channel.guild.members.cache.get(el).roles.remove(stats.guardian).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not remove role");
});
channel.guild.members.cache.get(el).roles.add(stats.dead_participant).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not add role");
});
});
}, () => {
channel.send("⛔ Database error. Could not kill the players in the kill queue");
});
}
/* Clear killq */
this.cmdKillqClear = function(channel) {
sql("DELETE FROM killq", result => {
channel.send("✅ Successfully cleared kill queue!");
}, () => {
channel.send("⛔ Database error. Could not clear kill queue!");
});
}
/* Lists all signedup players */
this.cmdPlayersList = function(channel, args) {
// Get a list of players
sql("SELECT id,emoji,role,alive,public_value,private_value,public_votes,ccs FROM players", result => {
let playerListArray = result.map(el => `${el.emoji} - ${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id): "<@" + el.id + ">"} (${el.role.split(",").map(role => toTitleCase(role)).join(" + ")}); Alive: ${channel.guild.members.cache.get(el.id) ? (el.alive ? client.emojis.cache.get(stats.yes_emoji) : client.emojis.cache.get(stats.no_emoji)) : "⚠️"}; CCs: ${el.ccs}; Votes: ${el.public_value},${el.private_value},${el.public_votes}`);
let playerList = [], counter = 0;
for(let i = 0; i < playerListArray.length; i++) {
if(!playerList[Math.floor(counter/10)]) playerList[Math.floor(counter/10)] = [];
playerList[Math.floor(counter/10)].push(playerListArray[i]);
counter++;
}
channel.send("**Players** | Total: " + result.length);
for(let i = 0; i < playerList.length; i++) {
// Print message
channel.send("✳ Listing players " + i + "/" + (playerList.length) + "...").then(m => {
m.edit(playerList[i].join("\n"));
}).catch(err => {
logO(err);
sendError(channel, err, "Could not list signed up players");
});
}
}, () => {
// DB error
channel.send("⛔ Database error. Could not list signed up players!");
});
}
/* Lists all signedup players in log format */
this.cmdPlayersLog = function(channel, args) {
// Get a list of players
sql("SELECT id,emoji,role,alive,public_value,private_value,public_votes,ccs FROM players", result => {
let playerList = result.map(el => {
let player = channel.guild.members.cache.get(el.id);
let nickname = player.nickname ? " (as `" + player.nickname + "`)" : "";
return `• ${el.emoji} ${player ? player : "<@" + el.id + ">"}${nickname} is \`${el.role.split(",").map(role => toTitleCase(role)).join(" + ")}\``;
});
channel.send("```**Players** | Total: " + result.length + "\n" + playerList.join("\n") + "\n```")
.catch(err => {
logO(err);
sendError(channel, err, "Could not log signed up players");
});
}, () => {
// DB error
channel.send("⛔ Database error. Could not list signed up players!");
});
}
/* Lists all signedup players in a different log format */
this.cmdPlayersLog2 = function(channel, args) {
// Get a list of players
sql("SELECT id,emoji,role,alive,public_value,private_value,public_votes,ccs FROM players WHERE alive=1", result => {
let playerList = result.map(el => {
let thisRoles = el.role.split(",").map(role => toTitleCase(role));
let thisPlayer = channel.guild.members.cache.get(el.id);
if(thisPlayer.roles.cache.get(stats.mayor) || thisPlayer.roles.cache.get(stats.mayor2)) thisRoles.push("Mayor");
if(thisPlayer.roles.cache.get(stats.reporter)) thisRoles.push("Reporter");
if(thisPlayer.roles.cache.get(stats.guardian)) thisRoles.push("Guardian");
let thisPlayerList = [];
thisPlayerList.push(thisPlayer.nickname ? (thisPlayer.nickname + " (" + thisPlayer.user.username + ")") : thisPlayer.user.username);
thisPlayerList.push(`• <@${el.id}> (${thisRoles.join(", ")}) ? []`);
thisRoles.forEach(role => thisPlayerList.push(`• ${role} (<@${el.id}>${thisRoles.length>1?', '+thisRoles.filter(r=>r!=role).join(', '):''}) ? @ ()`));
return thisPlayerList;
});
// chunk list
let playerListArray = playerList.flat();
playerList = [];
let counter = 0;
for(let i = 0; i < playerListArray.length; i++) {
if(!playerList[Math.floor(counter/30)]) playerList[Math.floor(counter/30)] = [];
playerList[Math.floor(counter/30)].push(playerListArray[i]);
counter++;
}
// send list
for(let i = 0; i < playerList.length; i++) {
// Print message
channel.send("```\n" + playerList[i].join("\n") + "```")
.catch(err => {
logO(err);
sendError(channel, err, "Could not list players for log");
});
}
}, () => {
// DB error
channel.send("⛔ Database error. Could not list signed up players!");
});
}
/* Lists all signedup players */
this.cmdPlayersListMsgs = function(channel, args) {
// Get a list of players
sql("SELECT id,emoji,public_msgs,private_msgs FROM players", result => {
let totalMsgs = 0;
let totalMsgsPrivate = 0;
let totalMsgsPublic = 0;
let playerListArray = result.sort((a,b) => (b.public_msgs+b.private_msgs) - (a.public_msgs+a.private_msgs)).map(el => {
totalMsgs += el.public_msgs+el.private_msgs;
totalMsgsPrivate += el.private_msgs;
totalMsgsPublic += el.public_msgs;
return `${el.emoji} - ${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id): "<@" + el.id + ">"}; Total: ${el.public_msgs+el.private_msgs}; Public: ${el.public_msgs}; Private: ${el.private_msgs}`;
});
let playerList = [], counter = 0;
for(let i = 0; i < playerListArray.length; i++) {
if(!playerList[Math.floor(counter/10)]) playerList[Math.floor(counter/10)] = [];
playerList[Math.floor(counter/10)].push(playerListArray[i]);
counter++;
}
channel.send("**Players** | Total: " + result.length + "\nTotal: " + totalMsgs + "; Public: " + totalMsgsPublic + "; Private: " + totalMsgsPrivate);
for(let i = 0; i < playerList.length; i++) {
// Print message
channel.send("✳ Listing players " + i + "/" + (playerList.length) + "...").then(m => {
m.edit(playerList[i].join("\n"));
}).catch(err => {
logO(err);
sendError(channel, err, "Could not list signed up players");
});
}
}, () => {
// DB error
channel.send("⛔ Database error. Could not list signed up players!");
});
}
/* Randomizes */
this.cmdRollExe = function(channel, args, wl) {
let blacklist = getUserList(channel, args, 1) || [];
console.log(blacklist);
// Get a list of players
sql("SELECT id FROM players WHERE alive=1", result => {
let playerList = result.map(el => getUser(channel, el.id));
if(!wl) playerList = playerList.filter(el => blacklist.indexOf(el) === -1);
else playerList = playerList.filter(el => blacklist.indexOf(el) != -1);
let rID = playerList[Math.floor(Math.random() * playerList.length)];
channel.send(`⏺️ Randomizing out of: ${playerList.map(el => idToEmoji(el)).join(", ")}`);
channel.send(`✳ Selecting...`).then(m => m.edit(`▶️ Selected <@${rID}> (${idToEmoji(rID)})`));
}, () => {
// DB error
channel.send("⛔ Database error. Could not retrieve list of participants!");
});
}
this.cmdModrole = function(message, args) {
let aid = getUser(message.channel, args[1]);
if(!aid) return;
let author = message.guild.members.cache.get(aid);
if(!author) return;
let role = message.guild.roles.cache.get(args[2]);
if(!role) return;
switch(args[0]) {
case "add":
author.roles.add(role);
message.channel.send("✅ Added `" + role.name + "` to <@" + author.id + "> (" + author.user.username + ")!");
break;
case "remove":
author.roles.remove(role);
message.channel.send("✅ Remove `" + role.name + "` from <@" + author.id + "> (" + author.user.username + ")!");
break;
}
}
/* Lists all signedup players */
this.cmdListSignedup = function(channel) {
// Get a list of players
sql("SELECT id,emoji FROM players", result => {
let playerList = result.map(el => `${el.emoji} - ${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id).user.username : "*user left*"} (${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id) : "<@" + el.id + ">"})`).join("\n");
// Print message
channel.send("✳ Listing signed up players").then(m => {
m.edit("**Signed Up Players** | Total: " + result.length + "\n" + playerList)
}).catch(err => {
logO(err);
sendError(channel, err, "Could not list signed up players");
});
}, () => {
// DB error
channel.send("⛔ Database error. Could not list signed up players!");
});
}
/* Lists all signedup players */
this.cmdListSignedupAlphabetical = function(channel) {
// Get a list of players
sql("SELECT id,emoji FROM players", result => {
let playerList = result.sort((a,b) => {
let pa = channel.guild.members.cache.get(a.id);
let pb = channel.guild.members.cache.get(b.id);
return (pa ? pa.nickname : "-") > (pb ? pb.nickname : "-") ? 1 : -1;
}).map(el => `${el.emoji} - ${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id).nickname : "*user left*"}`).join("\n");
// Print message
channel.send("✳ Listing signed up players").then(m => {
m.edit("**Signed Up Players (Alphabetical)** | Total: " + result.length + "\n" + playerList)
}).catch(err => {
logO(err);
sendError(channel, err, "Could not list signed up players");
});
}, () => {
// DB error
channel.send("⛔ Database error. Could not list signed up players!");
});
}
/* Lists all alive players */
this.cmdListAlive = function(channel) {
// Check gamephase
if(stats.gamephase < gp.INGAME) {
channel.send("⛔ Command error. Can only list alive players in ingame phase.");
return;
}
// Get a list of players
sql("SELECT id,emoji FROM players WHERE alive = 1", result => {
let playerList = result.map(el => `${el.emoji} - ${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id).user.username : "*user left*"} (${channel.guild.members.cache.get(el.id) ? channel.guild.members.cache.get(el.id) : "<@" + el.id + ">"})`).join("\n");
// Print message
channel.send("✳ Listing alive players").then(m => {
m.edit("**Alive Players** | Total: " + result.length + "\n" + playerList)
}).catch(err => {
logO(err);
sendError(channel, err, "Could not list alive players");
});
}, () => {
// DB error
channel.send("⛔ Database error. Could not list alive players!");
});
}
/* Substitutes a player */
this.cmdPlayersSubstitute = async function(message, args) {
if(!args[2] || !args[3]) {
message.channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `" + stats.prefix + "players substitute <current player id> <new player id> <new emoji>`!");
return;
}
cmdPlayersSet(message.channel, ["set", "role", getUser(message.channel, args[1]), "substituted"]);
cmdKillqAdd(message.channel, ["add", getUser(message.channel, args[1])]);
setTimeout(function () {
confirmActionExecute("killq killall", message, false);
}, 5000);
setTimeout(function () {
cmdPlayersSet(message.channel, ["set", "id", getUser(message.channel, args[1]), getUser(message.channel, args[2])]);
cmdPlayersSet(message.channel, ["set", "emoji", getUser(message.channel, args[2]), args[3]]);
cmdPlayersSet(message.channel, ["set", "role", getUser(message.channel, args[2]), pRoles.find(el => el.id === getUser(message.channel, args[1])).role]);
cmdPlayersResurrect(message.channel, ["resurrect", getUser(message.channel, args[2])]);
}, 10000);
setTimeout(function () {
let categories = cachedCCs;
categories.push(...cachedSCs)
substituteChannels(message.channel, categories, 0, getUser(message.channel, args[1]), getUser(message.channel, args[2]));
}, 15000);
setTimeout(function() {
cacheRoleInfo();
getVotes();
getCCs();
getPRoles();
getCCCats();
message.channel.send("✅ Substitution complete!");
}, 30000);
}
/* Substitutes a player */
this.cmdPlayersSwitch = async function(message, args) {
if(!args[2]) {
message.channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `" + stats.prefix + "players switch <player id #1> <player id #2>`!");
return;
}
getPRoles();
setTimeout(function () { // switch channels
cmdPlayersSet(message.channel, ["set", "role", getUser(message.channel, args[2]), pRoles.find(el => el.id === getUser(message.channel, args[1])).role]);
cmdPlayersSet(message.channel, ["set", "role", getUser(message.channel, args[1]), pRoles.find(el => el.id === getUser(message.channel, args[2])).role]);
let categories = cachedCCs;
categories.push(...cachedSCs)
switchChannels(message.channel, categories, 0, getUser(message.channel, args[1]), getUser(message.channel, args[2]));
}, 3000);
setTimeout(function() { // reload data
cacheRoleInfo();
getVotes();
getCCs();
getPRoles();
getCCCats();
message.channel.send("✅ Switch complete!");
}, 30000);
}
/* Subs a category */
this.substituteChannels = function(channel, ccCats, index, subPlayerFrom, subPlayerTo) {
// End
if(ccCats.length <= 0 || ccCats.length >= 20) return;
if(index >= ccCats.length) {
channel.send("✅ Successfully substituted in all channel categories!");
return;
}
// Category deleted
if(!channel.guild.channels.cache.get(ccCats[index])) {
substituteChannels(channel, ccCats, ++index, subPlayerFrom, subPlayerTo);
return;
}
// SUB channels in category
substituteOneChannel(channel, ccCats, index, channel.guild.channels.cache.get(ccCats[index]).children.toJSON(), 0, subPlayerFrom, subPlayerTo);
}
/* Subs a channel */
this.substituteOneChannel = function(channel, ccCats, index, channels, channelIndex, subPlayerFrom, subPlayerTo) {
if(channels.length <= 0) return;
if(channelIndex >= channels.length) {
channel.send("✅ Successfully substituted one channel category!");
substituteChannels(channel, ccCats, ++index, subPlayerFrom, subPlayerTo);
return;
}
// Deleted channel
if(!channels[channelIndex] || !channel.guild.channels.cache.get(channels[channelIndex].id)) {
substituteOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
return;
} else {
let channelMembers = channel.guild.channels.cache.get(channels[channelIndex].id).permissionOverwrites.cache.toJSON().filter(el => el.type === "member").map(el => el.id);
let channelOwners = channel.guild.channels.cache.get(channels[channelIndex].id).permissionOverwrites.cache.toJSON().filter(el => el.type === "member").filter(el => el.allow == 66560).map(el => el.id);
if(channelMembers.includes(subPlayerFrom)) {
cmdCCAdd(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["add", subPlayerTo], 1);
}
if(channelOwners.includes(subPlayerFrom)) {
setTimeout(function() {
cmdCCPromote(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["promote", subPlayerTo], 1);
substituteOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
}, 1000);
} else {
substituteOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
}
}
}
/* switch a category */
this.switchChannels = function(channel, ccCats, index, subPlayerFrom, subPlayerTo) {
// End
if(ccCats.length <= 0 || ccCats.length >= 20) return;
if(index >= ccCats.length) {
channel.send("✅ Successfully switched in all channel categories!");
return;
}
// Category deleted
if(!channel.guild.channels.cache.get(ccCats[index])) {
switchChannels(channel, ccCats, ++index, subPlayerFrom, subPlayerTo);
return;
}
// SUB channels in category
switchOneChannel(channel, ccCats, index, channel.guild.channels.cache.get(ccCats[index]).children.toJSON(), 0, subPlayerFrom, subPlayerTo);
}
/* Subs a channel */
this.switchOneChannel = function(channel, ccCats, index, channels, channelIndex, subPlayerFrom, subPlayerTo) {
if(channels.length <= 0) return;
if(channelIndex >= channels.length) {
channel.send("✅ Successfully switched one channel category!");
switchChannels(channel, ccCats, ++index, subPlayerFrom, subPlayerTo);
return;
}
// Deleted channel
if(!channels[channelIndex] || !channel.guild.channels.cache.get(channels[channelIndex].id)) {
switchOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
return;
} else {
let channelMembers = channel.guild.channels.cache.get(channels[channelIndex].id).permissionOverwrites.cache.toJSON().filter(el => el.type === "member").map(el => el.id);
let channelOwners = channel.guild.channels.cache.get(channels[channelIndex].id).permissionOverwrites.cache.toJSON().filter(el => el.type === "member").filter(el => el.allow == 66560).map(el => el.id);
if(channelMembers.includes(subPlayerFrom) && !channelMembers.includes(subPlayerTo)) {
cmdCCAdd(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["add", subPlayerTo], 1);
cmdCCRemove(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["remove", subPlayerFrom], 1);
channel.guild.channels.cache.get(channels[channelIndex].id).send("❗ " + channel.guild.members.cache.get(subPlayerFrom).displayName + " switched to " + channel.guild.members.cache.get(subPlayerTo).displayName + " ❗");
}
if(!channelMembers.includes(subPlayerFrom) && channelMembers.includes(subPlayerTo)) {
cmdCCAdd(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["add", subPlayerFrom], 1);
cmdCCRemove(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["remove", subPlayerTo], 1);
channel.guild.channels.cache.get(channels[channelIndex].id).send("❗ " + channel.guild.members.cache.get(subPlayerTo).displayName + " switched to " + channel.guild.members.cache.get(subPlayerFrom).displayName + " ❗");
}
if(channelOwners.includes(subPlayerFrom) && !channelOwners.includes(subPlayerTo)) {
setTimeout(function() {
cmdCCPromote(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["promote", subPlayerTo], 1);
if(channelMembers.includes(subPlayerTo) && channelMembers.includes(subPlayerFrom)) cmdCCDemote(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["demote", subPlayerFrom], 1);
switchOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
}, 1000);
} else if(!channelOwners.includes(subPlayerFrom) && channelOwners.includes(subPlayerTo)) {
setTimeout(function() {
cmdCCPromote(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["promote", subPlayerFrom], 1);
if(channelMembers.includes(subPlayerTo) && channelMembers.includes(subPlayerFrom)) cmdCCDemote(channel.guild.channels.cache.get(channels[channelIndex].id), {}, ["demote", subPlayerTo], 1);
switchOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
}, 1000);
} else {
switchOneChannel(channel, ccCats, index, channels, ++channelIndex, subPlayerFrom, subPlayerTo);
}
}
}
/* Get information about a player */
this.cmdPlayersGet = function(channel, args, mode) {
// Check arguments
if(!args[2]) {
channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `" + stats.prefix + "players get <value name> <player>`!");
return;
}
// Get user
var user = getUser(channel, args[2]);
if(!user) {
// Invalid user
channel.send("⛔ Syntax error. `" + args[2] + "` is not a valid player!");
return;
} else if(args[1] != "emoji" && args[1] != "role" && args[1] != "alive" && args[1] != "public_value" && args[1] != "private_value" && args[1] != "public_votes" && args[1] != "id" && args[1] != "ccs" && args[1] != "public_msgs" && args[1] != "private_msgs") {
// Invalid parameter
channel.send("⛔ Syntax error. Invalid parameter `" + args[1] + "`!");
return;
} else {
// Get info
sql("SELECT " + args[1] + " FROM players WHERE id = " + connection.escape(user), result => {
let playerName = channel.guild.members.cache.get(user).displayName;
channel.send("✅ `" + playerName + "`'s " + args[1] + " is `" + (args[1] === "role" ? (mode ? result[0][args[1]].split(",").filter(role => verifyRoleVisible(role)).join("` + `") : result[0][args[1]].split(",").join(", ")) : result[0][args[1]]) + "`!");
}, () => {
// Database error
channel.send("⛔ Database error. Could not get player information!");
});
}
}
/* Set information of a player */
this.cmdPlayersSet = function(channel, args) {
// Check arguments
if(!args[2] || !args[3]) {
channel.send("⛔ Syntax error. Not enough parameters! Correct usage: `" + stats.prefix + "players set <value name> <player> <value>`!");
return;
}
// Get user
var user = getUser(channel, args[2]);
if(!user) {
// Invalid user
channel.send("⛔ Syntax error. `" + args[2] + "` is not a valid player!");
return;
} else if(args[1] != "id" && args[1] != "emoji" && args[1] != "role" && args[1] != "alive" && args[1] != "public_value" && args[1] != "private_value" && args[1] != "public_votes" && args[1] != "ccs" && args[1] != "public_msgs" && args[1] != "private_msgs") {
// Invalid parameter
channel.send("⛔ Syntax error. Invalid parameter `" + args[1] + "`!");
return;
}
sql("UPDATE players SET " + args[1] + " = " + connection.escape(args[3]) + " WHERE id = " + connection.escape(user), result => {
let playerName = channel.guild.members.cache.get(user).displayName;
channel.send("✅ `" + playerName + "`'s " + args[1] + " value now is `" + args[3] + "`!");
updateGameStatus(channel.guild);
getVotes();
getCCs();
getPRoles();
}, () => {
channel.send("⛔ Database error. Could not update player information!");
});
}
/* Resurrects a dead player */
this.cmdPlayersResurrect = function(channel, args) {
// Get user
var user = getUser(channel, args[1]);
if(!user) {
// Invalid user
channel.send("⛔ Syntax error. `" + args[1] + "` is not a valid player!");
return;
} else {
// Send resurrect message
let playerName = channel.guild.members.cache.get(user).displayName;
channel.send("✳ Resurrecting " + playerName + "!");
// Set Roles
channel.guild.members.cache.get(user).roles.add(stats.participant).catch(err => {
logO(err);
sendError(channel, err, "Could not add role");
});
channel.guild.members.cache.get(user).roles.remove(stats.dead_participant).catch(err => {
logO(err);
sendError(channel, err, "Could not remove role");
});
// Set DB Value
channel.send(stats.prefix + "players set alive " + user + " 1");
}
}
/* Signup somebody else */
this.cmdPlayersSignup = function(channel, args) {
var user = getUser(channel, args[1]);
if(!user) {
// Invalid user
channel.send("⛔ Syntax error. `" + args[1] + "` is not a valid player!");
return;
} else {
cmdSignup(channel, channel.guild.members.cache.get(user), args.slice(2), false);
}
}
/* Signup a player */
this.cmdSignup = function(channel, member, args, checkGamephase) {
// Wrong Phase
if(checkGamephase && stats.gamephase != gp.SIGNUP) {
channel.send("⛔ Signup error. Sign ups are not open! Sign up will open up again soon.");
return;
} else if(isSub(member)) {
// Failed sign out
channel.send("⛔ Sign up error. Can't sign up while being a substitute player.");
return;
} else if(!args[0] && !isSignedUp(member)) {
// Failed sign out
channel.send("⛔ Sign up error. Can't sign out without being signed up! Use `" + stats.prefix + "signup <emoji>` to sign up.");
return;
} else if(!args[0] && isSignedUp(member)) {
// Sign out player
sql("DELETE FROM players WHERE id = " + connection.escape(member.id), result => {
channel.send(`✅ Successfully signed out, ${member.user}. You will no longer participate in the next game!`);
updateGameStatus(channel.guild);
member.roles.remove(stats.signed_up).catch(err => {
// Missing permissions
logO(err);
sendError(channel, err, "Could not remove role!");
});
}, () => {
// DB error
channel.send("⛔ Database error. Could not sign you out!");
});
} else if(!isSignedUp(member)) {
// Sign Up
channel.send("✳ Attempting to sign you up").then(message => {
message.react(args[0].replace(/<|>/g,"")).then(r => {
sql("SELECT id FROM players WHERE emoji = " + connection.escape(args[0]), result => {
// Check if somebody is already signed up with this emoji
if(result.length > 0 || args[0] === "⛔" || args[0] === "❌") {
// Signup error
channel.send("⛔ Database error. Emoji " + args[0] + " is already being used!");
message.reactions.removeAll().catch(err => {
// Couldn't clear reactions
logO(err);
sendError(channel, err, "Could not clear reactions!");
});
} else {
// Signup emoji
sql("INSERT INTO players (id, emoji, role) VALUES (" + connection.escape(member.id) + "," + connection.escape("" + args[0]) + "," + connection.escape("none") + ")", result => {
message.edit(`✅ ${member.user} signed up with emoji ${args[0]}!`);
updateGameStatus(message.guild);
message.reactions.removeAll().catch(err => {
// Couldn't clear reactions
logO(err);
sendError(channel, err, "Could not clear reactions!");
});
member.roles.add(stats.signed_up).catch(err => {
// Missing permissions
logO(err);
editError(message, err, "Could not add role!");
});
}, () => {
// DB error
message.edit("⛔ Database error. Could not sign you up!");
});
}
}, () => {
// DB error
message.edit("⛔ Database error. Could not check signed up players!");
});
}).catch(err => {
// Invalid emoji
message.edit("⛔ Invalid emoji. Couldn't use emoji. Could not sign you up!");
logO(err);
});
}).catch(err => {
// Couldn't check emoji
logO(err);
sendError(channel, err, "Could not check emoji!");
});
} else {
// Change Emoji
channel.send("✳ Attempting to sign you up").then(message => {
message.react(args[0].replace(/<|>/g,"")).then(r => {
sql("SELECT id FROM players WHERE emoji = " + connection.escape(args[0]), result => {
// Check if somebody already has this emoji
if(result.length > 0 || args[0] === "⛔") {
// Signup error
message.edit("⛔ Database error. Emoji " + args[0] + " is already being used!");
message.reactions.removeAll().catch(err => {
// Couldn't clear reactions
logO(err);
sendError(channel, err, "Could not clear reactions!");
});
} else {
// Change emoji
sql("UPDATE players SET emoji = " + connection.escape("" + args[0]) + " WHERE id = " + connection.escape(member.id), result => {
message.edit(`✅ ${member.user} changed emoji to ${args[0]}!`);
message.reactions.removeAll().catch(err => {
// Couldn't clear reactions
logO(err);
sendError(channel, err, "Could not clear reactions!");
});
}, () => {
// DB error
message.edit("⛔ Database error. Could not change your emoji!");
});
}
}, () => {
// DB error