forked from Abev08/TwitchBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
1026 lines (961 loc) · 57 KB
/
Config.cs
File metadata and controls
1026 lines (961 loc) · 57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Windows.Input;
using Serilog;
namespace AbevBot;
public static class Config
{
public enum Keys
{
ChannelName, ChannelID,
ConsoleVisible, PeriodicMessageTimeInterval, PeriodicMessageMinChatMessages, StartVideoEnabled,
AlwaysReadTTSFromThem, OverpoweredInFight,
SongRequestTimeout,
DiscordMessageOnline,
HotkeyNotificationPause, HotkeyNotificationSkip,
PrintChatMessagesToConsole,
GambaMinimalChatMessages,
FightMinimalChatMessages,
Enable, ChatMessage, TextToDisplay, TextPosition, TextSize, TextToSpeech, SoundToPlay, VideoToPlay, VideoPosition, VideoSize, MinimumRaiders, DoShoutout, MinimumDuration, MinimumBitsForTTS, Amount,
ChannelRedemption_RandomVideo_ID, ChannelRedemption_RandomVideo_MarkAsFulfilled, ChannelRedemption_SongRequest_ID, ChannelRedemption_SongRequest_MarkAsFulfilled, ChannelRedemption_SongSkip_ID, ChannelRedemption_SongSkip_MarkAsFulfilled,
ChannelRedemption_RandomVideo_Size, ChannelRedemption_RandomVideo_Position,
ChannelRedemption_ID, ChannelRedemption_KeyAction, ChannelRedemption_KeyActionType, ChannelRedemption_KeyActionAfterTime, ChannelRedemption_KeyActionAfterTimeType, ChannelRedemption_ChatMessage, ChannelRedemption_TextToDisplay, ChannelRedemption_TextPosition, ChannelRedemption_TextToSpeech, ChannelRedemption_SoundToPlay, ChannelRedemption_VideoToPlay, ChannelRedemption_MarkAsFulfilled,
msg
};
private const string FILENAME = "Config.ini";
private static Dictionary<Keys, string> _Data;
public static Dictionary<Keys, string> Data
{
get
{
if (_Data is null)
{
_Data = new();
foreach (var key in Enum.GetValues(typeof(Keys)))
{
_Data.Add((Keys)key, string.Empty);
}
}
return _Data;
}
}
public static bool ConsoleVisible { get; private set; }
public static bool StartVideoEnabled { get; private set; } = true;
public static bool VolumeValuesDirty { get; set; }
public static float VolumeAudio { get; set; }
public static float VolumeVideo { get; set; }
private static DateTime ConfigFileTimestamp;
public static DateTime BroadcasterLastOnline;
public static DateTime BroadcasterLastOnlineCheck { get; set; }
public static TimeSpan BroadcasterOnlineCheckInterval { get; } = TimeSpan.FromMinutes(3);
public static TimeSpan BroadcasterOfflineTimeout { get; } = TimeSpan.FromMinutes(30);
public static readonly List<Key> HotkeysForPauseNotification = new();
public static readonly List<Key> HotkeysForSkipNotification = new();
/// <summary> Is audio output of main window disabled? </summary>
public static bool WindowAudioDisabled { get; set; }
public static bool TestFeatureDisabled { get; set; }
public static bool ParseConfigFile(bool reload = false)
{
if (reload) { Log.Information("Reloading {file} file.", FILENAME); }
else { Log.Information("Reading {file} file.", FILENAME); }
// Create resources folders just for user convenience (if they don't exist)
DirectoryInfo dir = new(Notifications.SOUNDS_PATH);
if (!dir.Exists) dir.Create();
dir = new DirectoryInfo(Notifications.RANDOM_VIDEO_PATH);
if (!dir.Exists) dir.Create();
Chat.PeriodicMessages.Clear(); // Clear previous preiodic messages
Chatter.AlwaysReadTTSFromThem.Clear();
Chatter.OverpoweredInFight.Clear();
Notifications.ChannelRedemptions.Clear();
HotkeysForPauseNotification.Clear();
HotkeysForSkipNotification.Clear();
foreach (var config in Notifications.Configs) { config.Value.Reset(); }
Notifications.RandomVideoParameters?.Reset();
Notifications.CheerRangeNotifications.Clear();
// Create example Config.ini
FileInfo configFile = new("Config_example.ini");
CreateConfigFile(configFile, true);
// Create real Config.ini
configFile = new(FILENAME);
if (configFile.Exists == false)
{
CreateConfigFile(configFile);
return true;
}
else
{
string line;
int lineIndex = 0, indexOf;
bool result;
object position;
string[] text = new string[2];
string temp;
int temp2;
ChannelRedemption redemption = null;
string[] keys;
TimeSpan timeSpan;
NotificationsConfig currentNotifConfig = null;
// FileShare.ReadWrite needs to be used because it have to allow other processes to write into the file
using FileStream fileStream = new(configFile.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using StreamReader reader = new(fileStream);
while ((line = reader.ReadLine()) != null)
{
lineIndex++;
line = line.Trim();
// Skip commented out lines
if (line.StartsWith("//") || line.StartsWith(';') || line.StartsWith('#') || string.IsNullOrWhiteSpace(line)) continue;
// check for group heading
if (line.EndsWith(':'))
{
// Special check if previously configured notification was CheerRange - it should be added to notifications list
if (currentNotifConfig?.Type == NotificationType.CHEERRANGE) { Notifications.CheerRangeNotifications.Add(currentNotifConfig); }
if (!Notifications.Configs.TryGetValue(line[..^1], out currentNotifConfig))
{
Log.Warning("Bad config line {index}. Group header not recognized!", lineIndex);
currentNotifConfig = null;
}
// If configuring new CheerRange notification create new one - it would be added to CheerRange notifications list
if (currentNotifConfig?.Type == NotificationType.CHEERRANGE) { currentNotifConfig = new(NotificationType.CHEERRANGE); }
continue;
}
indexOf = line.IndexOf('=');
if (indexOf > 0)
{
text[0] = line[..indexOf].Trim();
text[1] = line[(indexOf + 1)..].Trim();
indexOf = text[1].IndexOf(';');
if (indexOf >= 0) text[1] = text[1][..indexOf].Trim();
text[1] = text[1].Replace("\"", "").Trim();
}
object key;
if (Enum.TryParse(typeof(Keys), text[0], out key))
{
switch ((Keys)key)
{
case Keys.ChannelName:
Data[(Keys)key] = text[1].Trim().ToLower();
break;
case Keys.ConsoleVisible:
if (bool.TryParse(text[1], out result)) ConsoleVisible = result;
break;
case Keys.PeriodicMessageTimeInterval:
if (TimeSpan.TryParse(text[1], out timeSpan))
{
if (timeSpan.TotalSeconds > 0) Chat.PeriodicMessageInterval = TimeSpan.FromTicks(timeSpan.Ticks);
}
break;
case Keys.PeriodicMessageMinChatMessages:
if (int.TryParse(text[1], out temp2))
{
if (temp2 >= 0) Chat.PeriodicMessageMinChatMessages = temp2;
}
break;
case Keys.SongRequestTimeout:
if (TimeSpan.TryParse(text[1], out timeSpan))
{
Spotify.SongRequestTimeout = TimeSpan.FromTicks(timeSpan.Ticks);
}
break;
case Keys.StartVideoEnabled:
if (bool.TryParse(text[1], out result)) StartVideoEnabled = result;
break;
case Keys.DiscordMessageOnline:
Discord.CustomOnlineMessage = text[1].Trim();
break;
case Keys.PrintChatMessagesToConsole:
if (bool.TryParse(text[1], out result)) { Chat.PrintChatMessages = result; }
else { Log.Warning("Keycode: {key} not recognized as boolean value in line {index} in Config.ini file.", text[1], lineIndex); }
break;
case Keys.HotkeyNotificationPause:
keys = text[1].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
foreach (string k in keys)
{
if (Enum.TryParse(typeof(Key), k, out position)) HotkeysForPauseNotification.Add((Key)position);
else Log.Warning("Keycode: {key} not recognized in line {index} in Config.ini file.", k, lineIndex);
}
break;
case Keys.HotkeyNotificationSkip:
keys = text[1].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
foreach (string k in keys)
{
if (Enum.TryParse(typeof(Key), k, out position)) HotkeysForSkipNotification.Add((Key)position);
else Log.Warning("Keycode: {key} not recognized in line {index} in Config.ini file.", k, lineIndex);
}
break;
case Keys.GambaMinimalChatMessages:
if (bool.TryParse(text[1], out result)) { MinigameGamba.MinimalChatMessages = result; }
else { Log.Warning("Keycode: {key} not recognized as boolean value in line {index} in Config.ini file.", text[1], lineIndex); }
break;
case Keys.FightMinimalChatMessages:
if (bool.TryParse(text[1], out result)) { MinigameFight.MinimalChatMessages = result; }
else { Log.Warning("Keycode: {key} not recognized as boolean value in line {index} in Config.ini file.", text[1], lineIndex); }
break;
case Keys.Enable:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (bool.TryParse(text[1], out result)) currentNotifConfig.Enable = result;
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
break;
case Keys.ChatMessage:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else currentNotifConfig.ChatMessage = text[1].Trim();
break;
case Keys.TextToDisplay:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else currentNotifConfig.TextToDisplay = text[1].Trim();
break;
case Keys.TextPosition:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (Enum.TryParse(typeof(Notifications.TextPosition), text[1].Trim(), out position)) currentNotifConfig.TextPosition = (Notifications.TextPosition)position;
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
break;
case Keys.TextSize:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (text[1].Length > 0)
{
string separator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
string numString = text[1];
if (separator == ",") numString = numString.Replace('.', ',');
else if (separator == ".") numString = numString.Replace(',', '.');
if (double.TryParse(numString, out double size) && size >= 0.1) currentNotifConfig.TextSize = size;
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
}
break;
case Keys.TextToSpeech:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else currentNotifConfig.TextToSpeech = text[1].Trim();
break;
case Keys.SoundToPlay:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (text[1].Length > 0) currentNotifConfig.SoundToPlay = $"Resources\\{text[1].Trim()}";
break;
case Keys.VideoToPlay:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (text[1].Length > 0) currentNotifConfig.VideoToPlay = $"Resources\\{text[1].Trim()}";
break;
case Keys.VideoPosition:
if (currentNotifConfig is null) { Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex); }
else if (text[1].Length > 0)
{
var stringNums = text[1].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (stringNums.Length == 2)
{
var nums = new double[stringNums.Length];
bool ok = true;
for (int i = 0; i < stringNums.Length; i++)
{
if (!double.TryParse(stringNums[i], out nums[i]))
{
Log.Warning("Bad config line {index}. Value {val} not recognized!", lineIndex, i + 1);
ok = false;
}
}
if (ok)
{
if (currentNotifConfig.VideoParams is null) currentNotifConfig.VideoParams = new();
currentNotifConfig.VideoParams.Left = nums[0];
currentNotifConfig.VideoParams.Top = nums[1];
}
}
else Log.Warning("Bad config line {index}. Not enough or too many values!", lineIndex);
}
break;
case Keys.VideoSize:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (text[1].Length > 0)
{
var stringNums = text[1].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (stringNums.Length == 2)
{
var nums = new double[stringNums.Length];
bool ok = true;
for (int i = 0; i < stringNums.Length; i++)
{
if (!double.TryParse(stringNums[i], out nums[i]))
{
Log.Warning("Bad config line {index}. Value {val} not recognized!", lineIndex, i + 1);
ok = false;
}
}
if (ok)
{
// check the aspect ratio
if (nums[0] / 16 > nums[1] / 9) { nums[0] = (nums[1] / 9) * 16; }
else { nums[1] = (nums[0] / 16) * 9; }
if (currentNotifConfig.VideoParams is null) currentNotifConfig.VideoParams = new();
currentNotifConfig.VideoParams.Width = nums[0];
currentNotifConfig.VideoParams.Height = nums[1];
}
}
else Log.Warning("Bad config line {index}. Not enough or too many values!", lineIndex);
}
break;
case Keys.MinimumRaiders:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (text[1].Length > 0)
{
if (int.TryParse(text[1], out temp2)) currentNotifConfig.MinimumRaiders = temp2;
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
}
break;
case Keys.DoShoutout:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (bool.TryParse(text[1], out result)) currentNotifConfig.DoShoutout = result;
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
break;
case Keys.MinimumDuration:
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (text[1].Length > 0)
{
if (TimeSpan.TryParse(text[1], out timeSpan)) currentNotifConfig.MinimumTime = TimeSpan.FromTicks(timeSpan.Ticks);
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
}
break;
case Keys.MinimumBitsForTTS:
if (text[1].Length > 0)
{
if (currentNotifConfig is null) Log.Warning("Bad config line {index}. Missing previous group header definition!", lineIndex);
else if (int.TryParse(text[1], out temp2)) currentNotifConfig.MinimumBits = temp2;
else Log.Warning("Bad config line {index}. Value not recognized!", lineIndex);
}
break;
case Keys.Amount:
var tmp = text[1].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
if (tmp.Length == 1)
{
if (int.TryParse(tmp[0], out int v1))
{
currentNotifConfig.BitsRange[0] = v1;
currentNotifConfig.BitsRange[1] = v1;
}
else { Log.Warning("Bad config line {index}. Value not recognized!", lineIndex); }
}
else if (tmp.Length != 2) { Log.Warning("Bad config line {index}. Value not recognized!", lineIndex); }
else
{
if (int.TryParse(tmp[0], out int v1) && int.TryParse(tmp[1], out int v2))
{
if (v1 > v2) { Log.Warning("Bad config line {index}. Upper range is smaller than lower range!", lineIndex); }
else
{
currentNotifConfig.BitsRange[0] = v1;
currentNotifConfig.BitsRange[1] = v2;
}
}
else { Log.Warning("Bad config line {index}. Value not recognized!", lineIndex); }
}
break;
case Keys.ChannelRedemption_ID:
if (text[1].Length > 0)
{
temp = text[1].Trim();
redemption = null;
for (int i = 0; i < Notifications.ChannelRedemptions.Count; i++)
{
if (Notifications.ChannelRedemptions[i].ID.Equals(temp))
{
redemption = Notifications.ChannelRedemptions[i];
break;
}
}
if (redemption is null)
{
redemption = new() { ID = temp };
Notifications.ChannelRedemptions.Add(redemption);
}
}
break;
case Keys.ChannelRedemption_KeyAction:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
keys = text[1].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
foreach (string k in keys)
{
if (Enum.TryParse(typeof(Key), k, out position)) redemption.KeysToPress.Add((Key)position);
else Log.Warning("Keycode: {key} not recognized in line {index} in Config.ini file.", k, lineIndex);
}
break;
case Keys.ChannelRedemption_KeyActionType:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
if (Enum.TryParse(typeof(KeyActionType), text[1].Trim(), out position)) redemption.KeysToPressType = (KeyActionType)position;
break;
case Keys.ChannelRedemption_KeyActionAfterTime:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
keys = text[1].Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
if (int.TryParse(keys[0], out temp2)) redemption.TimeToPressSecondAction = TimeSpan.FromMilliseconds(temp2);
else Log.Warning("Action time {key} not recognized in line {index} in Config.ini file.", keys[0], lineIndex);
keys[0] = string.Empty;
foreach (string k in keys)
{
if (k?.Length == 0) continue;
if (Enum.TryParse(typeof(Key), k, out position)) redemption.KeysToPressAfterTime.Add((Key)position);
else Log.Warning("Keycode: {key} not recognized in line {index} in Config.ini file.", k, lineIndex);
}
break;
case Keys.ChannelRedemption_KeyActionAfterTimeType:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
if (Enum.TryParse(typeof(KeyActionType), text[1].Trim(), out position)) redemption.KeysToPressAfterTimeType = (KeyActionType)position;
break;
case Keys.ChannelRedemption_ChatMessage:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
redemption.Config.ChatMessage = text[1].Trim();
break;
case Keys.ChannelRedemption_TextToDisplay:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
redemption.Config.TextToDisplay = text[1].Trim();
break;
case Keys.ChannelRedemption_TextPosition:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
if (Enum.TryParse(typeof(Notifications.TextPosition), text[1].Trim(), out position)) redemption.Config.TextPosition = (Notifications.TextPosition)position;
break;
case Keys.ChannelRedemption_TextToSpeech:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
redemption.Config.TextToSpeech = text[1].Trim();
break;
case Keys.ChannelRedemption_SoundToPlay:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
if (text[1].Length > 0) redemption.Config.SoundToPlay = $"Resources\\{text[1].Trim()}";
break;
case Keys.ChannelRedemption_VideoToPlay:
if (text[1].Length == 0) continue;
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
if (text[1].Length > 0) redemption.Config.VideoToPlay = $"Resources\\{text[1].Trim()}";
break;
case Keys.ChannelRedemption_MarkAsFulfilled:
if (redemption is null)
{
Log.Warning("Bad config line {index}. Missing previous ID filed declaration!", lineIndex);
continue;
}
if (bool.TryParse(text[1], out result)) redemption.MarkAsFulfilled = result;
break;
case Keys.msg:
// If there are '=' symbols in the message the previous splitting would brake it
string msg = line.Substring(line.IndexOf('=') + 1).Trim();
if (msg.Length > 0) Chat.PeriodicMessages.Add(msg);
break;
case Keys.ChannelRedemption_RandomVideo_ID:
case Keys.ChannelRedemption_SongRequest_ID:
case Keys.ChannelRedemption_SongSkip_ID:
Data[(Keys)key] = text[1].Trim();
break;
case Keys.ChannelRedemption_RandomVideo_MarkAsFulfilled:
case Keys.ChannelRedemption_SongRequest_MarkAsFulfilled:
case Keys.ChannelRedemption_SongSkip_MarkAsFulfilled:
if (bool.TryParse(text[1], out result)) Data[(Keys)key] = result.ToString();
break;
case Keys.AlwaysReadTTSFromThem:
Chatter.AlwaysReadTTSFromThem.AddRange(text[1].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries));
break;
case Keys.OverpoweredInFight:
Chatter.OverpoweredInFight.AddRange(text[1].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries));
break;
case Keys.ChannelRedemption_RandomVideo_Size:
if (text[1].Length > 0)
{
var stringNums = text[1].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (stringNums.Length == 2)
{
var nums = new double[stringNums.Length];
bool ok = true;
for (int i = 0; i < stringNums.Length; i++)
{
if (!double.TryParse(stringNums[i], out nums[i]))
{
Log.Warning("Bad config line {index}. Value {val} not recognized!", lineIndex, i + 1);
ok = false;
}
}
if (ok)
{
// check the aspect ratio
if (nums[0] / 16 > nums[1] / 9) { nums[0] = (nums[1] / 9) * 16; }
else { nums[1] = (nums[0] / 16) * 9; }
if (Notifications.RandomVideoParameters is null) Notifications.RandomVideoParameters = new();
Notifications.RandomVideoParameters.Width = nums[0];
Notifications.RandomVideoParameters.Height = nums[1];
}
}
else Log.Warning("Bad config line {index}. Not enough or too many values!", lineIndex);
}
break;
case Keys.ChannelRedemption_RandomVideo_Position:
if (text[1].Length > 0)
{
var stringNums = text[1].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
if (stringNums.Length == 2)
{
var nums = new double[stringNums.Length];
bool ok = true;
for (int i = 0; i < stringNums.Length; i++)
{
if (!double.TryParse(stringNums[i], out nums[i]))
{
Log.Warning("Bad config line {index}. Value {val} not recognized!", lineIndex, i + 1);
ok = false;
}
}
if (ok)
{
if (Notifications.RandomVideoParameters is null) Notifications.RandomVideoParameters = new();
Notifications.RandomVideoParameters.Left = nums[0];
Notifications.RandomVideoParameters.Top = nums[1];
}
}
else Log.Warning("Bad config line {index}. Not enough or too many values!", lineIndex);
}
break;
default:
if (Data.ContainsKey((Keys)key)) { Data[(Keys)key] = text[1].Trim(); }
else Log.Warning("Not recognized key '{key}' on line {index} in Config.ini file.", text[0], lineIndex);
break;
}
}
else { Log.Warning("Not recognized key '{key}' on line {index} in Config.ini file.", text[0], lineIndex); }
}
// Check if all needed data was read
if (Data[Keys.ChannelName].Length == 0)
{
Log.Error("Missing required info in {file} file.\r\nLook inside \"Required information in {file}\" section in README for help.\r\nYou can delete {file} file to generate new one. ! WARNING - ALL DATA INSIDE IT WILL BE LOST !", FILENAME, FILENAME, FILENAME);
return true;
}
// Nothing is missing, do some setup things
Log.Information("Loaded {count} periodic messages.", Chat.PeriodicMessages.Count);
}
ConfigFileTimestamp = configFile.LastWriteTime;
return false;
}
/// <summary> Creates new Config.ini file. </summary>
/// <param name="file">FileInfo object describing file parameters</param>
/// <param name="example">Is this example Config.ini file?</param>
private static void CreateConfigFile(FileInfo file, bool example = false)
{
using (StreamWriter writer = new(file.FullName))
{
if (example)
{
writer.WriteLine();
writer.WriteLine("; CAUTION");
writer.WriteLine("; ----------------------------------------------------------------------");
writer.WriteLine("; ---------------------------------------------------------------------");
writer.WriteLine("; EXAMPLE CONFIG.INI FILE, WILL BE OVERRIDEN EVERY TIME THE BOT IS RUN");
writer.WriteLine("; ---------------------------------------------------------------------");
writer.WriteLine("; ----------------------------------------------------------------------");
writer.WriteLine();
writer.WriteLine();
}
writer.WriteLine("; Required things, needs to be filled in.");
writer.WriteLine("; Channel name the bot should connect to.");
writer.WriteLine(string.Concat(Keys.ChannelName.ToString(), " = "));
writer.WriteLine();
writer.WriteLine();
writer.WriteLine($"; Sound samples such as farts, laughs, applauses, etc. should be placed in the \"{Notifications.SOUNDS_PATH}\" folder,");
writer.WriteLine("; to be used in TTS messages like this \"!tts -laugh\" - calling the file name with \"-\" symbol in front of it.");
writer.WriteLine(";");
writer.WriteLine($"; Videos that can be played via random video channel point redemption should be placed in the \"{Notifications.RANDOM_VIDEO_PATH}\" folder.");
writer.WriteLine();
writer.WriteLine();
writer.WriteLine("; --------------------------------------------------");
writer.WriteLine("; Additional things, can be left unchanged.");
writer.WriteLine("; --------------------------------------------------");
writer.WriteLine();
writer.WriteLine();
writer.WriteLine("; Internal bot configuration.");
writer.WriteLine("; Debug console visibility. Default: false");
writer.WriteLine(string.Concat(Keys.ConsoleVisible.ToString(), " = false"));
writer.WriteLine("; Periodic messages time interval (HH:MM:SS format -> 1 hour: 1:00:00, 1 minute 0:01:00, 1 second: 0:00:01). Default: empty - 10 minutes");
writer.WriteLine(string.Concat(Keys.PeriodicMessageTimeInterval.ToString(), " = "));
writer.WriteLine("; Minimum number of chat messages between periodic messages. Default: empty - 10 messages. 0 - disabled");
writer.WriteLine(string.Concat(Keys.PeriodicMessageMinChatMessages.ToString(), " = "));
writer.WriteLine("; Starting video when the bot is run. Default: true");
writer.WriteLine(string.Concat(Keys.StartVideoEnabled.ToString(), " = true"));
writer.WriteLine("; Comma separated list of user names from which TTS messages will ALWAYS be read (even when !tts chat is turned off)");
writer.WriteLine(string.Concat(Keys.AlwaysReadTTSFromThem.ToString(), " = AbevBot, Abev08"));
writer.WriteLine("; Comma separated list of user names that will be overpowered in !fight minigame");
writer.WriteLine(string.Concat(Keys.OverpoweredInFight.ToString(), " = Abev08"));
writer.WriteLine("; Song request timeout from the same user (HH:MM:SS format -> 1 hour: 1:00:00, 1 minute 0:01:00, 1 second: 0:00:01). Default: empty - 2 minutes");
writer.WriteLine(string.Concat(Keys.SongRequestTimeout.ToString(), " = "));
writer.WriteLine("; Discord message that will be sent when the stream goes online. Default: empty - \"Hello @everyone, stream just started https://twitch.tv/{ChannelName} ! {title}\"");
writer.WriteLine("; The \"{title}\" part of the message will be replaced with current stream title and can be used in custom online message specified below.");
writer.WriteLine(string.Concat(Keys.DiscordMessageOnline.ToString(), " = "));
writer.WriteLine("; Print chat messages to console window. Default: true");
writer.WriteLine(string.Concat(Keys.PrintChatMessagesToConsole.ToString(), " = true"));
writer.WriteLine("; Use minimal gamba minigame chat messages (ugly but less spammy). Default: false");
writer.WriteLine(string.Concat(Keys.GambaMinimalChatMessages.ToString(), " = false"));
writer.WriteLine("; Use minimal fight minigame chat messages (ugly but less spammy). Default: false");
writer.WriteLine(string.Concat(Keys.FightMinimalChatMessages.ToString(), " = false"));
writer.WriteLine();
writer.WriteLine("; Hotkeys configuration");
writer.WriteLine("; Each hotkey is comma separated list of keyboard keys that should be pressed for hotkey action to be activated.");
writer.WriteLine("; The keys needs to be written in according to: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.key");
writer.WriteLine("; For each hotkey - default: empty - inactive");
writer.WriteLine(string.Concat(Keys.HotkeyNotificationPause.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.HotkeyNotificationSkip.ToString(), " = "));
writer.WriteLine();
writer.WriteLine();
writer.WriteLine("; Event messages configuration.");
writer.WriteLine("; Empty assignment means that this part of the notification would be disabled or default value would be used.");
writer.WriteLine("; TextPosition - available options: TOPLEFT, TOP, TOPRIGHT, LEFT, CENTER, RIGHT, BOTTOMLEFT, BOTTOM, BOTTOMRIGHT, VIDEOABOVE, VIDEOCENTER, VIDEOBELOW.");
writer.WriteLine("; TextSize - displayed text size. Default: empty - 48");
writer.WriteLine("; Paths to sounds and videos are relative to Resources folder.");
writer.WriteLine("; For a file that is placed directly in Resources folder it would be just a filename with it's extension.");
writer.WriteLine("; VideoPosition - describes played video position from the top left corner in pixels. 2 values separated by a comma are needed.");
writer.WriteLine("; VideoSize - describes played video size in pixels. 2 values separated by a comma are needed. The aspect ratio is preserved. The best way is to set the width to some high value and shrink the video by chaning the height.");
writer.WriteLine("; Use below expressions to insert data into messages:");
writer.WriteLine("; {0} - user name that followed, subscribed, gifted subscriptions, etc.");
writer.WriteLine("; {1} - subscription tier");
writer.WriteLine("; {2} - subscription duration in advance, for example subscribed for next 3 months (only in extended subscription message)");
writer.WriteLine("; {3} - subscription streak, for example subscribed for 10 months in a row (only in extended subscription message)");
writer.WriteLine("; {4} - gifted subscription count, cheered bits count, raiders count");
writer.WriteLine("; {5} - cumulative subscription months (only in extended subscription message)");
writer.WriteLine("; {6} - comma separated list of user names that received gift subscription");
writer.WriteLine("; {7} - attached message");
writer.WriteLine("; {10} - if {2} > 1 then it is set to 's', otherwise empty");
writer.WriteLine("; {11} - if {3} > 1 then it is set to 's', otherwise empty");
writer.WriteLine("; {12} - if {4} > 1 then it is set to 's', otherwise empty");
writer.WriteLine("; {13} - if {5} > 1 then it is set to 's', otherwise empty");
writer.WriteLine("; Using index out of supported range WILL CRASH THE BOT!");
writer.WriteLine();
writer.WriteLine("; ----- Follow");
writer.WriteLine("Follow:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = true"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = @{0} thank you for following!"));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = New follower {0}!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Subscription (notification message, always received when someone subscribes even when the subscriber doesn't want it to be public)");
writer.WriteLine("Subscription:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = false"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = {0} just subscribed!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = Thank you {0} for tier {1} sub! {7}"));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = peepoHey.mp4"));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Subscription Extended Message (the subscriber shares that he subscribed)");
writer.WriteLine("SubscriptionExt:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = true"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = {0} just subscribed!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = Thank you {0} for {2} month{10} in advance tier {1} sub! It is your {3} month in a row! {7}"));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = peepoHey.mp4"));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Subscription gifted (the user is gifting subscriptions)");
writer.WriteLine("SubscriptionGift:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = true"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = Thank you {0} for {4} sub{12}!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = Thank you {0} for gifting {4} tier {1} sub{12} to {6}! {7}"));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = peepoHey.mp4"));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Subscription gift received (the user received subscription gift, these events are sent before or after subscription gifted event)");
writer.WriteLine("SubscriptionGiftReceived:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = false"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = New subscriber {0}!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Bits cheer");
writer.WriteLine("; Default notification");
writer.WriteLine("Cheer:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = true"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = Thank you {0} for {4} bit{12}!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = Thank you {0} for {4} bit{12}! {7}"));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine("; The minimum amount of bits thrown for the message to be read as TTS. Default: empty - 10");
writer.WriteLine(string.Concat(Keys.MinimumBitsForTTS.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; Custom cheer notifications (related to amount of bits)");
writer.WriteLine("; When cheer event is received first custom notifications are inspected if cheer amount mathes");
writer.WriteLine("; if none of custom cheer notifications is valid the default cheer notification is played");
writer.WriteLine("; You can have multiple custom cheer notifications - just start new one with \"CheerRange:\" header");
writer.WriteLine("; In the Amount field you can specify a value on which the notification would be played");
writer.WriteLine("; or a range on which the custom notification is valid. Examples:");
writer.WriteLine("; - play notification on 1234 bits: \"Amount = 1234\"");
writer.WriteLine("; - play notification on bits in range 100 - 1000: \"Amount = 100, 1000\"");
writer.WriteLine("; If bits range in different CheerRange notifications overlaps the first one configured is played");
writer.WriteLine("CheerRange:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = false"));
writer.WriteLine(string.Concat(Keys.Amount.ToString(), " = 123, 234"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = {0} cheered with {4} bit{12} which is in range of magic numbers! {7}"));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Raid (channel got raided)");
writer.WriteLine("Raid:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = true"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = {4} raider{12} from {0} are coming!"));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine("; Default empty -> minimum raiders 10.");
writer.WriteLine(string.Concat(Keys.MinimumRaiders.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.DoShoutout.ToString(), " = true"));
writer.WriteLine();
writer.WriteLine("; ----- Chatter timeout");
writer.WriteLine("Timeout:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = false"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine("; Minimum timeout duration (HH:MM:SS format -> 1 hour: 1:00:00, 1 minute 0:01:00, 1 second: 0:00:01). Default: empty - 0 seconds");
writer.WriteLine(string.Concat(Keys.MinimumDuration.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Chatter ban");
writer.WriteLine("Ban:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = false"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = tone1.wav"));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- On screen celebration (channel redemption with bits)");
writer.WriteLine("OnScreenCelebration:");
writer.WriteLine(string.Concat(Keys.Enable.ToString(), " = true"));
writer.WriteLine(string.Concat(Keys.ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToDisplay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextPosition.ToString(), " = TOP"));
writer.WriteLine(string.Concat(Keys.TextSize.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.TextToSpeech.ToString(), " = funny: {0} fired up a celebration. {7}"));
writer.WriteLine(string.Concat(Keys.SoundToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.VideoSize.ToString(), " = "));
writer.WriteLine();
writer.WriteLine();
writer.WriteLine("; Channel points redemptions. Assign channel point redemption ID.");
writer.WriteLine("; If the bot receives a channel point redemption event message that is not recognized (not configured),");
writer.WriteLine("; the message will get printed to the bot's console window.");
writer.WriteLine("; You can search the message for the ID and configure propper notification for it.");
writer.WriteLine("; If the console window is not visible search for 'ConsoleVisible' field in this configuration file.");
writer.WriteLine($"; ----- Plays random video from {Notifications.RANDOM_VIDEO_PATH} folder.");
writer.WriteLine(string.Concat(Keys.ChannelRedemption_RandomVideo_ID.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_RandomVideo_MarkAsFulfilled.ToString(), " = false"));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_RandomVideo_Position.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_RandomVideo_Size.ToString(), " = "));
writer.WriteLine();
writer.WriteLine("; ----- Adds provided song (Spotify link) to song queue.");
writer.WriteLine(string.Concat(Keys.ChannelRedemption_SongRequest_ID.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_SongRequest_MarkAsFulfilled.ToString(), " = false"));
writer.WriteLine();
writer.WriteLine("; ----- Skips current Spotify song.");
writer.WriteLine(string.Concat(Keys.ChannelRedemption_SongSkip_ID.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_SongSkip_MarkAsFulfilled.ToString(), " = false"));
writer.WriteLine();
writer.WriteLine("; ----- Custom channel points redemptions.");
writer.WriteLine("; The configuration group has to start with ID filed.");
writer.WriteLine("; Multiple groups are allowed. Just copy the group and start with ID field.");
writer.WriteLine("; Other available fields after ID fileds are referencing last assigned ID field.");
writer.WriteLine("; This means that for example setting chat message 2 times after assigning ID would override each other.");
writer.WriteLine("; Unused fields can be skipped (deleted from Config.ini).");
writer.WriteLine("; KeyAction is comma separated list of keyboard keys that should be pressed when the channel redemption happens.");
writer.WriteLine("; KeyActionAfterTime first value is time in miliseconds after which the action should be performed, next is comma separated list of keyboard keys that should be pressed.");
writer.WriteLine("; The keys needs to be written in according to: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.key");
writer.WriteLine("; For example to open task manager the combination would be: LeftCtrl, LeftShift, Escape.");
writer.WriteLine("; Key action type describes what key action should perform: PRESS (presses the keys at once), TYPE (presses the keys one after another like during the typing). Default: PRESS.");
writer.WriteLine(string.Concat(Keys.ChannelRedemption_ID.ToString(), " = 123456789"));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_KeyAction.ToString(), " = LeftCtrl, LeftShift, Escape"));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_KeyActionType.ToString(), " = PRESS"));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_KeyActionAfterTime.ToString(), " = 1000, LeftCtrl, LeftShift, Escape"));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_KeyActionAfterTimeType.ToString(), " = PRESS"));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_ChatMessage.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_TextToDisplay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_TextPosition.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_TextToSpeech.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_SoundToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_VideoToPlay.ToString(), " = "));
writer.WriteLine(string.Concat(Keys.ChannelRedemption_MarkAsFulfilled.ToString(), " = false"));
writer.WriteLine();
writer.WriteLine();
writer.WriteLine("; Periodic messages (one message per line, each starting with \"msg = \"), can be left empty");
writer.WriteLine("; Multiple messages are allowed.");
writer.WriteLine("; Time interval of sending periodic messages is configured in 'PeriodicMessageTimeInterval' field in this configuration file.");
writer.WriteLine("; Periodic message is sent when time 'PeriodicMessageTimeInterval' from previous one has been exceeded and there have been at least 'PeriodicMessageMinChatMessages' chat messages.");
writer.WriteLine("; msg = Commented out periodic message (deactivated) peepoSad");
}
if (!example)
{
// Notify the user
Log.Error("Missing required info in {file} file.\r\nThe file was generated.\r\nPlease fill it up and restart the bot.", FILENAME);
}
}
/// <summary> Checks if Config.ini file was updated. </summary>
/// <returns><value>true</value> if the file was updated, otherwise <value>false</value></returns>
public static bool IsConfigFileUpdated()
{
FileInfo file = new(FILENAME);
if (file.Exists)
{
return file.LastWriteTime != ConfigFileTimestamp;
}
return false;
}
public static async void UpdateVolumes()
{
if (!VolumeValuesDirty) return;
VolumeValuesDirty = false;
await Database.UpdateValueInConfig(Database.Keys.VolumeAudio, VolumeAudio.ToString().Replace('.', ','));
await Database.UpdateValueInConfig(Database.Keys.VolumeVideo, VolumeVideo.ToString().Replace('.', ','));
}
/// <summary> Gets Broadcaster ID from Channel Name. Should be used once at bot startup. </summary>
public static void GetBroadcasterID()
{
Log.Information("Getting broadcaster ID.");
string uri = $"https://api.twitch.tv/helix/users?login={Config.Data[Config.Keys.ChannelName]}";
using HttpRequestMessage request = new(HttpMethod.Get, uri);
request.Headers.Add("Authorization", $"Bearer {Secret.Data[Secret.Keys.OAuthToken]}");
request.Headers.Add("Client-Id", Secret.Data[Secret.Keys.CustomerID]);
string resp;
try { resp = Notifications.Client.Send(request).Content.ReadAsStringAsync().Result; }
catch (HttpRequestException ex) { Log.Error("Couldn't acquire broadcaster ID. {ex}", ex); return; }
var response = ChannelIDResponse.Deserialize(resp);
if (response != null && response?.Data?.Length == 1) { Config.Data[Config.Keys.ChannelID] = response.Data[0].ID; }
else { Log.Warning("Couldn't acquire broadcaster ID. Probably defined channel name doesn't exist."); }
}
/// <summary> Gets current broadcaster status. </summary>
/// <returns>true if the stream is online, otherwise false.</returns>
public static bool GetBroadcasterStatus()
{
Log.Information("Getting broadcaster status.");
string uri = string.Concat(
"https://api.twitch.tv/helix/search/channels",
"?query=", Config.Data[Config.Keys.ChannelName].Replace(" ", "%20")
);
using HttpRequestMessage request = new(HttpMethod.Get, uri);
request.Headers.Add("Authorization", $"Bearer {Secret.Data[Secret.Keys.OAuthToken]}");
request.Headers.Add("Client-Id", Secret.Data[Secret.Keys.CustomerID]);
string resp;
try { resp = Notifications.Client.Send(request).Content.ReadAsStringAsync().Result; }
catch (HttpRequestException ex) { Log.Error("Couldn't acquire stream status. {ex}", ex); return false; }
if (resp is null || resp.Length == 0 || resp.StartsWith('<'))
{
Log.Warning("Couldn't acquire stream status.");
return false;
}