-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConfig.cs
39 lines (37 loc) · 1.55 KB
/
Config.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
using Tomlyn;
using Tomlyn.Model;
namespace IRCrarria
{
public class Config
{
public string Hostname { get; }
public int Port { get; }
public bool UseSsl { get; }
public bool SkipCertValidation { get; }
public bool IrcLog { get; }
public string Username { get; }
public string Nickname { get; }
public string Channel { get; }
public string Prefix { get; }
public IEnumerable<KeyValuePair<string, object>>? ExtraDetails { get; }
public IEnumerable<string>? ConnectCommands { get; }
public Config(string configText)
{
var document = Toml.ToModel(configText);
var hosttable = (TomlTable)document["host"];
Hostname = (string)hosttable["hostname"];
Port = (int)(long)hosttable["port"]; // yes, this cast is required
UseSsl = (bool)hosttable["ssl"];
SkipCertValidation = (bool)hosttable["skip_cert_validation"];
IrcLog = (bool)hosttable["irc_log"];
var irctable = (TomlTable)document["irc"];
Username = (string)irctable["username"];
Nickname = (string)irctable["nickname"];
Channel = (string)irctable["channel"];
Prefix = (string)irctable["prefix"];
if (document.ContainsKey("server_details")) ExtraDetails = (TomlTable)document["server_details"];
if (irctable.ContainsKey("connect_commands"))
ConnectCommands = ((TomlArray)irctable["connect_commands"]).OfType<string>();
}
}
}