-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (100 loc) · 4.29 KB
/
Program.cs
File metadata and controls
111 lines (100 loc) · 4.29 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
using TranscriberBot.Data.Handler;
using TranscriberBot.Data.Models;
namespace TranscriberBot
{
public class Program
{
private const string ConfigPath = "config.json";
private const string VoiceConfigPath = "voicemodule.json";
private static async Task Main(string[] args)
{
Console.WriteLine(" \r\n,------.,--. ,--. ,----. ,---. \r\n| .---'| |,--,--,--. ,---. | |,---. ' .-./ ,---. ,---. / .-' \r\n| `--, | || || .-. |`-'( .-' | | .---.| .-. || .-. || `-, \r\n| `---.| || | | |' '-' ' .-' `) ' '--' |' '-' '' '-' '| .-' \r\n`------'`--'`--`--`--' `---' `----' `------' `---' `---' `--' \r\n ");
Console.WriteLine("If you ever need to change your tokens, edit or delete 'config.json' and restart.\n");
var config = LoadOrCreateConfig();
var voiceConfig = LoadOrCreateVoiceConfig();
while (true)
{
try
{
await Bot.InitializeAsync(config, voiceConfig);
Console.WriteLine("Bot started successfully!");
break;
}
catch (Exception ex)
{
Console.WriteLine($"\nError initializing bot: {ex.Message}");
Console.WriteLine("Let's try re‑entering your tokens.\n");
config = PromptForConfig();
JsonHandler.SaveJson(ConfigPath, config);
Console.WriteLine("\nConfiguration updated. Retrying...\n");
}
}
}
private static Config LoadOrCreateConfig()
{
if (File.Exists(ConfigPath))
{
try
{
Console.WriteLine("Loading configuration from 'config.json'…");
var existing = JsonHandler.LoadJson<Config>(ConfigPath);
Console.WriteLine("Loaded.\n");
return existing;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load existing config: {ex.Message}");
}
}
Console.WriteLine("No valid configuration found. Let's set it up now.\n");
var config = PromptForConfig();
JsonHandler.SaveJson(ConfigPath, config);
Console.WriteLine("\nConfiguration saved to 'config.json'.\n");
return config;
}
private static VoiceModuleConfig LoadOrCreateVoiceConfig()
{
if (File.Exists(VoiceConfigPath))
{
try
{
Console.WriteLine($"Loading voice config from '{VoiceConfigPath}'…");
var existing = JsonHandler.LoadJson<VoiceModuleConfig>(VoiceConfigPath);
Console.WriteLine("Loaded voice config.\n");
return existing;
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load voice config: {ex.Message}");
}
}
Console.WriteLine("No valid voice config found. Creating a new one.\n");
var cfg = new VoiceModuleConfig();
JsonHandler.SaveJson(VoiceConfigPath, cfg);
Console.WriteLine($"Voice config saved to '{VoiceConfigPath}'.\n");
return cfg;
}
private static Config PromptForConfig()
{
string botToken;
do
{
Console.Write("Discord Bot Token: ");
botToken = Console.ReadLine()?.Trim();
}
while (string.IsNullOrEmpty(botToken));
string assemblyToken;
do
{
Console.Write("Assembly AI Token: ");
assemblyToken = Console.ReadLine()?.Trim();
}
while (string.IsNullOrEmpty(assemblyToken));
return new Config
{
BotToken = botToken,
AssemblyAIToken = assemblyToken
};
}
}
}