-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
849 lines (770 loc) · 32.4 KB
/
index.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
/*
Twitch Multigoal
Copyright © <2022> <Victor Liljeholm>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
let fs = require("fs")
let sound = require("sound-play")
let question = require("readline-sync").question
const tmi = require('tmi.js');
const defaultSettings = {
"installed": false,
"channel": "",
"username": "",
"token": "TOKEN",
"chatMessage": "",
"soundPath": "",
"soundVolume": "",
"outputString": "",
"points": 0,
"defaultGoal": 10,
"goal": 10,
"defaultGoalCount": 1,
"goalCount": 1,
"pointsPerPrimeSubscription": 1,
"pointsPerTier1Subscription": 1,
"pointsPerTier2Subscription": 2,
"pointsPerTier3Subscription": 3,
"pointsPerGiftedTier1Subscription": 1,
"pointsPerGiftedTier2Subscription": 2,
"pointsPerGiftedTier3Subscription": 3,
"shouldGiftedFromChannelCount": false,
"cheerMode": "off",
"pointsToAddPerCheer": 1,
"bitsToIncreasePoints": 500,
"controlCommandName": "!goaledit",
"difficultyMode": false,
"difficultyPointIncrease": 1,
"upgradedSubsAllowed": false,
"pointsPerUpgradedSub": 1,
"version": 5
};
let answer
const load = () =>{
if(fs.existsSync("settings.json")){
let rawData = fs.readFileSync("settings.json")
data = JSON.parse(rawData)
}else{
let fileID = fs.openSync("settings.json", "w")
fs.closeSync(fileID)
data = defaultSettings
save()
}
}
const save = () => {
let rawData = JSON.stringify(data, null, 4)
fs.writeFileSync("settings.json", rawData)
}
function saveAndExit(){
let rawData = JSON.stringify(data)
fs.writeFile("settings.json", rawData, null, () => {
exit()
})
}
const update = () =>{
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
New version found
-------------------------------------------------------------------------------------
A new version have been found and so new settings will apply and new settings might be
asked for.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
if(!data.version || data.version === 1){
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hype Chat Settings
-------------------------------------------------------------------------------------
Time to set up points for hype chats, here you can choose if hype chats should count
towards the multigoal and how much many points each level should give. There is two
modes for Hype chat, these are: \n
automatic: You set the base Hype chat level where one point should be added towards
the goal, then the scripts figure out how much other levels should give. Example if
you set it to 3, it will require three level 1 or two level 2 to get one point, or
a level 4 will give 2 points, it's all accumulative. \n
manual: You set how many points each hype level is worth, these can be decimal numbers.
these are also accumulative, so if you have one that is less then 0, let's say 0.5,
it will require two of those to get one point.\n
decimal numbers are allowed for manual mode up tp 2 decimal places, the decimal needs
to be written with a dot. So for example 1.5 and not 1,5.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
data.hypeChatsActive = question("What mode do you want for Hype chats? (off/manual/automatic): ").trim().toLowerCase()
if(data.hypeChatsActive === "manual"){
data.pointsForLevelONE = parseFloat(question("how many points should a level 1 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelTWO = parseFloat(question("how many points should a level 2 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelTHREE = parseFloat(question("how many points should a level 3 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelFOUR = parseFloat(question("how many points should a level 4 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelFIVE = parseFloat(question("how many points should a level 5 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelSIX = parseFloat(question("how many points should a level 6 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelSEVEN = parseFloat(question("how many points should a level 7 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelEIGHT = parseFloat(question("how many points should a level 8 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelNINE = parseFloat(question("how many points should a level 9 hype chat be worth?(number only, decimal allowed): ").trim())
data.pointsForLevelTEN = parseFloat(question("how many points should a level 10 hype chat be worth?(number only, decimal allowed): ").trim())
}else if(data.hypeChatsActive === "automatic"){
data.automaticBaseLevel = parseInt(question("What hype chat level should be the base for getting points? (numbers only): ").trim())
convertLevelToString()
}else{
data.hypeChatsActive = "off"
}
data.version = 2
}
if(!data.version || data.version === 2){
if("hypeChatsActive" in data){
delete data.hypeChatsActive
}
if("pointsForLevelONE" in data){
delete data.pointsForLevelONE
}
if("pointsForLevelTWO" in data){
delete data.pointsForLevelTWO
}
if("pointsForLevelTHREE" in data){
delete data.pointsForLevelTHREE
}
if("pointsForLevelFOUR" in data){
delete data.pointsForLevelFOUR
}
if("pointsForLevelFIVE" in data){
delete data.pointsForLevelFIVE
}
if("pointsForLevelSIX" in data){
delete data.pointsForLevelSIX
}
if("pointsForLevelSEVEN" in data){
delete data.pointsForLevelSEVEN
}
if("pointsForLevelEIGHT" in data){
delete data.pointsForLevelEIGHT
}
if("pointsForLevelNINE" in data){
delete data.pointsForLevelNINE
}
if("pointsForLevelTEN" in data){
delete data.pointsForLevelTEN
}
if("automaticBaseLevel" in data){
delete data.automaticBaseLevel
}
if("pointsToAddPerHypeChat" in data){
delete data.pointsToAddPerHypeChat
}
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hype Chat Settings removed
-------------------------------------------------------------------------------------
The hype chat settings have been removed as the old hype chat is no longer a thing on
twitch and is now replaced with bits.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
data.version = 3
}
if(!data.version || data.version === 3){
data.difficultyMode = false
data.difficultyPointIncrease = 1
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
New settings (Goal Increase Mode)
-------------------------------------------------------------------------------------
Settings for the new difficulty mode have been added, this mode will increase the goal
each time it has been reached, the amount it will increase by can be set when setting
up the script. By default it is off, if you want to use this feature you need to reset
the script, this can be done by using the following command in CMD: fullReset()
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
}
data.version = 4
if(!data.version || data.version === 4){
data.upgradedSubsAllowed = false
data.pointsPerUpgradedSub = 1
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"Upgraded subscription settings"
-------------------------------------------------------------------------------------
The Multigoal can now add points if someone "upgrades" their prime or gifted subscription
to a regular subscription. So you can now award people who uppgrade their subscription.
Be aware that this can create a "double" dip that month as when their subscription
renews the same month they upgraded, they will get points for that too.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
let updateUpgradedQuestion = question("You want to enabled points for 'upgraded' prime/gifted subscriptions (y/n): ").trim().toLowerCase()
if(updateUpgradedQuestion === "y"){
data.upgradedSubsAllowed = true
data.pointsPerUpgradedSub = parseInt(question("How many points should be added when someone 'uppgrades' their subscription? (number only): ").trim())
}else{
data.upgradedSubsAllowed = false
data.pointsPerUpgradedSub = 1
}
}
data.version = 5
save()
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Version update done
-------------------------------------------------------------------------------------
Your new settings is now saved and the script will continue like usual.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
}
const setup = () =>{
console.log(`
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Welcome to the setup of Twitch Multi goal and general settings
-------------------------------------------------------------------------------------
Time to set up some general settings for the multigoal. When setting up what should be
written to the output.txt file you can use the following parameters:\n
\${points} : current points.\n
\${goal} : the goal set.\n
\${goalCount} : numbers of time the goal has been reached. \n
an example would be "\${points}/\${goal} points to reach goal number #\${goalCount}"\n
This will also ask if you want to enable difficulty mode, this will increase the goal
each time it's reached by the given amount.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
data.channel = question("What is your channel name?: ").trim().toLowerCase()
data.defaultGoal = parseInt(question("How many points should be required to reach the goal?(number only): ").trim())
data.goal = data.defaultGoal
data.defaultGoalCount = parseInt(question("What count should the multigoal start at?: ").trim())
data.goalCount = data.defaultGoalCount
data.outputString = question("How should the text in output.txt be formated?: ").trim()
let difficultyModeAnswer = question("Do you want to enable difficulty mode(this will increase the goal each time its reached? (y/n): ").trim().toLowerCase()
if(difficultyModeAnswer === "y"){
data.difficultyMode = true
data.difficultyPointIncrease = parseInt(question("How much should the goal increase by each time it's reached?(number only): ").trim())
}else{
data.difficultyMode = false
}
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Subscription Settings
-------------------------------------------------------------------------------------
Time to set up points for subscription, normal sub or resub will give points when
a user "announces" it in stream, gifted points will be given out right as someone
gifts sub, if it's a multi month gifted sub the set points will be multiplied with
the number of months gifted.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
data.pointsPerPrimeSubscription = parseInt(question("how many points should a prime (re)sub be worth? (numbers only): ").trim())
data.pointsPerTier1Subscription = parseInt(question("how many points should a tier 1 (re)sub be worth? (numbers only): ").trim())
data.pointsPerTier2Subscription = parseInt(question("how many points should a tier 2 (re)sub be worth? (numbers only): ").trim())
data.pointsPerTier3Subscription = parseInt(question("how many points should a tier 3 (re)sub be worth? (numbers only): ").trim())
data.pointsPerGiftedTier1Subscription = parseInt(question("\nhow many points should one tier 1 gift sub be worth? (numbers only): ").trim())
data.pointsPerGiftedTier2Subscription = parseInt(question("how many points should one tier 2 gift sub be worth? (numbers only): ").trim())
data.pointsPerGiftedTier3Subscription = parseInt(question("how many points should one tier 3 gift sub be worth? (numbers only): ").trim())
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"Upgraded subscription settings"
-------------------------------------------------------------------------------------
Do you want to reward people who upgrade their prime or gifted subscription to a regular
subscription? Be aware that this can create a "double" dip that month as when their
subscription renews the same month they upgraded, they will get points for that too.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
let updateUpgradedQuestion = question("Do you want to enabled points for 'upgraded' prime/gifted subscriptions (y/n): ").trim().toLowerCase()
if(updateUpgradedQuestion === "y"){
data.upgradedSubsAllowed = true
data.pointsPerUpgradedSub = parseInt(question("How many points should be added when someone 'uppgrades' their subscription? (number only): ").trim())
}else{
data.upgradedSubsAllowed = false
data.pointsPerUpgradedSub = 1
}
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Cheer Settings
-------------------------------------------------------------------------------------
Time to set up points for cheers, here you can choose if cheers should count towards
the multigoal and how much needs to be cheered to increase points.
The cheer mode can be set to the following:\n
off = cheers do no not count towards multigoal.\n
accumulated = increases the counter whenever reaching "bitsToIncreasePoints" amounts
of bits total given, so several small bit amount from different people can count
towards points to the multigoal. also any overflow will be saved towards the next point.\n
single = only single amount that goes over "bitsToIncreasePoints" will add points
towards the bits. There is also no overlow.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
data.cheerMode = question("What mode do you want for cheers (info above)? (off/accumulated/single): ").trim().toLowerCase()
if(data.cheerMode !== "off"){
data.bitsToIncreasePoints = parseInt(question("How much needs to be cheered to increase the points?(number only): ").trim())
data.pointsToAddPerCheer = parseInt(question("How many points should be added when reached? (numbers only): ").trim())
}
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chat settings
-------------------------------------------------------------------------------------
Do you want a chat message to appear when a goal has been reached? For that you need
a seprate account from your channel account, with that account go grab a oauth token
from https://twitchapps.com/tmi/, it will look something like this:
oauth:1h4x0s1svsga4aif40x47bnoaa26i4 , Enter the full thing when asked. When setting up
the chat message format the following parameters can be used: \n
\${points} = current points. \n
\${goal} = the goal set. \n
\${goalCount} = the number of times the goal has been reached.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
answer = question("do you want a chat message to appear when a goal is reached? (y/n): ").trim()
if(answer.toLowerCase() === "y"){
data.username = question("Account name of the account that will announce in chat (most be seprate from channel name): ").trim().toLowerCase()
data.token = question("What is the full oath token for that account?: ").trim()
data.chatMessage = question("What should the chat message say?: ").trim()
} else {
data.username = ""
data.token = "TOKEN"
data.chatMessage = ""
}
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sound settings
-------------------------------------------------------------------------------------
Do you want a sound to play when the goal has been reached? For that you need give
the full path to a sound file, only .wav and .mp3 files is guranteed to work.
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
answer = question("do you want a sound to play when a goal is reached? (y/n): ").trim()
if(answer.toLowerCase() === "y"){
data.soundPath = question("What is the full path to the soundfile you want to play?: ").trim()
data.soundVolume = parseInt(question("Volume level (can be between 0 and 100): ").trim())/100
}
else{
data.soundPath = ""
data.soundVolume = 0
}
console.log(`\n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Command settings
-------------------------------------------------------------------------------------
There is a number of commands you or your moderator can use to control the multigoal,
these being the following:
controlCommandName reset : Resets the multigoal
controlCommandName p+ : Increases the points by 1
controlCommandName p+ NUMBER : Increases the points by NUMBER
controlCommandName p- : Decreaese the points by 1
controlCommandName p- NUMBER : Decreaess the points by NUMBER
controlCommandName g+ : Increases the number of goal reached by 1
controlCommandName g+ NUMBER : Increases the number of goal reached by NUMBER
controlCommandName g- : Decreaese the number of goal reached by 1
controlCommandName g- NUMBER : Decreaess the number of goal reached by NUMBER
-------------------------------------------------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
data.controlCommandName = question("What should the controlCommandName be to control the multigoal?: ").trim()
data.installed = true
save()
}
function convertLevelToString(){
switch(data.automaticBaseLevel){
case 1: data.automaticBaseLevel = "ONE"; break;
case 2: data.automaticBaseLevel = "TWO"; break;
case 3: data.automaticBaseLevel = "THREE"; break;
case 4: data.automaticBaseLevel = "FOUR"; break;
case 5: data.automaticBaseLevel = "FIVE"; break;
case 6: data.automaticBaseLevel = "SIX"; break;
case 7: data.automaticBaseLevel = "SEVEN"; break;
case 8: data.automaticBaseLevel = "EIGHT"; break;
case 9: data.automaticBaseLevel = "NINE"; break;
case 10: data.automaticBaseLevel = "TEN"; break;
}
}
function debugtxt(...text){
if(data.debug){
for(let i=0; i<text.length; i++){
console.log(txt[i])
}
}
}
let chat
const execute = () => {
let tokenstring
if(data.token && data.token !== "TOKEN"){
tokenstring = "with token"
chat = new tmi.Client(
{
identity: {
username: data.username,
password: data.token
},
channels: [data.channel]
}
)
}else{
tokenstring = "without token"
chat = new tmi.Client(
{
channels: [data.channel]
}
)
}
chat.connect().then(() => {
console.log(`
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
Connected to channel: ${data.channel} ${tokenstring}, ready to receive events!
If you want information on commands you can use in CMD type commands() \n
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n
`)
chat.removeAllListeners()
fileWriteHandler()
chat.on("message", (channel, tags, message, self)=>{
if(tags !== null && tags !== undefined){
if(message.split(" ")[0].toLowerCase() === data.controlCommandName.toLowerCase()){
if((tags.badges.moderator === "1" || tags.badges.broadcaster === "1")){
controlCommand(message.split(" "))
}
}
}else{
debugtxt(tags, message)
}
})
chat.on("anongiftpaidupgrade", (channel, username, userstate) =>{
if(data.upgradedSubsAllowed){
console.log(`${CurrentTime()}: Gifted upgrade, name: ${username}`)
pointsHandler("add", data.pointsPerUpgradedSub)
}
})
chat.on("giftpaidupgrade", (channel, username, sender, userstate) =>{
if(data.upgradedSubsAllowed){
console.log(`${CurrentTime()}: Gifted upgrade, name: ${username}`)
pointsHandler("add", data.pointsPerUpgradedSub)
}
})
let raw_messages = []
chat.on("raw_message", (messageCloned, message) => {
if(data.upgradedSubsAllowed && message.command === "USERNOTICE" && message.tags["msg-id"] === "primepaidupgrade"){
console.log(`${CurrentTime()}: Prime upgrade, name: ${message.tags["login"]}`)
pointsHandler("add", data.pointsPerUpgradedSub)
}
})
chat.on("cheer", (channel, userstate, message) =>{
if(data.cheerMode !== "off"){
console.log(`${CurrentTime()}: From: ${userstate["display-name"]}, cheered: ${userstate["bits"]}`)
bitsPointCalculation(parseInt(userstate["bits"]))
}
})
chat.on("subscription", (channel, username, method, message, userstate) => {
switch(userstate["msg-param-sub-plan"]){
case "Prime":{
pointsHandler("add", data.pointsPerPrimeSubscription)
break
}
case("1000"):{
pointsHandler("add", data.pointsPerTier1Subscription)
break
}
case("2000"):{
pointsHandler("add", data.pointsPerTier2Subscription)
break
}
case("3000"):{
pointsHandler("add", data.pointsPerTier3Subscription)
break
}
default:{
console.log(`${CurrentTime()}: Something went wrong reading subscription`)
}
}
console.log(`${CurrentTime()}: Subscription from: ${username}, tier: ${userstate["msg-param-sub-plan"]}`)
})
chat.on("resub", (channel, username, months, message, userstate, methods) => {
switch(userstate["msg-param-sub-plan"]){
case "Prime":{
pointsHandler("add", data.pointsPerPrimeSubscription)
break
}
case("1000"):{
pointsHandler("add", data.pointsPerTier1Subscription)
break
}
case("2000"):{
pointsHandler("add", data.pointsPerTier2Subscription)
break
}
case("3000"):{
pointsHandler("add", data.pointsPerTier3Subscription)
break
}
default:{
console.log(`${CurrentTime()}: Something went wrong reading resubscription`)
}
}
console.log(`${CurrentTime()}: Resubscription from: ${username}, tier: ${userstate["msg-param-sub-plan"]}`)
})
chat.on("subgift", (channel, username, streakMonths, recipient, methods, userstate) => {
if (username.toLowerCase() === data.channel.toLowerCase() && !data.shouldGiftedFromChannelCount) return
let giftMonths = parseInt(userstate["msg-param-gift-months"])
if(isNaN(giftMonths)){
giftMonths = 1
}
switch(userstate["msg-param-sub-plan"]){
case("1000"):{
pointsHandler("add", data.pointsPerGiftedTier1Subscription*giftMonths)
break
}
case("2000"):{
pointsHandler("add", data.pointsPerGiftedTier2Subscription*giftMonths)
break
}
case("3000"):{
pointsHandler("add", data.pointsPerGiftedTier3Subscription*giftMonths)
break
}
default:{
console.log(`${CurrentTime()}: Something went wrong reading subscription gift`)
}
}
console.log(`${CurrentTime()}: Gift Subscription from: ${username}, recipient: ${recipient}, tier: ${userstate["msg-param-sub-plan"]}, months: ${giftMonths}.`)
})
}).catch((err) => {
console.log(`${CurrentTime()}: Chat connection error`)
console.log(err)
})
}
let totalCheered = 0
function bitsPointCalculation(bits){
let timesReached = 0
switch(data.cheerMode){
default:
case "off":{
return
}
case "accumulated":{
totalCheered += bits
timesReached = Math.floor(totalCheered/data.bitsToIncreasePoints)
if(timesReached >= 1){
pointsHandler("add", timesReached*data.pointsToAddPerCheer)
totalCheered = totalCheered%data.bitsToIncreasePoints
}
break;
}
case "single":{
timesReached = Math.floor(bits/data.bitsToIncreasePoints)
if(timesReached >= 1){
pointsHandler("add", timesReached*data.pointsToAddPerCheer)
}
break;
}
}
}
let superChange = 0
let pointsHandelerTimeoutID
function pointsHandler(typeOfChange, change){
superChange += change
clearTimeout(pointsHandelerTimeoutID)
pointsHandelerTimeoutID = setTimeout(()=>{
switch(typeOfChange){
case "add":{
addPoints(superChange)
break;
}
case "remove":{
removePoints(superChange)
break
}
}
superChange = 0
}, 333)
}
const removePoints = (change) => {
data.points -= change
if (data.points < 0) {
data.goalCount -= 1
let left = Math.abs(data.points)
data.points = data.goal
if(left > 0){
pointsHandler("remove", left)
}else{
data.point = left
}
}
fileWriteHandler()
}
function calculateTimesReachedWithDifficulty(change){
if(data.goal > change) return 0;
let timesReached = 0
let currentPoints = change
while(currentPoints > 0){
if(data.goal > currentPoints){
data.points = currentPoints
return timesReached
}
currentPoints -= data.goal
timesReached += 1
data.goal += data.difficultyPointIncrease
}
data.points = currentPoints
return timesReached
}
const addPoints = (change) => {
data.points += change
let timesReached = 0
if(data.difficultyMode){
timesReached = calculateTimesReachedWithDifficulty(data.points)
}else{
timesReached = Math.floor(data.points/data.goal)
data.points = data.points%data.goal
}
if (timesReached >= 1) {
data.goalCount += timesReached
if(data.chatMessage !== "" && data.chatMessage !== null && data.chatMessage !== undefined){
chat.say(data.channel, data.chatMessage.replaceAll("${points}", data.points).replaceAll("${goal}", data.goal).replaceAll("${goalCount}", data.goalCount)).catch((err) => {console.log(err)})
}
if(data.soundPath !== "" && data.soundPath !== null && data.soundPath !== undefined){
sound.play(data.soundPath, data.soundVolume).catch((err)=>{
console.log("sound error:")
console.log(err)
})
}
fileWriteHandler()
}else{
fileWriteHandler()
}
}
function controlCommand(words){
if (words.length === 1) {
console.log(`${CurrentTime()}: ${data.controlCommandName} needs a parameter/option`)
return
}
switch(words[1].toLowerCase()){
case("reset"):{
resetGoal()
break
}
case("p+"):{
if(words.length === 2){
pointsHandler("add", 1)
}
else if(words.length === 3 && !isNaN(words[2])){
pointsHandler("add", Math.floor(words[2]))
}
else{
pointsHandler("add", 1)
}
break
}
case("p-"):{
if(words.length === 2){
pointsHandler("remove", 1)
}
else if(words.length === 3 && !isNaN(words[2])){
pointsHandler("remove", Math.floor(words[2]))
}
else{
pointsHandler("remove", 1)
}
break
}
case("g+"):{
if(words.length === 2){
addGoals(1)
}
else if(words.length === 3 && !isNaN(words[2])){
addGoals(Math.floor(words[2]))
}
else{
addGoals(1)
}
break
}
case("g-"):{
if(words.length === 2){
removeGoals(1)
}
else if(words.length === 3 && !isNaN(words[2])){
removeGoals(Math.floor(words[2]))
}
else{
removeGoals(1)
}
break
}
default:{
console.log(`${CurrentTime()}: ${words[1]} is not a valid option for ${data.controlCommandName}`)
return
}
}
}
const CurrentTime = () => {
return new Date().toLocaleTimeString()
}
const resetGoal = () => {
data.points = 0
data.goalCount = data.defaultGoalCount
data.goal = data.defaultGoal
totalCheered = 0
fileWriteHandler()
}
const addGoals = (change) => {
data.goalCount += change
fileWriteHandler()
}
const removeGoals = (change) => {
data.goalCount -= change
fileWriteHandler()
}
const fileWriteHandler = async () => {
let outstring = data.outputString
outstring = outstring.replaceAll("${points}", data.points).replaceAll("${goal}", data.goal).replaceAll("${goalCount}", data.goalCount)
fs.writeFile("output.txt", outstring, function (err) {
if (err){
console.log(`${CurrentTime()}: file write error: `)
console.log(err)
}else{
console.log(`${CurrentTime()}:"${outstring}" written to output.txt`)
}
})
save()
}
const exit = () => {
save()
console.log("Exiting!")
process.exit(0)
}
const test = (level) =>{
hypeChatManager(level)
}
const fullReset = () => {
if(answer === "y"){
data = defaultSettings
saveAndExit()
}
}
const commands = () => {
console.log(`
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
addPoints(x) : add x number of points.
removePoints(x) : remove x number of points.
addGoals(x) : add x number of goals reached.
removeGoals(x) : remove x number of goals reached.
resetGoal(): resets the multigoal.
exit() : End the program.
fullReset(): Will fully reset your settings and quit out
of the script, the next time you start it it will prompt
you for what settings you want again.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
`)
}
load()
if(!data.installed){
setup()
}else{
if(!data.version || data.version < 5){
update()
}
answer = question("Do you want to reset the multigoal (points and goal count)? (y/n): ")
if(answer === "y"){
resetGoal()
}
}
execute()