-
Notifications
You must be signed in to change notification settings - Fork 2
/
Environment.cs
executable file
·47 lines (40 loc) · 1.29 KB
/
Environment.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
using Moe.Services;
namespace Moe;
public class Environment
{
public const string ProductionEnvFile = "production.env";
public const string DevelopmentEnvFile = "development.env";
public string Token { get; set; } = default!;
public ulong? ServerID { get; set; } = default!;
public List<ulong> Owners { get; set; } = default!;
public int StatusPort { get; set; } = default!;
public static async Task<Environment> Load()
{
string envFile = default!;
if (ConfigService.Options.IsDevelopment)
{
envFile = DevelopmentEnvFile;
}
else if (ConfigService.Options.IsProduction)
{
envFile = ProductionEnvFile;
}
await LogService.LogToFileAndConsole($"Using {envFile} for environment variables");
DotNetEnv.Env.Load(envFile);
return new Environment()
{
Token = GetEnv("TOKEN"),
ServerID = ConfigService.Options.IsProduction ? null : ulong.Parse(GetEnv("SERVERID")),
Owners = GetEnv("OWNERS")
.Split(',')
.Select(x => ulong.Parse(x))
.ToList(),
StatusPort = int.Parse(GetEnv("STATUS_PORT")),
};
}
private static string GetEnv(string name)
{
return System.Environment.GetEnvironmentVariable(name) ??
throw new InvalidOperationException($"Environment variable {name} is not set");
}
}