forked from get-got/discord-downloader-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
1613 lines (1473 loc) · 60.4 KB
/
config.go
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
package main
import (
"bufio"
"encoding/json"
"io"
"log"
"os"
"runtime"
"strings"
"github.com/bwmarrin/discordgo"
"github.com/fatih/color"
"github.com/muhammadmuzzammil1998/jsonc"
"gopkg.in/ini.v1"
"gopkg.in/yaml.v3"
)
var (
configFileBase string = "settings"
configFile string
configFileC bool
configFileYaml bool
config configuration = defaultConfiguration()
)
//#region Config, Credentials
var (
placeholderToken string = "REPLACE_WITH_YOUR_TOKEN_OR_DELETE_LINE"
placeholderEmail string = "REPLACE_WITH_YOUR_EMAIL_OR_DELETE_LINE"
placeholderPassword string = "REPLACE_WITH_YOUR_PASSWORD_OR_DELETE_LINE"
)
type configurationCredentials struct {
// Login
Token string `json:"token" yaml:"token"` // required for bot token (this or login)
Email string `json:"email" yaml:"email"` // required for login (this or token)
Password string `json:"password" yaml:"password"` // required for login (this or token)
// APIs
TwitterAuthEnabled *bool `json:"twitterEnabled" yaml:"twitterEnabled"`
TwitterUsername string `json:"twitterUsername" yaml:"twitterUsername"`
TwitterPassword string `json:"twitterPassword" yaml:"twitterPassword"`
TwitterProxy string `json:"twitterProxy,omitempty" yaml:"twitterProxy,omitempty"`
InstagramAuthEnabled *bool `json:"instagramEnabled" yaml:"instagramEnabled"`
InstagramUsername string `json:"instagramUsername" yaml:"instagramUsername"`
InstagramPassword string `json:"instagramPassword" yaml:"instagramPassword"`
InstagramTOTP *string `json:"instagramTOTP,omitempty" yaml:"instagramTOTP,omitempty"`
InstagramProxy string `json:"instagramProxy,omitempty" yaml:"instagramProxy,omitempty"`
InstagramProxyInsecure *bool `json:"instagramProxyInsecure,omitempty" yaml:"instagramProxyInsecure,omitempty"`
InstagramProxyForceHTTP2 *bool `json:"instagramProxyForceHTTP2,omitempty" yaml:"instagramProxyForceHTTP2,omitempty"`
FlickrApiKey string `json:"flickrApiKey" yaml:"flickrApiKey"`
}
//#endregion
//#region Config, Main
// defConfig_ = Config Default
// Needed for settings used without redundant nil checks, and settings defaulting + creation
var (
defConfig_AuthTwitter bool = true
defConfig_AuthInstagram bool = true
defConfig_Debug bool = false
defConfig_CommandPrefix string = "ddg "
defConfig_ScanOwnMessages bool = false
defConfig_GithubUpdateChecking bool = true
// Appearance
defConfig_PresenceEnabled bool = true
defConfig_PresenceStatus string = string(discordgo.StatusIdle)
defConfig_PresenceType discordgo.GameType = discordgo.GameTypeGame
defConfig_ReactWhenDownloaded bool = false
defConfig_InflateDownloadCount int64 = 0
// These are only defaults to "fix" when loading settings for when people put stupid values
defConfig_ProcessLimit int = 32
defConfig_DiscordTimeout int = 180
defConfig_DownloadTimeout int = 60
defConfig_DownloadRetryMax int = 2
defConfig_HistoryManagerRate int = 5
defConfig_CheckupRate int = 30
defConfig_ConnectionCheckRate int = 5
defConfig_PresenceRefreshRate int = 3
defConfig_FilenameDateFormat string = "2006-01-02_15-04-05"
defConfig_FilenameFormat string = "{{date}} {{file}}"
defConfig_HistoryMaxJobs int = 3
)
func defaultConfiguration() configuration {
return configuration{
// Logins
Credentials: configurationCredentials{
Token: placeholderToken,
Email: placeholderEmail,
Password: placeholderPassword,
TwitterAuthEnabled: &defConfig_AuthTwitter,
InstagramAuthEnabled: &defConfig_AuthInstagram,
},
// Owner Settings
Admins: []string{},
AdminChannels: []configurationAdminChannel{},
// Program Settings
LogIndent: true,
ProcessLimit: defConfig_ProcessLimit,
Debug: defConfig_Debug,
BackupDatabaseOnStart: false,
WatchSettings: true,
LogSettings: true,
MessageOutput: true,
MessageOutputHistory: false,
DiscordLogLevel: discordgo.LogError,
DiscordTimeout: defConfig_DiscordTimeout,
DownloadTimeout: defConfig_DownloadTimeout,
DownloadRetryMax: defConfig_DownloadRetryMax,
ExitOnBadConnection: false,
GithubUpdateChecking: defConfig_GithubUpdateChecking,
CommandPrefix: defConfig_CommandPrefix,
CommandTagging: true,
ScanOwnMessages: defConfig_ScanOwnMessages,
AllowGeneralCommands: true,
InflateDownloadCount: &defConfig_InflateDownloadCount,
EuropeanNumbers: false,
HistoryManagerRate: defConfig_HistoryManagerRate,
CheckupRate: defConfig_CheckupRate,
ConnectionCheckRate: defConfig_ConnectionCheckRate,
PresenceRefreshRate: defConfig_PresenceRefreshRate,
// Emojis & Stickers
EmojisFilenameFormat: "{{ID}} {{name}}",
StickersFilenameFormat: "{{ID}} {{name}}",
// Source Setup Defaults
Save: true,
AllowCommands: true,
ScanEdits: true,
IgnoreBots: true,
SendErrorMessages: false,
SendFileToChannel: "",
SendFileDirectly: true,
SendFileCaption: "",
// Appearance
PresenceEnabled: defConfig_PresenceEnabled,
PresenceStatus: defConfig_PresenceStatus,
PresenceType: defConfig_PresenceType,
ReactWhenDownloaded: defConfig_ReactWhenDownloaded,
ReactWhenDownloadedHistory: false,
HistoryTyping: true,
// History
HistoryMaxJobs: defConfig_HistoryMaxJobs,
AutoHistory: false,
AutoHistoryBefore: "",
AutoHistorySince: "",
SendHistoryStatus: true,
SendAutoHistoryStatus: false,
OutputHistoryStatus: true,
OutputHistoryErrors: true,
HistoryRequestCount: 100,
HistoryRequestDelay: 0,
// Rules for Saving
Subfolders: []string{"{{fileType}}"},
FilenameDateFormat: defConfig_FilenameDateFormat,
FilenameFormat: defConfig_FilenameFormat,
FilepathNormalizeText: false,
FilepathStripSymbols: false,
SaveImages: true,
SaveVideos: true,
SaveAudioFiles: true,
SaveTextFiles: false,
SaveOtherFiles: false,
SavePossibleDuplicates: false,
DelayHandling: 0,
DelayHandlingHistory: 0,
Filters: &configurationSourceFilters{
BlockedExtensions: &[]string{
".htm",
".html",
".php",
".exe",
".dll",
".bin",
".cmd",
".sh",
".py",
".jar",
},
},
Duplo: false,
DuploThreshold: 0,
}
}
type configuration struct {
Constants map[string]string `json:"_constants" yaml:"_constants"`
// Logins
Credentials configurationCredentials `json:"credentials" yaml:"credentials"`
// Owner Settings
Admins []string `json:"admins" yaml:"admins"`
AdminChannels []configurationAdminChannel `json:"adminChannels" yaml:"adminChannels"`
// Path Overwrites
OverwriteCachePath string `json:"overwriteCachePath,omitempty" yaml:"overwriteCachePath,omitempty"`
OverwriteHistoryPath string `json:"overwriteHistoryPath,omitempty" yaml:"overwriteHistoryPath,omitempty"`
OverwriteDuploPath string `json:"overwriteDuploPath,omitempty" yaml:"overwriteDuploPath,omitempty"`
OverwriteTwitterPath string `json:"overwriteTwitterPath,omitempty" yaml:"overwriteTwitterPath,omitempty"`
OverwriteInstagramPath string `json:"overwriteInstagramPath,omitempty" yaml:"overwriteInstagramPath,omitempty"`
OverwriteConstantsPath string `json:"overwriteConstantsPath,omitempty" yaml:"overwriteConstantsPath,omitempty"`
OverwriteDatabasePath string `json:"overwriteDatabasePath,omitempty" yaml:"overwriteDatabasePath,omitempty"`
OverwriteDatabaseBackupsPath string `json:"overwriteDatabaseBackupsPath,omitempty" yaml:"overwriteDatabaseBackupsPath,omitempty"`
// Logging
Verbose bool `json:"verbose" yaml:"verbose"`
Debug bool `json:"debug" yaml:"debug"`
DebugExtra bool `json:"debugExtra" yaml:"debugExtra"`
LogSettings bool `json:"settingsOutput" yaml:"settingsOutput"`
LogOutput string `json:"logOutput,omitempty" yaml:"logOutput,omitempty"`
LogIndent bool `json:"logIndent" yaml:"logIndent"`
MessageOutput bool `json:"messageOutput" yaml:"messageOutput"`
MessageOutputHistory bool `json:"messageOutputHistory" yaml:"messageOutputHistory"`
DiscordLogLevel int `json:"discordLogLevel" yaml:"discordLogLevel"`
// Program Settings
ProcessLimit int `json:"processLimit" yaml:"processLimit"`
GithubUpdateChecking bool `json:"githubUpdateChecking" yaml:"githubUpdateChecking"`
ExitOnBadConnection bool `json:"exitOnBadConnection" yaml:"exitOnBadConnection"`
WatchSettings bool `json:"watchSettings" yaml:"watchSettings"`
BackupDatabaseOnStart bool `json:"backupDatabaseOnStart" yaml:"backupDatabaseOnStart"`
CheckupRate int `json:"checkupRate,omitempty" yaml:"checkupRate,omitempty"`
ConnectionCheckRate int `json:"connectionCheckRate,omitempty" yaml:"connectionCheckRate,omitempty"`
HistoryManagerRate int `json:"historyManagerRate,omitempty" yaml:"historyManagerRate,omitempty"`
InflateDownloadCount *int64 `json:"inflateDownloadCount,omitempty" yaml:"inflateDownloadCount,omitempty"`
EuropeanNumbers bool `json:"europeanNumbers,omitempty" yaml:"europeanNumbers,omitempty"`
// Discord
ScanEdits bool `json:"scanEdits" yaml:"scanEdits"`
IgnoreBots bool `json:"ignoreBots" yaml:"ignoreBots"`
ScanOwnMessages bool `json:"scanOwnMessages" yaml:"scanOwnMessages"`
AllowCommands bool `json:"allowCommands" yaml:"allowCommands"`
AllowGeneralCommands bool `json:"allowGeneralCommands" yaml:"allowGeneralCommands"`
CommandPrefix string `json:"commandPrefix" yaml:"commandPrefix"`
CommandTagging bool `json:"commandTagging" yaml:"commandTagging"`
DiscordTimeout int `json:"discordTimeout" yaml:"discordTimeout"`
DownloadTimeout int `json:"downloadTimeout" yaml:"downloadTimeout"`
DownloadRetryMax int `json:"downloadRetryMax" yaml:"downloadRetryMax"`
SendErrorMessages bool `json:"sendErrorMessages" yaml:"sendErrorMessages"`
// Discord Emojis & Stickers
EmojisServers *[]string `json:"emojisServers" yaml:"emojisServers"`
EmojisFilenameFormat string `json:"emojisFilenameFormat" yaml:"emojisFilenameFormat"`
EmojisDestination *string `json:"emojisDestination" yaml:"emojisDestination"`
StickersServers *[]string `json:"stickersServers" yaml:"stickersServers"`
StickersFilenameFormat string `json:"stickersFilenameFormat" yaml:"stickersFilenameFormat"`
StickersDestination *string `json:"stickersDestination" yaml:"stickersDestination"`
// File Forwarding to Discord Channel
SendFileToChannel string `json:"sendFileToChannel" yaml:"sendFileToChannel"`
SendFileToChannels []string `json:"sendFileToChannels,omitempty" yaml:"sendFileToChannels,omitempty"`
SendFileDirectly bool `json:"sendFileDirectly,omitempty" yaml:"sendFileDirectly,omitempty"`
SendFileCaption string `json:"sendFileCaption,omitempty" yaml:"sendFileCaption,omitempty"`
// Discord Presence
PresenceEnabled bool `json:"presenceEnabled" yaml:"presenceEnabled"`
PresenceStatus string `json:"presenceStatus" yaml:"presenceStatus"`
PresenceType discordgo.GameType `json:"presenceType" yaml:"presenceType"`
PresenceLabel *string `json:"presenceLabel" yaml:"presenceLabel"`
PresenceDetails *string `json:"presenceDetails" yaml:"presenceDetails"`
PresenceState *string `json:"presenceState" yaml:"presenceState"`
PresenceRefreshRate int `json:"presenceRefreshRate,omitempty" yaml:"presenceRefreshRate,omitempty"`
// Discord Appearance
ReactWhenDownloaded bool `json:"reactWhenDownloaded" yaml:"reactWhenDownloaded"`
ReactWhenDownloadedEmoji *string `json:"reactWhenDownloadedEmoji" yaml:"reactWhenDownloadedEmoji"`
ReactWhenDownloadedHistory bool `json:"reactWhenDownloadedHistory" yaml:"reactWhenDownloadedHistory"`
OverwriteDefaultReaction *string `json:"overwriteDefaultReaction,omitempty" yaml:"overwriteDefaultReaction,omitempty"`
HistoryTyping bool `json:"historyTyping,omitempty" yaml:"historyTyping,omitempty"`
EmbedColor *string `json:"embedColor,omitempty" yaml:"embedColor,omitempty"`
// History
HistoryMaxJobs int `json:"historyMaxJobs" yaml:"historyMaxJobs"`
AutoHistory bool `json:"autoHistory" yaml:"autoHistory"`
AutoHistoryBefore string `json:"autoHistoryBefore" yaml:"autoHistoryBefore"`
AutoHistorySince string `json:"autoHistorySince" yaml:"autoHistorySince"`
SendAutoHistoryStatus bool `json:"sendAutoHistoryStatus" yaml:"sendAutoHistoryStatus"`
SendHistoryStatus bool `json:"sendHistoryStatus" yaml:"sendHistoryStatus"`
OutputHistoryStatus bool `json:"outputHistoryStatus" yaml:"outputHistoryStatus"`
OutputHistoryErrors bool `json:"outputHistoryErrors" yaml:"outputHistoryErrors"`
HistoryRequestCount int `json:"historyRequestCount" yaml:"historyRequestCount"`
HistoryRequestDelay int `json:"historyRequestDelay" yaml:"historyRequestDelay"`
// Rules for Saving
Save bool `json:"save" yaml:"save"`
Subfolders []string `json:"subfolders" yaml:"subfolders"`
FilenameDateFormat string `json:"filenameDateFormat" yaml:"filenameDateFormat"`
FilenameFormat string `json:"filenameFormat" yaml:"filenameFormat"`
FilepathNormalizeText bool `json:"filepathNormalizeText,omitempty" yaml:"filepathNormalizeText,omitempty"`
FilepathStripSymbols bool `json:"filepathStripSymbols,omitempty" yaml:"filepathStripSymbols,omitempty"`
SaveImages bool `json:"saveImages" yaml:"saveImages"`
SaveVideos bool `json:"saveVideos" yaml:"saveVideos"`
SaveAudioFiles bool `json:"saveAudioFiles" yaml:"saveAudioFiles"`
SaveTextFiles bool `json:"saveTextFiles" yaml:"saveTextFiles"`
SaveOtherFiles bool `json:"saveOtherFiles" yaml:"saveOtherFiles"`
SavePossibleDuplicates bool `json:"savePossibleDuplicates" yaml:"savePossibleDuplicates"`
DelayHandling int `json:"delayHandling,omitempty" yaml:"delayHandling,omitempty"`
DelayHandlingHistory int `json:"delayHandlingHistory,omitempty" yaml:"delayHandlingHistory,omitempty"`
Filters *configurationSourceFilters `json:"filters" yaml:"filters"`
Duplo bool `json:"duplo,omitempty" yaml:"duplo,omitempty"`
DuploThreshold float64 `json:"duploThreshold,omitempty" yaml:"duploThreshold,omitempty"`
// Misc Rules
LogLinks *configurationSourceLog `json:"logLinks,omitempty" yaml:"logLinks,omitempty"`
LogMessages *configurationSourceLog `json:"logMessages,omitempty" yaml:"logMessages,omitempty"`
// Sources
All *configurationSource `json:"all,omitempty" yaml:"all,omitempty"`
AllBlacklistUsers *[]string `json:"allBlacklistUsers,omitempty" yaml:"allBlacklistUsers,omitempty"`
AllBlacklistServers *[]string `json:"allBlacklistServers,omitempty" yaml:"allBlacklistServers,omitempty"`
AllBlacklistCategories *[]string `json:"allBlacklistCategories,omitempty" yaml:"allBlacklistCategories,omitempty"`
AllBlacklistChannels *[]string `json:"allBlacklistChannels,omitempty" yaml:"allBlacklistChannels,omitempty"`
Users []configurationSource `json:"users,omitempty" yaml:"users,omitempty"`
Servers []configurationSource `json:"servers,omitempty" yaml:"servers,omitempty"`
Categories []configurationSource `json:"categories,omitempty" yaml:"categories,omitempty"`
Channels []configurationSource `json:"channels,omitempty" yaml:"channels,omitempty"`
}
//#endregion
//#region Config, Sources
// Needed for settings used without redundant nil checks, and settings defaulting + creation
var (
defSource_Enabled bool = true
)
type configurationSource struct {
// ~
UserID string `json:"user,omitempty" yaml:"user,omitempty"`
UserIDs *[]string `json:"users,omitempty" yaml:"users,omitempty"`
ServerID string `json:"server,omitempty" yaml:"server,omitempty"`
ServerIDs *[]string `json:"servers,omitempty" yaml:"servers,omitempty"`
ServerBlacklist *[]string `json:"serverBlacklist,omitempty" yaml:"serverBlacklist,omitempty"`
CategoryID string `json:"category,omitempty" yaml:"category,omitempty"`
CategoryIDs *[]string `json:"categories,omitempty" yaml:"categories,omitempty"`
CategoryBlacklist *[]string `json:"categoryBlacklist,omitempty" yaml:"categoryBlacklist,omitempty"`
ChannelID string `json:"channel,omitempty" yaml:"channel,omitempty"`
ChannelIDs *[]string `json:"channels,omitempty" yaml:"channels,omitempty"`
Destination string `json:"destination" yaml:"destination"`
Alias *string `json:"alias,omitempty" yaml:"alias,omitempty"`
Aliases *[]string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
// Setup
Enabled *bool `json:"enabled" yaml:"enabled"`
Save *bool `json:"save" yaml:"save"`
AllowCommands *bool `json:"allowCommands" yaml:"allowCommands"`
ScanEdits *bool `json:"scanEdits" yaml:"scanEdits"`
IgnoreBots *bool `json:"ignoreBots" yaml:"ignoreBots"`
CommandPrefix *string `json:"commandPrefix" yaml:"commandPrefix"`
SendErrorMessages *bool `json:"sendErrorMessages" yaml:"sendErrorMessages"`
SendFileToChannel *string `json:"sendFileToChannel" yaml:"sendFileToChannel"`
SendFileToChannels *[]string `json:"sendFileToChannels,omitempty" yaml:"sendFileToChannels,omitempty"`
SendFileDirectly *bool `json:"sendFileDirectly,omitempty" yaml:"sendFileDirectly,omitempty"`
SendFileCaption *string `json:"sendFileCaption,omitempty" yaml:"sendFileCaption,omitempty"`
// Appearance
PresenceEnabled *bool `json:"presenceEnabled" yaml:"presenceEnabled"`
ReactWhenDownloaded *bool `json:"reactWhenDownloaded" yaml:"reactWhenDownloaded"`
ReactWhenDownloadedEmoji *string `json:"reactWhenDownloadedEmoji" yaml:"reactWhenDownloadedEmoji"`
ReactWhenDownloadedHistory *bool `json:"reactWhenDownloadedHistory" yaml:"reactWhenDownloadedHistory"`
BlacklistReactEmojis *[]string `json:"blacklistReactEmojis,omitempty" yaml:"blacklistReactEmojis,omitempty"`
HistoryTyping *bool `json:"historyTyping,omitempty" yaml:"historyTyping,omitempty"`
EmbedColor *string `json:"embedColor,omitempty" yaml:"embedColor,omitempty"`
// History
AutoHistory *bool `json:"autoHistory" yaml:"autoHistory"`
AutoHistoryBefore *string `json:"autoHistoryBefore" yaml:"autoHistoryBefore"`
AutoHistorySince *string `json:"autoHistorySince" yaml:"autoHistorySince"`
SendAutoHistoryStatus *bool `json:"sendAutoHistoryStatus" yaml:"sendAutoHistoryStatus"`
SendHistoryStatus *bool `json:"sendHistoryStatus" yaml:"sendHistoryStatus"`
OutputHistoryStatus *bool `json:"outputHistoryStatus" yaml:"outputHistoryStatus"`
OutputHistoryErrors *bool `json:"outputHistoryErrors" yaml:"outputHistoryErrors"`
// Rules for Saving
Subfolders *[]string `json:"subfolders,omitempty" yaml:"subfolders,omitempty"`
FilenameDateFormat *string `json:"filenameDateFormat" yaml:"filenameDateFormat"`
FilenameFormat *string `json:"filenameFormat" yaml:"filenameFormat"`
FilepathNormalizeText *bool `json:"filepathNormalizeText,omitempty" yaml:"filepathNormalizeText,omitempty"`
FilepathStripSymbols *bool `json:"filepathStripSymbols,omitempty" yaml:"filepathStripSymbols,omitempty"`
SaveImages *bool `json:"saveImages" yaml:"saveImages"`
SaveVideos *bool `json:"saveVideos" yaml:"saveVideos"`
SaveAudioFiles *bool `json:"saveAudioFiles" yaml:"saveAudioFiles"`
SaveTextFiles *bool `json:"saveTextFiles" yaml:"saveTextFiles"`
SaveOtherFiles *bool `json:"saveOtherFiles" yaml:"saveOtherFiles"`
SavePossibleDuplicates *bool `json:"savePossibleDuplicates" yaml:"savePossibleDuplicates"`
DelayHandling *int `json:"delayHandling,omitempty" yaml:"delayHandling,omitempty"`
DelayHandlingHistory *int `json:"delayHandlingHistory,omitempty" yaml:"delayHandlingHistory,omitempty"`
Filters *configurationSourceFilters `json:"filters" yaml:"filters"`
Duplo *bool `json:"duplo,omitempty" yaml:"duplo,omitempty"`
DuploThreshold *float64 `json:"duploThreshold,omitempty" yaml:"duploThreshold,omitempty"`
// Misc Rules
LogLinks *configurationSourceLog `json:"logLinks,omitempty" yaml:"logLinks,omitempty"`
LogMessages *configurationSourceLog `json:"logMessages,omitempty" yaml:"logMessages,omitempty"`
}
type configurationSourceFilters struct {
BlockedPhrases *[]string `json:"blockedPhrases,omitempty" yaml:"blockedPhrases,omitempty"`
AllowedPhrases *[]string `json:"allowedPhrases,omitempty" yaml:"allowedPhrases,omitempty"`
BlockedUsers *[]string `json:"blockedUsers,omitempty" yaml:"blockedUsers,omitempty"`
AllowedUsers *[]string `json:"allowedUsers,omitempty" yaml:"allowedUsers,omitempty"`
BlockedRoles *[]string `json:"blockedRoles,omitempty" yaml:"blockedRoles,omitempty"`
AllowedRoles *[]string `json:"allowedRoles,omitempty" yaml:"allowedRoles,omitempty"`
BlockedDomains *[]string `json:"blockedDomains,omitempty" yaml:"blockedDomains,omitempty"`
AllowedDomains *[]string `json:"allowedDomains,omitempty" yaml:"allowedDomains,omitempty"`
BlockedExtensions *[]string `json:"blockedExtensions,omitempty" yaml:"blockedExtensions,omitempty"`
AllowedExtensions *[]string `json:"allowedExtensions,omitempty" yaml:"allowedExtensions,omitempty"`
BlockedFilenames *[]string `json:"blockedFilenames,omitempty" yaml:"blockedFilenames,omitempty"`
AllowedFilenames *[]string `json:"allowedFilenames,omitempty" yaml:"allowedFilenames,omitempty"`
BlockedReactions *[]string `json:"blockedReactions,omitempty" yaml:"blockedReactions,omitempty"`
AllowedReactions *[]string `json:"allowedReactions,omitempty" yaml:"allowedReactions,omitempty"`
}
var (
defSourceLog_Subfolders []string = []string{"{{year}}-{{monthNum}}-{{dayOfMonth}}"}
defSourceLog_FilenameFormat string = "{{serverName}} - {{channelName}}.txt"
defSourceLog_FilepathNormalizeText bool = false
defSourceLog_FilepathStripSymbols bool = false
defSourceLog_LinePrefix string = "[{{serverName}} / {{channelName}}] \"{{username}}\" @ {{timestamp}}: "
defSourceLog_LogDownloads bool = true
defSourceLog_LogFailures bool = true
defSourceLogMsg_LineContent string = "{{message}}"
defSourceLogLink_LineContent string = "{{link}}"
)
type configurationSourceLog struct {
Destination string `json:"destination" yaml:"destination"`
Subfolders *[]string `json:"subfolders,omitempty" yaml:"subfolders,omitempty"`
FilenameFormat *string `json:"filenameFormat,omitempty" yaml:"filenameFormat,omitempty"`
FilepathNormalizeText *bool `json:"filepathNormalizeText,omitempty" yaml:"filepathNormalizeText,omitempty"`
FilepathStripSymbols *bool `json:"filepathStripSymbols,omitempty" yaml:"filepathStripSymbols,omitempty"`
LinePrefix *string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
LineSuffix *string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
LineContent *string `json:"content,omitempty" yaml:"content,omitempty"`
FilterDuplicates *bool `json:"filterDuplicates" yaml:"filterDuplicates"`
LogDownloads *bool `json:"logDownloads" yaml:"logDownloads"` // links only
LogFailures *bool `json:"logFailures" yaml:"logFailures"` // links only
}
//#endregion
//#region Config, Admin Channels
var (
adefConfig_LogProgram bool = false
adefConfig_LogStatus bool = true
adefConfig_LogErrors bool = true
adefConfig_UnlockCommands bool = false
)
type configurationAdminChannel struct {
// Specify target command channels
ChannelID string `json:"channel" yaml:"channel"`
ChannelIDs *[]string `json:"channels,omitempty" yaml:"channels,omitempty"`
LogProgram *bool `json:"logProgram" yaml:"logProgram"`
LogStatus *bool `json:"logStatus" yaml:"logStatus"`
LogErrors *bool `json:"logErrors" yaml:"logErrors"`
UnlockCommands *bool `json:"unlockCommands" yaml:"unlockCommands"`
CommandPrefix *string `json:"commandPrefix,omitempty" yaml:"commandPrefix,omitempty"`
}
//#endregion
//#region Management
func loadConfig() error {
// Determine config type
if _, err := os.Stat(configFileBase + ".yaml"); err == nil {
configFile = configFileBase + ".yaml"
configFileYaml = true
} else if _, err := os.Stat(configFileBase + ".jsonc"); err == nil {
configFile = configFileBase + ".jsonc"
configFileC = true
} else {
configFile = configFileBase + ".json"
configFileC = false
}
log.Println(lg("Settings", "loadConfig", color.YellowString, "Loading from \"%s\"...", configFile))
// Load settings
configContent, err := os.ReadFile(configFile)
if err != nil {
log.Println(lg("Settings", "loadConfig", color.HiRedString, "Failed to open file...\t%s", err))
createConfig()
properExit()
} else {
fixed := string(configContent)
// Fix backslashes
fixed = strings.ReplaceAll(fixed, "\\", "\\\\")
for strings.Contains(fixed, "\\\\\\") {
fixed = strings.ReplaceAll(fixed, "\\\\\\", "\\\\")
}
//TODO: Not even sure if this is realistic to do but would be nice to have line comma & trailing comma fixing
// Parse
newConfig := defaultConfiguration()
if configFileYaml {
err = yaml.Unmarshal([]byte(fixed), &newConfig)
} else if configFileC {
err = jsonc.Unmarshal([]byte(fixed), &newConfig)
} else {
err = json.Unmarshal([]byte(fixed), &newConfig)
}
if err != nil {
log.Println(lg("Settings", "loadConfig", color.HiRedString, "Failed to parse settings file...\t%s", err))
log.Println(lg("Settings", "loadConfig", color.MagentaString, "Please ensure you're following proper JSON format syntax."))
properExit()
}
// Constants
if newConfig.Constants != nil {
for key, value := range newConfig.Constants {
if strings.Contains(fixed, key) {
fixed = strings.ReplaceAll(fixed, key, value)
}
}
// Re-parse
newConfig = defaultConfiguration()
if configFileYaml {
err = yaml.Unmarshal([]byte(fixed), &newConfig)
} else if configFileC {
err = jsonc.Unmarshal([]byte(fixed), &newConfig)
} else {
err = json.Unmarshal([]byte(fixed), &newConfig)
}
if err != nil {
log.Println(lg("Settings", "loadConfig", color.HiRedString,
"Failed to re-parse settings file after replacing constants...\t%s", err))
log.Println(lg("Settings", "loadConfig", color.MagentaString, "Please ensure you're following proper JSON format syntax."))
properExit()
}
newConfig.Constants = nil
}
config = newConfig
// Source Defaults
for i := 0; i < len(config.Channels); i++ {
sourceDefault(&config.Channels[i])
}
for i := 0; i < len(config.Categories); i++ {
sourceDefault(&config.Categories[i])
}
for i := 0; i < len(config.Servers); i++ {
sourceDefault(&config.Servers[i])
}
for i := 0; i < len(config.Users); i++ {
sourceDefault(&config.Users[i])
}
if config.All != nil {
sourceDefault(config.All)
}
// Admin Channel Defaults
for i := 0; i < len(config.AdminChannels); i++ {
adminChannelDefault(&config.AdminChannels[i])
}
// Checks & Fixes
if config.ProcessLimit < 1 {
config.ProcessLimit = defConfig_ProcessLimit
}
if config.DiscordTimeout < 10 {
config.DiscordTimeout = defConfig_DiscordTimeout
}
if config.DownloadTimeout < 10 {
config.DownloadTimeout = defConfig_DownloadTimeout
}
if config.DownloadRetryMax < 1 {
config.DownloadRetryMax = defConfig_DownloadRetryMax
}
if config.CheckupRate < 1 {
config.CheckupRate = defConfig_CheckupRate
}
if config.ConnectionCheckRate < 1 {
config.ConnectionCheckRate = defConfig_ConnectionCheckRate
}
if config.PresenceRefreshRate < 1 {
config.PresenceRefreshRate = defConfig_PresenceRefreshRate
}
if config.FilenameDateFormat == "" {
config.FilenameDateFormat = defConfig_FilenameDateFormat
}
if config.FilenameFormat == "" {
config.FilenameFormat = defConfig_FilenameFormat
}
if config.HistoryMaxJobs < 1 {
config.HistoryMaxJobs = defConfig_HistoryMaxJobs
}
// Log to File
if config.LogOutput != "" {
f, err := os.OpenFile(config.LogOutput, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Println(lg("Settings", "loadConfig", color.HiRedString, "Failed to open LogOutput file...\t%s", err))
} else {
log.SetOutput(io.MultiWriter(color.Output, f))
}
}
// Misc Rules
if config.LogLinks != nil {
if config.LogLinks.Subfolders == nil {
config.LogLinks.Subfolders = &defSourceLog_Subfolders
}
if config.LogLinks.FilenameFormat == nil {
config.LogLinks.FilenameFormat = &defSourceLog_FilenameFormat
}
if config.LogLinks.FilepathNormalizeText == nil {
config.LogLinks.FilepathNormalizeText = &defSourceLog_FilepathNormalizeText
}
if config.LogLinks.FilepathStripSymbols == nil {
config.LogLinks.FilepathStripSymbols = &defSourceLog_FilepathStripSymbols
}
if config.LogLinks.LinePrefix == nil {
config.LogLinks.LinePrefix = &defSourceLog_LinePrefix
}
// vv unique vv
if config.LogLinks.LineContent == nil {
config.LogLinks.LineContent = &defSourceLogLink_LineContent
}
if config.LogLinks.LogDownloads == nil {
config.LogLinks.LogDownloads = &defSourceLog_LogDownloads
}
if config.LogLinks.LogFailures == nil {
config.LogLinks.LogFailures = &defSourceLog_LogFailures
}
}
if config.LogMessages != nil {
if config.LogMessages.Subfolders == nil {
config.LogMessages.Subfolders = &defSourceLog_Subfolders
}
if config.LogMessages.FilenameFormat == nil {
config.LogMessages.FilenameFormat = &defSourceLog_FilenameFormat
}
if config.LogMessages.FilepathNormalizeText == nil {
config.LogMessages.FilepathNormalizeText = &defSourceLog_FilepathNormalizeText
}
if config.LogMessages.FilepathStripSymbols == nil {
config.LogMessages.FilepathStripSymbols = &defSourceLog_FilepathStripSymbols
}
if config.LogMessages.LinePrefix == nil {
config.LogMessages.LinePrefix = &defSourceLog_LinePrefix
}
// vv unique vv
if config.LogMessages.LineContent == nil {
config.LogMessages.LineContent = &defSourceLogMsg_LineContent
}
}
// Overwrite Paths
if config.OverwriteCachePath != "" {
pathCache = config.OverwriteCachePath
}
if config.OverwriteHistoryPath != "" {
pathCacheHistory = config.OverwriteHistoryPath
}
if config.OverwriteDuploPath != "" {
pathCacheDuplo = config.OverwriteDuploPath
}
if config.OverwriteTwitterPath != "" {
pathCacheTwitter = config.OverwriteTwitterPath
}
if config.OverwriteInstagramPath != "" {
pathCacheInstagram = config.OverwriteInstagramPath
}
if config.OverwriteConstantsPath != "" {
pathConstants = config.OverwriteConstantsPath
}
if config.OverwriteDatabasePath != "" {
pathDatabaseBase = config.OverwriteDatabasePath
}
if config.OverwriteDatabaseBackupsPath != "" {
pathDatabaseBackups = config.OverwriteDatabaseBackupsPath
}
// Overwrite Default Reaction
if config.OverwriteDefaultReaction != nil {
defaultReact = *config.OverwriteDefaultReaction
}
// Settings Output
if config.LogSettings {
dupeConfig := config
if dupeConfig.Credentials.Token != "" && dupeConfig.Credentials.Token != placeholderToken {
dupeConfig.Credentials.Token = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.Email != "" && dupeConfig.Credentials.Email != placeholderEmail {
dupeConfig.Credentials.Email = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.Password != "" && dupeConfig.Credentials.Password != placeholderPassword {
dupeConfig.Credentials.Password = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.TwitterUsername != "" {
dupeConfig.Credentials.TwitterUsername = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.TwitterPassword != "" {
dupeConfig.Credentials.TwitterPassword = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.InstagramUsername != "" {
dupeConfig.Credentials.InstagramUsername = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.InstagramPassword != "" {
dupeConfig.Credentials.InstagramPassword = "STRIPPED_FOR_OUTPUT"
}
if dupeConfig.Credentials.FlickrApiKey != "" {
dupeConfig.Credentials.FlickrApiKey = "STRIPPED_FOR_OUTPUT"
}
s, err := json.MarshalIndent(dupeConfig, "", "\t")
if err != nil {
log.Println(lg("Debug", "loadConfig", color.HiRedString, "Failed to output...\t%s", err))
} else {
log.Println(lg("Debug", "loadConfig", color.HiYellowString, "Parsed into JSON:\n\n%s", color.YellowString(string(s))))
}
}
// Credentials Check
if (config.Credentials.Token == "" || config.Credentials.Token == placeholderToken) &&
(config.Credentials.Email == "" || config.Credentials.Email == placeholderEmail) &&
(config.Credentials.Password == "" || config.Credentials.Password == placeholderPassword) {
log.Println(lg("Settings", "loadConfig", color.HiRedString, "No valid discord login found..."))
log.Println(lg("Settings", "loadConfig", color.HiYellowString, "Please save your credentials & info into \"%s\" then restart...", configFile))
log.Println(lg("Settings", "loadConfig", color.MagentaString, "If your credentials are already properly saved, please ensure you're following proper JSON format syntax..."))
log.Println(lg("Settings", "loadConfig", color.MagentaString, "You DO NOT NEED token *AND* email/password, just one OR the other."))
properExit()
}
allString := ""
if config.All != nil {
allString = ", ALL GROUP ENABLED"
}
log.Println(lg("Settings", "", color.HiYellowString,
"Finished loading ... bound to %d channel%s, %d categories, %d server%s, %d user%s%s",
getBoundChannelsCount(), pluralS(getBoundChannelsCount()),
getBoundCategoriesCount(),
getBoundServersCount(), pluralS(getBoundServersCount()),
getBoundUsersCount(), pluralS(getBoundUsersCount()), allString,
))
// SETTINGS TO BE APPLIED IMMEDIATELY
if config.ProcessLimit > 0 {
runtime.GOMAXPROCS(config.ProcessLimit)
}
// Make cache path
os.MkdirAll(pathCache, 0755)
// Convert and cache
if !configFileYaml {
d, err := yaml.Marshal(&config)
if err == nil {
os.WriteFile(pathCacheSettingsYAML, d, 0644)
}
} else {
d, err := json.Marshal(&config)
if err == nil {
os.WriteFile(pathCacheSettingsJSON, d, 0644)
}
}
}
return nil
}
func createConfig() {
log.Println(lg("Settings", "create", color.YellowString, "Creating new settings file..."))
defaultConfig := defaultConfiguration()
defaultConfig.Credentials.Token = placeholderToken
defaultConfig.Credentials.Email = placeholderEmail
defaultConfig.Credentials.Password = placeholderPassword
defaultConfig.Admins = []string{"REPLACE_WITH_YOUR_DISCORD_USER_ID"}
enteredBaseChannel := "REPLACE_WITH_DISCORD_CHANNEL_ID_TO_DOWNLOAD_FROM"
enteredBaseDestination := "REPLACE_WITH_FOLDER_LOCATION_TO_DOWNLOAD_TO"
// Import old config
if _, err := os.Stat("config.ini"); err == nil {
log.Println(lg("Settings", "create", color.HiGreenString,
"Detected config.ini from Seklfreak's discord-image-downloader-go, importing..."))
cfg, err := ini.Load("config.ini")
if err != nil {
log.Println(lg("Settings", "create", color.HiRedString,
"Unable to read your old config file:\t%s", err))
cfg = ini.Empty()
} else { // Import old ini
importKey := func(section string, key string, outVar interface{}, outType string) bool {
if cfg.Section(section).HasKey(key) {
if outType == "string" {
outVar = cfg.Section(section).Key(key).String()
} else if outType == "int" {
outVar = cfg.Section(section).Key(key).MustInt()
} else if outType == "bool" {
outVar = cfg.Section(section).Key(key).MustBool()
}
log.Println(lg("Settings", "create", color.GreenString, "IMPORTED %s - %s:\t\t\t%s", section, key, outVar))
return true
}
return false
}
// Auth
if !importKey("auth", "token", &defaultConfig.Credentials.Token, "string") {
defaultConfig.Credentials.Token = ""
}
if !importKey("auth", "email", &defaultConfig.Credentials.Email, "string") {
defaultConfig.Credentials.Email = ""
}
if !importKey("auth", "password", &defaultConfig.Credentials.Password, "string") {
defaultConfig.Credentials.Password = ""
}
importKey("flickr", "api key", &defaultConfig.Credentials.FlickrApiKey, "string")
// General
importKey("general", "max download retries", &defaultConfig.DownloadRetryMax, "int")
importKey("general", "download timeout", &defaultConfig.DownloadTimeout, "int")
// Status
importKey("status", "status enabled", &defaultConfig.PresenceEnabled, "bool")
importKey("status", "status type", &defaultConfig.PresenceStatus, "string")
importKey("status", "status label", &defaultConfig.PresenceType, "int")
// Channels
InteractiveChannelWhitelist := cfg.Section("interactive channels").KeysHash()
for key := range InteractiveChannelWhitelist {
newChannel := configurationAdminChannel{
ChannelID: key,
}
log.Println(lg("Settings", "create", color.GreenString, "IMPORTED Admin Channel:\t\t%s", key))
defaultConfig.AdminChannels = append(defaultConfig.AdminChannels, newChannel)
}
ChannelWhitelist := cfg.Section("channels").KeysHash()
for key, value := range ChannelWhitelist {
newChannel := configurationSource{
ChannelID: key,
Destination: value,
}
log.Println(lg("Settings", "create", color.GreenString, "IMPORTED Channel:\t\t\t%s to \"%s\"", key, value))
defaultConfig.Channels = append(defaultConfig.Channels, newChannel)
}
}
log.Println(lg("Settings", "create", color.HiGreenString,
"Finished importing config.ini from Seklfreak's discord-image-downloader-go!"))
} else {
var baseChannel configurationSource
sourceDefault(&baseChannel)
baseChannel.ChannelID = enteredBaseChannel
baseChannel.Destination = enteredBaseDestination
defaultConfig.Channels = append(defaultConfig.Channels, baseChannel)
baseAdminChannel := configurationAdminChannel{
ChannelID: "REPLACE_WITH_DISCORD_CHANNEL_ID_FOR_ADMIN_COMMANDS",
}
defaultConfig.AdminChannels = append(defaultConfig.AdminChannels, baseAdminChannel)
adminChannelDefault(&defaultConfig.AdminChannels[0])
//TODO: Improve, this is very crude, I just wanted *something* for this.
log.Print(lg("Settings", "create", color.HiCyanString, "Would you like to enter settings info now? [Y/N]: "))
reader := bufio.NewReader(os.Stdin)
inputCredsYN, _ := reader.ReadString('\n')
inputCredsYN = strings.ReplaceAll(inputCredsYN, "\n", "")
inputCredsYN = strings.ReplaceAll(inputCredsYN, "\r", "")
if strings.Contains(strings.ToLower(inputCredsYN), "y") {
EnterCreds:
log.Print(color.HiCyanString("Token or Login? [\"token\"/\"login\"]: "))
inputCreds, _ := reader.ReadString('\n')
inputCreds = strings.ReplaceAll(inputCreds, "\n", "")
inputCreds = strings.ReplaceAll(inputCreds, "\r", "")
if strings.Contains(strings.ToLower(inputCreds), "token") {
EnterToken:
log.Print(color.HiCyanString("Enter token: "))
inputToken, _ := reader.ReadString('\n')
inputToken = strings.ReplaceAll(inputToken, "\n", "")
inputToken = strings.ReplaceAll(inputToken, "\r", "")
if inputToken != "" {
defaultConfig.Credentials.Token = inputToken
} else {
log.Println(lg("Settings", "create", color.HiRedString, "Please input token..."))
goto EnterToken
}
} else if strings.Contains(strings.ToLower(inputCreds), "login") {
EnterEmail:
log.Print(color.HiCyanString("Enter email: "))
inputEmail, _ := reader.ReadString('\n')
inputEmail = strings.ReplaceAll(inputEmail, "\n", "")
inputEmail = strings.ReplaceAll(inputEmail, "\r", "")
if strings.Contains(inputEmail, "@") {
defaultConfig.Credentials.Email = inputEmail
EnterPassword:
log.Print(color.HiCyanString("Enter password: "))
inputPassword, _ := reader.ReadString('\n')
inputPassword = strings.ReplaceAll(inputPassword, "\n", "")
inputPassword = strings.ReplaceAll(inputPassword, "\r", "")
if inputPassword != "" {
defaultConfig.Credentials.Password = inputPassword
} else {
log.Println(lg("Settings", "create", color.HiRedString, "Please input password..."))
goto EnterPassword
}
} else {
log.Println(lg("Settings", "create", color.HiRedString, "Please input email..."))
goto EnterEmail
}
} else {
log.Println(lg("Settings", "create", color.HiRedString, "Please input \"token\" or \"login\"..."))
goto EnterCreds
}
EnterAdmin:
log.Print(color.HiCyanString("Input your Discord User ID: "))
inputAdmin, _ := reader.ReadString('\n')
inputAdmin = strings.ReplaceAll(inputAdmin, "\n", "")
inputAdmin = strings.ReplaceAll(inputAdmin, "\r", "")
if isNumeric(inputAdmin) {
defaultConfig.Admins = []string{inputAdmin}
} else {
log.Println(lg("Settings", "create", color.HiRedString, "Please input your Discord User ID..."))
goto EnterAdmin
}
//TODO: Base channel setup? Would be kind of annoying and may limit options
//TODO: Admin channel setup?
}
}
log.Println(lg("Settings", "create", color.MagentaString,
"The default settings will be missing some options to avoid clutter."))
log.Println(lg("Settings", "create", color.HiMagentaString,
"There are MANY MORE SETTINGS! If you would like to maximize customization, see the GitHub README for all available settings."))
defaultJSON, err := json.MarshalIndent(defaultConfig, "", "\t")
if err != nil {
log.Println(lg("Settings", "create", color.HiRedString, "Failed to format new settings...\t%s", err))
} else {
err := os.WriteFile(configFile, defaultJSON, 0644)
if err != nil {
log.Println(lg("Settings", "create", color.HiRedString, "Failed to save new settings file...\t%s", err))
} else {
log.Println(lg("Settings", "create", color.HiYellowString, "Created new settings file..."))
log.Println(lg("Settings", "create", color.HiYellowString,
"Please save your credentials & info into \"%s\" then restart...", configFile))
log.Println(lg("Settings", "create", color.MagentaString,
"You DO NOT NEED token *AND* email/password, just one OR the other."))
log.Println(lg("Settings", "create", color.MagentaString,
"THERE ARE MANY HIDDEN SETTINGS AVAILABLE, SEE THE GITHUB README github.com/"+projectRepoBase))
}
}
}
func sourceDefault(source *configurationSource) {
// These have to use the default variables since literal values and consts can't be set to the pointers
// Setup
if source.Enabled == nil {
source.Enabled = &defSource_Enabled
}
if source.Save == nil {
source.Save = &config.Save
}
if source.AllowCommands == nil {
source.AllowCommands = &config.AllowCommands
}
if source.SendErrorMessages == nil {
source.SendErrorMessages = &config.SendErrorMessages
}
if source.ScanEdits == nil {
source.ScanEdits = &config.ScanEdits
}