-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaff-list_service_modtimestamp.js
1592 lines (1512 loc) · 69.3 KB
/
staff-list_service_modtimestamp.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
/*
Author: RLNT
Requested by: Mortis
License: MIT
Repository: https://github.com/RLNT/sinus-staff-list
Resource-Page: https://forum.sinusbot.com/resources/staff-list.497/
Discord: https://discord.com/invite/Q3qxws6
Modified by: Michael - 13MHW75 ([email protected]) @ 21.01.2022
Changes: fixed: footertext doesn't work correctly
fixed: footertext placeholder %time% for actually timestamp
added: footertext placeholder %date% for actually datestamp
added: enable autocleanup after x days
...some database optimations ...
*/
registerPlugin(
{
name: 'Staff List - Services (timed)',
version: '1.10.4',
description: 'With this script, the bot will automatically keep track of the online status of predefined staff members and post it to a chosen channel description.',
author: 'RLNT (modded by: Micha)',
backends: ['ts3'],
vars: [
{
name: 'required',
title: 'All fields that are marked with (*) are required, fields with [*] are semi-required and all others are optional and have a default value.'
},
{
name: 'functionality',
title:
"The script stores usernames of clients with relevant groups. Each client you want to list has to join the server at least once while the script is running. A client can't be displayed in the staff list if they are offline and are not stored yet."
},
{
name: 'configuration',
title: 'A guide how to configure the script to your needs can be found here: https://github.com/RLNT/sinus-staff-list/blob/master/CONFIGURATION.md'
},
{
name: 'spacer0',
title: ''
},
{
name: 'header0',
title: '->>> General Options <<<-'
},
{
name: 'channel',
title: 'Display-Channel > Define the channel where the staff list should be shown in! (*)',
type: 'channel'
},
{
name: 'clickable',
title: 'Clickable-Names > Do you want the usernames in the list to be clickable? They work like hyperlinks then.',
type: 'select',
options: ['Yes', 'No']
},
{
name: 'multiple',
title: 'Show-Multiple-Groups > Do you want clients with multiple relevant groups to be displayed in all of them?',
type: 'select',
options: ['Yes', 'No']
},
{
name: 'away',
title: 'Away-Status > Do you want a third status (besides online & offline) if someone is away/afk?',
type: 'select',
options: ['Yes', 'No']
},
{
name: 'awayChannel',
title: 'Away-Channels > Do you want to set someone away/afk if they join an afk channel?',
type: 'select',
options: ['Yes', 'No'],
indent: 1,
conditions: [
{
field: 'away',
value: 0
}
]
},
{
name: 'afkChannels',
title: 'AFK-Channels > Define a list of channel IDs that should count as AFK-channels! (*)',
type: 'strings',
indent: 2,
conditions: [
{
field: 'away',
value: 0
},
{
field: 'awayChannel',
value: 0
}
]
},
{
name: 'awayMute',
title: 'Away-Mute > Do you want to count muted clients as away/afk?',
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'away',
value: 0
}
]
},
{
name: 'awayDeaf',
title: 'Away-Deaf > Do you want to count deaf clients as away/afk?',
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'away',
value: 0
}
]
},
{
name: 'autoremove',
title: 'Autoremove offline clients after time',
type: 'select',
options: ['Yes', 'No']
},
{ name: 'daystoremove',
title: 'After x days, client will remove permantently from list',
type: 'string',
placeholder: '10',
indent: 1,
conditions: [
{
field: 'autoremove',
value: 0
}
]
},
{
name: 'removeCommand',
title: "Remove-Command > Do you want a command to remove clients manually from the script's database?",
type: 'select',
options: ['Yes', 'No']
},
{
name: 'command',
title: 'Command > Define the command you want to use to delete a client manually!',
type: 'string',
placeholder: '!remove',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandServer',
title: "Server > Do you want the bot listening to the command when it's being sent in the server chat?",
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandChannel',
title: "Channel > Do you want the bot listening to the command when it's being sent in the channel chat?",
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandPrivate',
title: "Private > Do you want the bot listening to the command when it's being sent in the private chat?",
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandClients',
title: 'Clients > Define the list of client UIDs that should be allowed to use the command! [*]',
type: 'strings',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandGroups',
title: 'Groups > Define the list of group IDs that should be allowed to use the command! [*]',
type: 'strings',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandNoPerm',
title: "Permission-Text > Define the text that should be sent to the command invoker if they don't have permission to use the command!",
type: 'string',
placeholder: "You don't have permission to perform this command!",
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandArgument',
title: "Missing-Argument-Text > Define the text that should be sent to the command invoker if they didn't pass an argument to the command!",
type: 'string',
placeholder: 'Not enough arguments! You have to add a client UID to the command! Usage: !remove <client UID>',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandInvalid',
title: 'Invalid-UID-Text > Define the text that should be sent to the command invoker if the argument they entered is not a valid client UID! | placeholders: %arg% - entered argument',
type: 'string',
placeholder: '"%arg%" is not a valid client UID! Make sure to send the correct one.',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandNotFound',
title:
"Not-Found-Text > Define the text that should be sent to the command invoker if the target client couldn't be found in the database! | placeholders: %uid% - uid of the target client",
type: 'string',
placeholder: 'The client (%uid%) was not found in the database! Make sure to send the correct UID.',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'commandSuccess',
title: 'Success-Text > Define the text that should be sent to the command invoker if the target client was successfully removed! | placeholders: %uid% - uid of the target client',
type: 'string',
placeholder: 'The client (%uid%) was successfully removed!',
indent: 1,
conditions: [
{
field: 'removeCommand',
value: 0
}
]
},
{
name: 'dbRemoveCommand',
title: 'DB-Remove-Command > Do you want a command to drop/remove the whole database of the script?',
type: 'select',
options: ['Yes', 'No']
},
{
name: 'dbCommand',
title: 'Command > Define the command you want to use to delete the whole database!',
type: 'string',
placeholder: '!removedatabase',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandServer',
title: "Server > Do you want the bot listening to the command when it's being sent in the server chat?",
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandChannel',
title: "Channel > Do you want the bot listening to the command when it's being sent in the channel chat?",
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandPrivate',
title: "Private > Do you want the bot listening to the command when it's being sent in the private chat?",
type: 'checkbox',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandClients',
title: 'Clients > Define the list of client UIDs that should be allowed to use the command! [*]',
type: 'strings',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandGroups',
title: 'Groups > Define the list of group IDs that should be allowed to use the command! [*]',
type: 'strings',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandNoPerm',
title: "Permission-Text > Define the text that should be sent to the command invoker if they don't have permission to use the command!",
type: 'string',
placeholder: "You don't have permission to perform this command!",
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandEmpty',
title: 'Empty-Database-Text > Define the text that should be sent to the command invoker if database is already empty!',
type: 'string',
placeholder: 'The database is already empty!',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'dbCommandSuccess',
title:
'Success-Text > Define the text that should be sent to the command invoker if the database was successfully dropped/removed! | placeholders: %amount% - amount of database removals',
type: 'string',
placeholder: 'The database was successfully dropped! %amount% entries have been removed.',
indent: 1,
conditions: [
{
field: 'dbRemoveCommand',
value: 0
}
]
},
{
name: 'spacer1',
title: ''
},
{
name: 'header1',
title: '->>> Text & Format Options <<<-'
},
{
name: 'format',
title: 'You can use the normal BB code to format your text, like in TeamSpeak.'
},
{
name: 'template',
title: 'Custom-Template > Do you want to use a custom template to format your staff list?',
type: 'select',
options: ['Yes', 'No']
},
{
name: 'tUsername',
title: 'Username > Define what the name of a client in the staff list should look like! | placeholders: %name% - name of the client',
type: 'string',
placeholder: '[B]%name%[/B]',
indent: 1,
conditions: [
{
field: 'template',
value: 0
}
]
},
{
name: 'tPhraseOnline',
title: 'Online-Phrase > Define what the phrase if a client is online should look like!',
type: 'string',
placeholder: '[COLOR=#00ff00][B]ONLINE[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'template',
value: 0
}
]
},
{
name: 'tPhraseAway',
title: 'Away-Phrase > Define what the phrase if a client is away/afk should look like!',
type: 'string',
placeholder: '[COLOR=#c8c8c8][B]AWAY[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'template',
value: 0
},
{
field: 'away',
value: 0
}
]
},
{
name: 'tPhraseOffline',
title: 'Offline-Phrase > Define what the phrase if a client is offline should look like!',
type: 'string',
placeholder: '[COLOR=#ff0000][B]OFFLINE[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'template',
value: 0
}
]
},
{
name: 'tMemberLine',
title: 'User-Line > Define what a full line in the staff list should look like! | placeholders: %name% - formatted username, %status% - formatted status phrase, %lb% - line break',
type: 'multiline',
placeholder: '%name% [COLOR=#aaff00]>[/COLOR] %status%',
indent: 1,
conditions: [
{
field: 'template',
value: 0
}
]
},
{
name: 'tGroupSection',
title:
'Group-Section > Define what a group section in the staff list should look like! | placeholders: %group% - formatted group name, %users% - formatted member list, %lb% - line break',
type: 'multiline',
placeholder: '[center]> %group% <\n%users%\n____________________\n[/center]%lb%',
indent: 1,
conditions: [
{
field: 'template',
value: 0
}
]
},
{
name: 'separator',
title: 'Separator > Define what the separator between each group section in the staff list should look like!',
type: 'multiline',
placeholder: '_______________________________________',
indent: 1,
conditions: [
{
field: 'template',
value: 1
}
]
},
{
name: 'phraseOnline',
title: 'Online-Phrase > Define what the phrase if a client is online should look like!',
type: 'string',
placeholder: '[COLOR=#00ff00][B]ONLINE[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'template',
value: 1
}
]
},
{
name: 'phraseAway',
title: 'Away-Phrase > Define what the phrase if a client is away/afk should look like!',
type: 'string',
placeholder: '[COLOR=#c8c8c8][B]AWAY[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'template',
value: 1
},
{
field: 'away',
value: 0
}
]
},
{
name: 'phraseOffline',
title: 'Offline-Phrase > Define what the phrase if a client is offline should look like!',
type: 'string',
placeholder: '[COLOR=#ff0000][B]OFFLINE[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'template',
value: 1
}
]
},
{
name: 'emptyGroup',
title: 'Empty-Groups > Do you want to display empty groups in the staff list? A group is considered empty if no client is assigned/stored to it?',
type: 'select',
options: ['Yes', 'No']
},
{
name: 'emptyGroupText',
title: 'Empty-Groups-Text > Define what the text of an empty group should look like! | placeholders: %group% - formatted group name, %lb% - line break',
type: 'multiline',
placeholder: '[COLOR=#aa007f][size=12][B]%group%[/B][/size]\n[/COLOR][COLOR=#c8c8c8][B]NOT ASSIGNED[/B][/COLOR]',
indent: 1,
conditions: [
{
field: 'emptyGroup',
value: 0
}
]
},
{
name: 'header',
title: "Header > Do you want to display a header above the staff list? This will be static static text and won't be changed on a list update.",
type: 'select',
options: ['Yes', 'No']
},
{
name: 'headerText',
title: 'Header-Text > Define what the text of the header above the staff list should be! | placeholders: %lb% - line break',
type: 'multiline',
placeholder: 'This is the staff list of the server!\nYou can see if a specific team member is online, afk or offline.',
indent: 1,
conditions: [
{
field: 'header',
value: 0
}
]
},
{
name: 'footer',
title: "Footer > Do you want to display a footer underneath the staff list? This will be static static text and won't be changed on a list update.",
type: 'select',
options: ['Yes', 'No']
},
{
name: 'footerText',
title: 'Footer-Text > Define what the text of the footer underneath the staff list should be! | placeholders: %lb% - line break, %time% - timestamp, %date% - datestamp',
type: 'multiline',
placeholder: 'Coded by 13MHW75',
indent: 1,
conditions: [
{
field: 'footer',
value: 0
}
]
},
{
name: 'spacer2',
title: ''
},
{
name: 'header2',
title: '->>> Group Options <<<-'
},
{
name: 'priority',
title: 'The order in which you define the groups is important! Priority of the groups goes from top to bottom.'
},
{
name: 'staffGroups',
title: 'Staff Groups List',
type: 'array',
vars: [
{
name: 'id',
title: 'ID > Define the ID of the staff group! (*)',
indent: 2,
type: 'string',
placeholder: '1337'
},
{
name: 'name',
title: 'Name > Define the name that should be shown for the group! If not set, it will use the default group name.',
indent: 2,
type: 'multiline',
placeholder: '[COLOR=#aa007f][size=12][B]ADMIN[/B][/size][/COLOR]'
},
{
name: 'clients',
title: 'Clients > Define the list of additional client UIDs that should also count towards this staff group!',
indent: 2,
type: 'strings'
},
{
name: 'groups',
title: 'Groups > Define the list of additional group IDs that should also count towards this staff group!',
indent: 2,
type: 'strings'
}
]
},
{
name: 'spacer3',
title: ''
},
{
name: 'header3',
title: '->>> Dev Options <<<-'
},
{
name: 'developer',
title: "Don't change any of the following values if you have not been told to! This section is to identify problems faster and will drain performance."
},
{
name: 'devEnabled',
title: 'Do you want to enable the developer mode?',
type: 'select',
options: ['Yes', 'No']
}
]
},
(_, scriptConfig, meta) => {
// DEPENDENCIES
const engine = require('engine');
const backend = require('backend');
const event = require('event');
const store = require('store');
// GLOBAL VARS
let staffClients = []; // [uid, nickname, [staff groups]]
let groupList = []; // list of all relevant group IDs
const uidPattern = new RegExp('^[a-zA-Z0-9+\\/]{27}=$');
// CONFIG OPTIONS
let config = {
channel: scriptConfig.channel,
autoremove: scriptConfig.autoremove == 0 || false,
daystoremove: scriptConfig.daystoremove || '10',
clickable: scriptConfig.clickable == 0 || false,
multiple: scriptConfig.multiple == 0 || false,
away: scriptConfig.away == 0 || false,
remove: scriptConfig.removeCommand == 0 || false,
dbRemove: scriptConfig.dbRemoveCommand == 0 || false,
template: scriptConfig.template == 0 || false,
emptyGroup: scriptConfig.emptyGroup == 0 || false,
header: scriptConfig.header == 0 || false,
footer: scriptConfig.footer == 0 || false,
staffGroups: scriptConfig.staffGroups,
dev: scriptConfig.devEnabled == 0 || false
};
const away = {
awayChannel: config.away ? scriptConfig.awayChannel == 0 || false : false,
awayMute: config.away ? scriptConfig.awayMute === true || false : false,
awayDeaf: config.away ? scriptConfig.awayDeaf === true || false : false,
afkChannels: config.away ? scriptConfig.afkChannels : undefined
};
const remove = {
rCommand: config.remove ? scriptConfig.command || '!remove' : undefined,
rServer: config.remove ? scriptConfig.commandServer === true || false : undefined,
rChannel: config.remove ? scriptConfig.commandChannel === true || false : undefined,
rPrivate: config.remove ? scriptConfig.commandPrivate === true || false : undefined,
rClients: config.remove ? scriptConfig.commandClients || [] : undefined,
rGroups: config.remove ? scriptConfig.commandGroups || [] : undefined,
rPerm: config.remove ? scriptConfig.commandNoPerm || "You don't have permission to perform this command!" : undefined,
rArgument: config.remove ? scriptConfig.commandArgument || 'Not enough arguments! You have to add a client UID to the command! Usage: !remove <client UID>' : undefined,
rInvalid: config.remove ? scriptConfig.commandInvalid || '"%arg%" is not a valid client UID! Make sure to send the correct one.' : undefined,
rNotFound: config.remove ? scriptConfig.commandNotFound || 'The client (%uid%) was not found in the database! Make sure to send the correct UID.' : undefined,
rSuccess: config.remove ? scriptConfig.commandSuccess || 'The client (%uid%) was successfully removed!' : undefined
};
const dbRemove = {
dbrCommand: config.dbRemove ? scriptConfig.dbCommand || '!removedatabase' : undefined,
dbrServer: config.dbRemove ? scriptConfig.dbCommandServer === true || false : undefined,
dbrChannel: config.dbRemove ? scriptConfig.dbCommandChannel === true || false : undefined,
dbrPrivate: config.dbRemove ? scriptConfig.dbCommandPrivate === true || false : undefined,
dbrClients: config.dbRemove ? scriptConfig.dbCommandClients || [] : undefined,
dbrGroups: config.dbRemove ? scriptConfig.dbCommandGroups || [] : undefined,
dbrPerm: config.dbRemove ? scriptConfig.dbCommandNoPerm || "You don't have permission to perform this command!" : undefined,
dbrEmpty: config.dbRemove ? scriptConfig.dbCommandEmpty || 'The database is already empty!' : undefined,
dbrSuccess: config.dbRemove ? scriptConfig.dbCommandSuccess || 'The database was successfully dropped! %amount% entries have been removed.' : undefined
};
const template = {
username: config.template ? scriptConfig.tUsername || '[B]%name%[/B]' : undefined,
line: config.template ? scriptConfig.tMemberLine || '%name% [COLOR=#aaff00]>[/COLOR] %status%' : undefined,
section: config.template ? scriptConfig.tGroupSection || '[center]%group%\n%users%____________________[/center]' : undefined,
pOnline: (config.template ? scriptConfig.tPhraseOnline : scriptConfig.phraseOnline) || '[COLOR=#00ff00][B]ONLINE[/B][/COLOR]',
pAway: (config.template ? scriptConfig.tPhraseAway : scriptConfig.phraseAway) || '[COLOR=#c8c8c8][B]AWAY[/B][/COLOR]',
pOffline: (config.template ? scriptConfig.tPhraseOffline : scriptConfig.phraseOffline) || '[COLOR=#ff0000][B]OFFLINE[/B][/COLOR]',
separator: config.template ? undefined : scriptConfig.separator || '_______________________________________'
};
const emptyGroup = {
emptyText: config.emptyGroup ? scriptConfig.emptyGroupText || '[COLOR=#aa007f][size=12][B]%group%[/B][/size]\n[/COLOR][COLOR=#c8c8c8][B]NOT ASSIGNED[/B][/COLOR]' : undefined
};
const staticText = {
headerText: config.header ? scriptConfig.headerText || 'This is the staff list of the server!\nYou can see if a specific team member is online, afk or offline.' : undefined,
footerText: config.footer ? scriptConfig.footerText || 'Have fun on our server!' : undefined
};
// merge configs into one object
config = Object.assign(config, away, remove, dbRemove, template, emptyGroup, staticText);
// FUNCTIONS
/**
* Send a message to the SinusBot instance log
* @param {String} message > the message to send
* @returns {void} > nothing
*/
function log(message) {
engine.log(meta.name + ' > ' + message);
}
/**
* Wait for the backend to be online/connected each given amount of time for a given amount of tries
* @param {Number} attempts > the amount of tries the function should check for the backend to be online/connected
* @param {Number} wait > the amount of time (in seconds) that should be waited between each try
* @returns {Promise} > resolve when the backend is online/connected, reject when the backend was not online/connected in time
*/
function waitForBackend(attempts, wait) {
return new Promise((success, fail) => {
let attempt = 1;
const timer = setInterval(() => {
if (backend.isConnected()) {
clearInterval(timer);
if (config.dev) log('waitForBackend() took ' + attempt + ' attempts with a timer of ' + wait + ' seconds to resolve');
success();
return;
} else if (attempt > attempts) {
clearInterval(timer);
if (config.dev) log('waitForBackend() failed at ' + attempt + '. attempt with a timer of ' + wait + ' seconds');
fail('backend');
return;
}
attempt++;
}, wait * 1000);
});
}
/**
* Check all staff groups from the config if their entries are valid and if all IDs
* reference valid objects on TeamSpeak;
* Otherwise drop the whole config entry for the runtime
* @returns {Array} > a list of all valid staff groups objects
*/
function validateStaffGroups() {
let staffGroups = [];
let problemGroups = [];
config.staffGroups.forEach((group, index) => {
// check if necessary config options are set
if (group.id === undefined) return;
// check if the staff group id points to valid group on teamspeak
if (backend.getServerGroupByID(group.id) === undefined) return problemGroups.push(index);
// apply defaults
if (group.clients === undefined || !group.clients.length) group.clients = [];
if (group.groups === undefined || !group.groups.length) {
group.groups = [group.id];
} else {
group.groups = group.groups.filter(id => backend.getServerGroupByID(id) !== undefined && id !== group.id);
group.groups.push(group.id);
}
if (group.name === undefined || group.name === '') {
group.name = '[size=12][B]' + backend.getServerGroupByID(group.id).name() + '[/B][/size]';
}
// if all error checks passed, mark it as valid
groupList = groupList.concat(group.groups);
staffGroups.push(group);
});
// notify the script user that there are invalid groups in the configuration
if (problemGroups.length)
log(
"There was at least one entry in your configuration which is invalid! This can happen if a required field is empty or if your group ID doesn't point to a valid group on your TeamSpeak server! Any invalid entries will be skipped. The entries with the following indexes are invalid: " +
problemGroups
);
return staffGroups;
}
/**
* Validate the script database by checking all entries if they still have a relevant
* group to list and if they match the current database format;
* Otherwise drop the whole entry;
* Database format: <key - uid | entry - nickname, [staff groups]>
* @returns {void} > nothing
*/
function validateDatabase() {
var time = new Date();
var timestamp = time.getTime();
store.getKeys().forEach(key => {
// delete entries from database which do not have the correct format
if (Array.isArray(store.get(key)[3])) {
if (store.get(key)[2].some(clientGroup => typeof clientGroup !== 'object')) {
removeClient(key);
} else {
// get relevant groups
const relevantGroups = store.get(key)[3].filter(clientGroup => groupList.includes(clientGroup.id));
// drop entry if no relevant groups are found
if (!relevantGroups.length) return removeClient(key);
// remove irrelevant groups
if (relevantGroups.length !== store.get(key)[3].length) {
storeClient(key, store.get(key)[0], timestamp, relevantGroups);
}
}
} else {
removeClient(key);
}
});
}
/**
* Dump the whole script database to find errors faster
* @returns {void} > nothing
*/
function dumpDatabase() {
store.getKeys().forEach((key, index) => {
console.log(`${index} | uid: ${key} | nick: ${store.get(key)[0]} | timestamp: ${store.get(key)[1]}`);
store.get(key)[2].forEach((group, groupIndex) => {
console.log(`${index} | ${groupIndex} | ${Object.entries(group)}`);
});
});
}
/**
* Store a client to the script's database if they are not already stored;
* Can also update information if entry is alreadyp present;
* @param {String} uid > the UID of the client to store
* @param {String} nick > the nickname of the client to store
* @param {String} timestamp > the timestamp new Date() of the client
* @param {Array} groups > the relevant staff groups of the client to store
* @returns {void} > nothing
*/
function storeClient(uid, nick, timestamp, groups) {
if (!store.getKeys().includes(uid)) {
store.set(uid, [nick, timestamp, groups]);
} else if (store.get(uid)[0] !== nick) {
store.unset(uid);
store.set(uid, [nick, timestamp, groups]);
} else if (store.get(uid)[1] !== timestamp) {
store.unset(uid);
store.set(uid, [nick, timestamp, groups]);
} else if (store.get(uid)[2] !== groups) {
store.unset(uid);
store.set(uid, [nick, timestamp, groups]);
} else {
return;
}
updateStaffClients();
}
/**
* Remove a client from the script's database if they are stored;
* Will give feedback if the entry was removed
* @param {String} uid > the UID of the client to remove
* @returns {Boolean} > true if the client was removed, false if no entry was found
*/
function removeClient(uid) {
if (store.getKeys().includes(uid)) {
store.unset(uid);
updateStaffClients();
if (config.dev) log(`Removed client (${uid}) from database!`);
return true;
} else {
return false;
}
}
/**
* Update the global list of staff clients with an easier to access format;
* Accessing a variable is also faster than reading everything from the script storage;
* List format: [uid, nickname, [staff groups]]
* @returns {void} > nothing
*/
function updateStaffClients() {
let list = [];
const keys = store.getKeys();
keys.forEach(key => {
list.push([key, store.get(key)[0], store.get(key)[1], store.get(key)[2]]);
});
staffClients = list;
}
/**
* Get the relevant staff groups from a given client
* @param {Object} client > the client object to check
* @param {Array} staffGroups > the list of all validated staff groups from the config
* @returns {Array} > the relevant staff groups of the given client
*/
function getStaffGroupsFromClient(client, staffGroups) {
let clientStaffGroups = [];
for (let staffGroup of staffGroups) {
if (isStaffGroupMember(client, staffGroup)) clientStaffGroups.push(staffGroup);
}
return clientStaffGroups;
}
/**
* Check if a client is a valid member of a given staff group from the config
* @param {Object} client > the client object to check
* @param {Object} staffGroup > the staff group object from the config to check
* @returns {Boolean} > true if the client is a valid member, otherwise false
*/
function isStaffGroupMember(client, staffGroup) {
if (staffGroup.clients.includes(client.uid())) return true;
for (let clientGroup of client.getServerGroups()) {
if (staffGroup.groups.includes(clientGroup.id())) return true;
}
return false;
}
/**
* Check if a client is counted as away/afk by checking different status of them
* @param {Object} client > the client object to check
* @returns {Boolean} > true if the client is counted as away/afk, otherwise false
*/
function isAway(client) {
return client.isAway() || (config.awayMute && client.isMuted()) || (config.awayDeaf && client.isDeaf()) || (config.awayChannel && isInAfkChannel(client));
}
/**
* Check if a client is in any afk channel which is given in the config
* @param {Object} client > the client object to check
* @returns {Boolean} > true if the client is in any afk channel, otherwise false
*/
function isInAfkChannel(client) {
for (let channel of client.getChannels()) {
if (config.afkChannels.includes(channel.id())) return true;
}
return false;
}