6
6
using Microsoft . Extensions . Configuration ;
7
7
using Microsoft . Extensions . DependencyInjection ;
8
8
using Microsoft . Extensions . Hosting ;
9
+ using Microsoft . Extensions . Logging ;
9
10
using Microsoft . Extensions . Options ;
10
11
using System ;
11
12
using System . Collections . Generic ;
@@ -27,15 +28,18 @@ public class TwitchPubSubService : IHostedService
27
28
private readonly Twitch . PubSub . Proxy _Proxy ;
28
29
private readonly ConfigurationSettings _Configuration ;
29
30
private readonly IHostEnvironment _HostEnvironment ;
30
- private readonly Dictionary < string , Action < IHubContext < AttentionHub , IAttentionHubClient > > > _ChannelPointActions = new Dictionary < string , Action < IHubContext < AttentionHub , IAttentionHubClient > > > ( ) ;
31
+ private readonly ILogger _Logger ;
32
+ private readonly Dictionary < string , Action < IHubContext < AttentionHub , IAttentionHubClient > > > _ChannelPointActions = new Dictionary < string , Action < IHubContext < AttentionHub , IAttentionHubClient > > > ( ) ;
31
33
32
- public TwitchPubSubService ( IServiceProvider serviceProvider , Twitch . PubSub . Proxy proxy , IHostEnvironment hostEnvironment , IOptions < ConfigurationSettings > settings )
34
+ public TwitchPubSubService ( IServiceProvider serviceProvider , Twitch . PubSub . Proxy proxy , IHostEnvironment hostEnvironment , IOptions < ConfigurationSettings > settings , ILoggerFactory loggerFactory )
33
35
{
34
36
_ServiceProvider = serviceProvider ;
35
37
_Proxy = proxy ;
36
38
_Configuration = settings . Value ;
37
39
_HostEnvironment = hostEnvironment ;
38
40
41
+ _Logger = loggerFactory . CreateLogger ( "TwitchPubSub" ) ;
42
+
39
43
InitializeChannelPointActions ( ) ;
40
44
41
45
}
@@ -47,6 +51,12 @@ private void InitializeChannelPointActions()
47
51
48
52
public Task StartAsync ( CancellationToken cancellationToken )
49
53
{
54
+
55
+ if ( string . IsNullOrEmpty ( _Configuration . PubSubAuthToken ) ) {
56
+ _Logger . LogError ( "Twitch PubSub token was not provided, unable to start this service" ) ;
57
+ return Task . CompletedTask ;
58
+ }
59
+
50
60
_Proxy . OnChannelPointsRedeemed += _Proxy_OnChannelPointsRedeemed ;
51
61
_Token = cancellationToken ;
52
62
_BackgroundTask = _Proxy . StartAsync ( new TwitchTopic [ ] { TwitchTopic . ChannelPoints ( _Configuration . UserId ) } , _Token ) ;
@@ -59,7 +69,10 @@ private void IdentifyOldManAudio()
59
69
60
70
var oldManPath = Path . Combine ( _HostEnvironment . ContentRootPath , "wwwroot" , "contents" , "oldman" ) ;
61
71
var di = new DirectoryInfo ( oldManPath ) ;
62
- _OldManSoundFx = di . GetFiles ( ) . Select ( f => f . Name ) . OrderBy ( x => Guid . NewGuid ( ) ) . ToArray ( ) ;
72
+
73
+ if ( di . Exists && di . GetFiles ( ) . Any ( ) ) {
74
+ _OldManSoundFx = di . GetFiles ( ) . Select ( f => f . Name ) . OrderBy ( x => Guid . NewGuid ( ) ) . ToArray ( ) ;
75
+ }
63
76
64
77
}
65
78
0 commit comments