Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added pub sub message converter #352

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,32 @@ insert_final_newline = true
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_elsewhere = true:error
csharp_prefer_braces = true
csharp_prefer_braces = true:warning
csharp_new_line_before_open_brace = none



######################################################################
# Start by defining the naming symbols (groups) for fields...
######################################################################
# allowed by design guidelines, but naming is not specified by naming guidelines
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, internal, protected_internal

######################################################################
# Now define the styles that will be applied to those naming symbols...
######################################################################
# prefix_with_underscore_pascal_case
dotnet_naming_style.prefix_with_underscore_pascal_case.capitalization = pascal_case
dotnet_naming_style.prefix_with_underscore_pascal_case.required_prefix = _

######################################################################
# Naming Rules are matched in the order listed, and only the first match is applied
# Use this to match allowed field types, then match all other field types with the invalid style
# Explicitly mark the field type that is user-preference, to allow simple changing to camelCase
# or other settings...
######################################################################
# Fields that are private can be formatted entirely by user preference
dotnet_naming_rule.private_fields_rule.symbols = private_fields
dotnet_naming_rule.private_fields_rule.style = prefix_with_underscore_pascal_case
dotnet_naming_rule.private_fields_rule.severity = warning
2 changes: 1 addition & 1 deletion Fritz.StreamTools/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80

Expand Down
12 changes: 8 additions & 4 deletions Fritz.StreamTools/Services/GitHubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class GitHubService : IHostedService
{

public static DateTime LastUpdate = DateTime.MinValue;
private CancellationToken _Token;
private Task _RunningTask;

public GitHubService(IServiceProvider services, ILogger<GitHubService> logger)
{
Expand All @@ -27,22 +29,24 @@ public GitHubService(IServiceProvider services, ILogger<GitHubService> logger)

public Task StartAsync(CancellationToken cancellationToken)
{
return MonitorUpdates(cancellationToken);
_Token = cancellationToken;
_RunningTask = MonitorUpdates();
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

private async Task MonitorUpdates(CancellationToken cancellationToken)
private async Task MonitorUpdates()
{
var lastRequest = DateTime.Now;
using (var scope = Services.CreateScope())
{
var repo = scope.ServiceProvider.GetService(typeof(GitHubRepository)) as GitHubRepository;
var mcGithubFaceClient = scope.ServiceProvider.GetService(typeof(GithubyMcGithubFaceClient)) as GithubyMcGithubFaceClient;
while (!cancellationToken.IsCancellationRequested)
while (!_Token.IsCancellationRequested)
{
if (repo != null)
{
Expand All @@ -56,7 +60,7 @@ private async Task MonitorUpdates(CancellationToken cancellationToken)
mcGithubFaceClient?.UpdateGitHub("", "", 0);
}
}
await Task.Delay(500, cancellationToken);
await Task.Delay(500, _Token);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Fritz.StreamTools/Services/TwitchPubSubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class TwitchPubSubService : IHostedService
{

private IServiceProvider _ServiceProvider;
private CancellationToken _Token;
private Task _BackgroundTask;
private readonly Twitch.PubSub.Proxy _Proxy;
private readonly ConfigurationSettings _Configuration;

Expand All @@ -32,7 +34,9 @@ public TwitchPubSubService(IServiceProvider serviceProvider, Twitch.PubSub.Proxy
public Task StartAsync(CancellationToken cancellationToken)
{
_Proxy.OnChannelPointsRedeemed += _Proxy_OnChannelPointsRedeemed;
return _Proxy.StartAsync(new TwitchTopic[] { TwitchTopic.ChannelPoints(_Configuration.UserId) }, cancellationToken);
_Token = cancellationToken;
_BackgroundTask = _Proxy.StartAsync(new TwitchTopic[] { TwitchTopic.ChannelPoints(_Configuration.UserId) }, _Token);
return Task.CompletedTask;
}

private void _Proxy_OnChannelPointsRedeemed(object sender, ChannelRedemption e)
Expand Down
6 changes: 5 additions & 1 deletion Fritz.StreamTools/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@ public void Configure(IApplicationBuilder app, IHostEnvironment env, IConfigurat
}

app.UseHsts();
app.UseHttpsRedirection();
//app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{

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

endpoints.MapRazorPages();

endpoints.MapDefaultControllerRoute();

});
Expand Down
9 changes: 7 additions & 2 deletions Fritz.StreamTools/StartupServices/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void Execute(IServiceCollection services, IConfiguration configura
// Add the SentimentSink
//services.AddSingleton<Fritz.Chatbot.Commands.SentimentSink>();

services.AddSingleton<IHostedService, FritzBot>();
services.AddHostedService<FritzBot>();

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

services.AddSingleton<StreamService>();

}

/// <summary>
Expand All @@ -133,7 +134,7 @@ private static void AddStreamService<TStreamService>(this IServiceCollection ser
IConfiguration configuration,
Func<IConfiguration, ILoggerFactory, TStreamService> factory,
Func<IConfiguration, bool> isDisabled)
where TStreamService : class, IStreamService
where TStreamService : class, IStreamService, IHostedService
{

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

}).AddMessagePackProtocol();

services.AddRazorPages();

services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

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

services.AddSingleton<Twitch.PubSub.Proxy>();

services.AddHostedService<TwitchPubSubService>();

//var provider = services.BuildServiceProvider();

//var pubSub = new TwitchPubSubService(
Expand Down
1 change: 1 addition & 0 deletions Fritz.StreamTools/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ClientId": "",
"UserId": "",
"ChatToken": "",
"PubSubAuthToken": "",
"ChatBotName": "FritzBot_"
},
"Mixer": {
Expand Down
2 changes: 2 additions & 0 deletions Fritz.Twitch/ConfigurationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class ConfigurationSettings

public virtual string OAuthToken { get; set; }

public virtual string PubSubAuthToken { get; set; }

[Obsolete]
public string Channel { get => ChannelName; set => ChannelName = value; }

Expand Down
Loading