Skip to content

Commit 522f188

Browse files
domFxcsharpfritz
authored andcommitted
Hopefully a more elegant method of extracting a Dictionary from AppSettings.json (#302)
1 parent f7bdfae commit 522f188

File tree

3 files changed

+4
-19
lines changed

3 files changed

+4
-19
lines changed

Fritz.Chatbot/Commands/SoundFxCommand.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,11 @@ namespace Fritz.Chatbot.Commands
1414
public class SoundFxCommand : IExtendedCommand
1515
{
1616

17-
public SoundFxCommand(IHubContext<AttentionHub, IAttentionHubClient> hubContext, IConfiguration configuration)
17+
public SoundFxCommand(IHubContext<AttentionHub, IAttentionHubClient> hubContext, IOptions<Dictionary<string, SoundFxDefinition>> soundEffects)
1818
{
1919
this.HubContext = hubContext;
2020

21-
LoadConfiguration(configuration);
22-
23-
}
24-
25-
private void LoadConfiguration(IConfiguration configuration)
26-
{
27-
28-
var sounds = configuration.GetSection("FritzBot:SoundFxCommands").GetChildren();
29-
30-
Effects = sounds.ToDictionary(s => s.Key, s => new SoundFxDefinition {
31-
Cooldown = s.GetValue<int>("cooldown"),
32-
Response = s.GetValue<string>("response"),
33-
File = s.GetValue<string>("file")
34-
});
35-
36-
21+
Effects = soundEffects.Value;
3722
}
3823

3924
public IHubContext<AttentionHub, IAttentionHubClient> HubContext { get; }

Fritz.StreamTools/StartupServices/ConfigureServices.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void Execute(IServiceCollection services, IConfiguration configura
3434
services.AddSingleton<IRundownService, RundownService>();
3535
services.Configure<FollowerGoalConfiguration>(configuration.GetSection("FollowerGoal"));
3636
services.Configure<FollowerCountConfiguration>(configuration.GetSection("FollowerCount"));
37-
services.Configure<SoundFxConfig>(configuration.GetSection("FritzBot:SoundFxCommands"));
37+
services.Configure<Dictionary<string, SoundFxDefinition>>(configuration.GetSection("FritzBot:SoundFxCommands"));
3838
services.AddStreamingServices(configuration);
3939
services.Configure<GitHubConfiguration>(configuration.GetSection("GitHub"));
4040
services.AddSingleton<FollowerClient>();

Fritz.StreamTools/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"andthen": {
6767
"response": "... and then ...",
68-
"file": [
68+
"files": [
6969
"andthen1.mp3",
7070
"andthen2.mp3",
7171
"andthen3.mp3",

0 commit comments

Comments
 (0)