-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBoderatorConfigurationFactory.cs
More file actions
32 lines (27 loc) · 1.06 KB
/
BoderatorConfigurationFactory.cs
File metadata and controls
32 lines (27 loc) · 1.06 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
using System;
using System.Collections;
using System.Configuration;
namespace ArmaForces.Boderator.BotService.Configuration
{
internal class BoderatorConfigurationFactory
{
private readonly IDictionary _environmentVariables;
public BoderatorConfigurationFactory()
{
_environmentVariables = Environment.GetEnvironmentVariables();
}
// TODO: Consider making this a bit more automatic so configuration is easily extensible
public BoderatorConfiguration CreateConfiguration() => new BoderatorConfiguration
{
DiscordToken = GetStringValue(nameof(BoderatorConfiguration.DiscordToken))
};
private string GetStringValue(string variableName)
{
var fullVariableName = $"AF_Boderator_{variableName}";
var value = _environmentVariables[fullVariableName];
return value is not null
? (string) value
: throw new ConfigurationErrorsException($"Variable {fullVariableName} does not exist.");
}
}
}