-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonManager.cs
50 lines (41 loc) · 1.39 KB
/
JsonManager.cs
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
using Newtonsoft.Json;
using System.Reflection;
namespace StatusBot
{
public class JsonManager
{
public BotConfig GetBotConfig()
{
string botPath = FixPath(Assembly.GetEntryAssembly().Location);
string configPath = botPath + "\\Config.json";
if (!File.Exists(configPath))
{
string jsonString = JsonConvert.SerializeObject(new BotConfig(), Formatting.Indented);
File.WriteAllText(configPath, jsonString);
}
return OpenBotConfig();
}
private BotConfig? OpenBotConfig()
{
string botPath = FixPath(Assembly.GetExecutingAssembly().Location);
string configPath = botPath + "\\Config.json";
using StreamReader reader = new(configPath);
string json = reader.ReadToEnd();
return JsonConvert.DeserializeObject<BotConfig>(json);
}
private static string FixPath(string path)
{
int endPos = path.LastIndexOf("\\");
return path.Substring(0, endPos);
}
}
public class BotConfig
{
public string ServerNamePrefix = "yourserversprefix";
public string BotToken = "yourtoken";
public int DelayMilliseconds = 2500;
public ulong GuildId = 0;
public ulong ChannelId = 0;
public ulong MessageToEdit = 0;
}
}