Skip to content

Commit a76a878

Browse files
committed
Added pub sub message converter
1 parent c20f13b commit a76a878

File tree

10 files changed

+226
-87
lines changed

10 files changed

+226
-87
lines changed

.editorconfig

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,32 @@ insert_final_newline = true
1111
csharp_style_var_for_built_in_types = true:error
1212
csharp_style_var_when_type_is_apparent = true:error
1313
csharp_style_var_elsewhere = true:error
14-
csharp_prefer_braces = true
14+
csharp_prefer_braces = true:warning
15+
csharp_new_line_before_open_brace = none
16+
17+
18+
19+
######################################################################
20+
# Start by defining the naming symbols (groups) for fields...
21+
######################################################################
22+
# allowed by design guidelines, but naming is not specified by naming guidelines
23+
dotnet_naming_symbols.private_fields.applicable_kinds = field
24+
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, internal, protected_internal
25+
26+
######################################################################
27+
# Now define the styles that will be applied to those naming symbols...
28+
######################################################################
29+
# prefix_with_underscore_pascal_case
30+
dotnet_naming_style.prefix_with_underscore_pascal_case.capitalization = pascal_case
31+
dotnet_naming_style.prefix_with_underscore_pascal_case.required_prefix = _
32+
33+
######################################################################
34+
# Naming Rules are matched in the order listed, and only the first match is applied
35+
# Use this to match allowed field types, then match all other field types with the invalid style
36+
# Explicitly mark the field type that is user-preference, to allow simple changing to camelCase
37+
# or other settings...
38+
######################################################################
39+
# Fields that are private can be formatted entirely by user preference
40+
dotnet_naming_rule.private_fields_rule.symbols = private_fields
41+
dotnet_naming_rule.private_fields_rule.style = prefix_with_underscore_pascal_case
42+
dotnet_naming_rule.private_fields_rule.severity = warning

Fritz.StreamTools/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
1+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
22
WORKDIR /app
33
EXPOSE 80
44

Fritz.StreamTools/Services/GitHubService.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class GitHubService : IHostedService
1515
{
1616

1717
public static DateTime LastUpdate = DateTime.MinValue;
18+
private CancellationToken _Token;
19+
private Task _RunningTask;
1820

1921
public GitHubService(IServiceProvider services, ILogger<GitHubService> logger)
2022
{
@@ -27,22 +29,24 @@ public GitHubService(IServiceProvider services, ILogger<GitHubService> logger)
2729

2830
public Task StartAsync(CancellationToken cancellationToken)
2931
{
30-
return MonitorUpdates(cancellationToken);
32+
_Token = cancellationToken;
33+
_RunningTask = MonitorUpdates();
34+
return Task.CompletedTask;
3135
}
3236

3337
public Task StopAsync(CancellationToken cancellationToken)
3438
{
3539
return Task.CompletedTask;
3640
}
3741

38-
private async Task MonitorUpdates(CancellationToken cancellationToken)
42+
private async Task MonitorUpdates()
3943
{
4044
var lastRequest = DateTime.Now;
4145
using (var scope = Services.CreateScope())
4246
{
4347
var repo = scope.ServiceProvider.GetService(typeof(GitHubRepository)) as GitHubRepository;
4448
var mcGithubFaceClient = scope.ServiceProvider.GetService(typeof(GithubyMcGithubFaceClient)) as GithubyMcGithubFaceClient;
45-
while (!cancellationToken.IsCancellationRequested)
49+
while (!_Token.IsCancellationRequested)
4650
{
4751
if (repo != null)
4852
{
@@ -56,7 +60,7 @@ private async Task MonitorUpdates(CancellationToken cancellationToken)
5660
mcGithubFaceClient?.UpdateGitHub("", "", 0);
5761
}
5862
}
59-
await Task.Delay(500, cancellationToken);
63+
await Task.Delay(500, _Token);
6064
}
6165
}
6266
}

Fritz.StreamTools/Services/TwitchPubSubService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class TwitchPubSubService : IHostedService
1919
{
2020

2121
private IServiceProvider _ServiceProvider;
22+
private CancellationToken _Token;
23+
private Task _BackgroundTask;
2224
private readonly Twitch.PubSub.Proxy _Proxy;
2325
private readonly ConfigurationSettings _Configuration;
2426

@@ -32,7 +34,9 @@ public TwitchPubSubService(IServiceProvider serviceProvider, Twitch.PubSub.Proxy
3234
public Task StartAsync(CancellationToken cancellationToken)
3335
{
3436
_Proxy.OnChannelPointsRedeemed += _Proxy_OnChannelPointsRedeemed;
35-
return _Proxy.StartAsync(new TwitchTopic[] { TwitchTopic.ChannelPoints(_Configuration.UserId) }, cancellationToken);
37+
_Token = cancellationToken;
38+
_BackgroundTask = _Proxy.StartAsync(new TwitchTopic[] { TwitchTopic.ChannelPoints(_Configuration.UserId) }, _Token);
39+
return Task.CompletedTask;
3640
}
3741

3842
private void _Proxy_OnChannelPointsRedeemed(object sender, ChannelRedemption e)

Fritz.StreamTools/Startup.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,21 @@ public void Configure(IApplicationBuilder app, IHostEnvironment env, IConfigurat
4949
}
5050

5151
app.UseHsts();
52-
app.UseHttpsRedirection();
52+
//app.UseHttpsRedirection();
5353

5454
app.UseStaticFiles();
5555

56+
app.UseRouting();
57+
5658
app.UseEndpoints(endpoints =>
5759
{
5860

5961
endpoints.MapHub<FollowerHub>("/followerstream");
6062
endpoints.MapHub<GithubyMcGithubFace>("/github");
6163
endpoints.MapHub<AttentionHub>("/attentionhub");
6264

65+
endpoints.MapRazorPages();
66+
6367
endpoints.MapDefaultControllerRoute();
6468

6569
});

Fritz.StreamTools/StartupServices/ConfigureServices.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void Execute(IServiceCollection services, IConfiguration configura
4949
// Add the SentimentSink
5050
//services.AddSingleton<Fritz.Chatbot.Commands.SentimentSink>();
5151

52-
services.AddSingleton<IHostedService, FritzBot>();
52+
services.AddHostedService<FritzBot>();
5353

5454
services.AddSingleton(new GitHubClient(new ProductHeaderValue("Fritz.StreamTools")));
5555
FritzBot.RegisterCommands(services);
@@ -119,6 +119,7 @@ private static void AddStreamingServices(this IServiceCollection services, IConf
119119
c => !bool.TryParse(c["StreamServices:Fake:Enabled"], out var enabled) || !enabled); // Test to disable
120120

121121
services.AddSingleton<StreamService>();
122+
122123
}
123124

124125
/// <summary>
@@ -133,7 +134,7 @@ private static void AddStreamService<TStreamService>(this IServiceCollection ser
133134
IConfiguration configuration,
134135
Func<IConfiguration, ILoggerFactory, TStreamService> factory,
135136
Func<IConfiguration, bool> isDisabled)
136-
where TStreamService : class, IStreamService
137+
where TStreamService : class, IStreamService, IHostedService
137138
{
138139

139140
// Don't configure this service if it is disabled
@@ -174,6 +175,8 @@ private static void AddAspNetFeatures(this IServiceCollection services)
174175

175176
}).AddMessagePackProtocol();
176177

178+
services.AddRazorPages();
179+
177180
services.AddMvc()
178181
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
179182

@@ -182,7 +185,9 @@ private static void AddAspNetFeatures(this IServiceCollection services)
182185
private static void RegisterTwitchPubSub(this IServiceCollection services) {
183186

184187
services.AddSingleton<Twitch.PubSub.Proxy>();
188+
185189
services.AddHostedService<TwitchPubSubService>();
190+
186191
//var provider = services.BuildServiceProvider();
187192

188193
//var pubSub = new TwitchPubSubService(

Fritz.StreamTools/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"ClientId": "",
1818
"UserId": "",
1919
"ChatToken": "",
20+
"PubSubAuthToken": "",
2021
"ChatBotName": "FritzBot_"
2122
},
2223
"Mixer": {

Fritz.Twitch/ConfigurationSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class ConfigurationSettings
1717

1818
public virtual string OAuthToken { get; set; }
1919

20+
public virtual string PubSubAuthToken { get; set; }
21+
2022
[Obsolete]
2123
public string Channel { get => ChannelName; set => ChannelName = value; }
2224

0 commit comments

Comments
 (0)