Skip to content

Commit c06f6bf

Browse files
committed
Fixed AttentionCommand to properly connect and stay connected
1 parent 856f832 commit c06f6bf

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Fritz.Chatbot/Commands/AttentionCommand.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
using Microsoft.AspNetCore.SignalR.Client;
66
using Microsoft.Extensions.Configuration;
77
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
89

910
namespace Fritz.Chatbot.Commands
1011
{
11-
public class AttentionCommand : IBasicCommand
12+
public class AttentionCommand : IBasicCommand, IDisposable
1213
{
1314
private readonly IConfiguration Configuration;
1415

15-
public AttentionCommand(IConfiguration configuration)
16+
public ILogger Logger { get; }
17+
18+
public AttentionCommand(IConfiguration configuration, ILoggerFactory loggerFactory)
1619
{
1720
this.Configuration = configuration;
21+
this.Logger = loggerFactory.CreateLogger("AttentionCommand");
22+
1823
var thisUri = new Uri(configuration["FritzBot:ServerUrl"], UriKind.Absolute);
19-
this.Client = new HubConnectionBuilder().WithUrl(new Uri(thisUri, "attentionhub").ToString()).Build();
20-
this.Client.StartAsync();
24+
var attentionUri = new Uri(thisUri, "attentionhub");
25+
26+
Logger.LogTrace($"Connecting AttentionCommand to: {attentionUri}");
27+
28+
this.Client = new HubConnectionBuilder().WithUrl(attentionUri.ToString()).Build();
29+
2130
}
2231

2332
protected HubConnection Client { get; }
@@ -30,11 +39,19 @@ public AttentionCommand(IConfiguration configuration)
3039

3140
public async Task Execute(IChatService chatService, string userName, ReadOnlyMemory<char> rhs)
3241
{
42+
43+
await this.Client.StartAsync();
44+
3345
await this.Client.InvokeAsync("AlertFritz");
3446

3547
var attentionText = Configuration["FritzBot:AttentionCommand:TemplateText"];
3648

3749
await chatService.SendMessageAsync(string.Format(attentionText, userName));
3850
}
51+
52+
public void Dispose()
53+
{
54+
Client.DisposeAsync();
55+
}
3956
}
4057
}

Fritz.StreamTools/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"RepositoryOwner": "csharpfritz",
7777
"ExcludeUsers": [
7878
"csharpfritz",
79-
"dependabot"
79+
"dependabot[bot]"
8080
]
8181
}
8282
}

Test/Startup/ConfigureServicesTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ private static Dictionary<string, string> MakeFakeConfiguration(string twitchCli
5757
{
5858
{"StreamServices:Twitch:ClientId", twitchClientId},
5959
{"StreamServices:Mixer:Channel", mixerClientId},
60-
{"StreamServices:Fake:Enabled", enableFake.ToString()}
60+
{"StreamServices:Fake:Enabled", enableFake.ToString()},
61+
{"FritzBot:ServerUrl", "http://localhost:80" }
6162
};
6263
}
64+
6365
}
6466
}

0 commit comments

Comments
 (0)