@@ -84,6 +84,11 @@ public class MainService : BackgroundService {
8484 /// </summary>
8585 private readonly ITwitchApiProxy _api ;
8686
87+ /// <summary>
88+ /// The twitch client for sending/receiving chat messages.
89+ /// </summary>
90+ private readonly ITwitchClientProxy _client ;
91+
8792 /// <summary>
8893 /// Initializes a new instance of the <see cref="MainService" /> class.
8994 /// </summary>
@@ -93,6 +98,7 @@ public MainService(IServiceScopeFactory serviceScopeFactory) {
9398 _scope = _serviceScopeFactory . CreateScope ( ) ;
9499 _db = _scope . ServiceProvider . GetRequiredService < INullinsideContext > ( ) ;
95100 _api = _scope . ServiceProvider . GetRequiredService < ITwitchApiProxy > ( ) ;
101+ _client = _scope . ServiceProvider . GetRequiredService < ITwitchClientProxy > ( ) ;
96102 _chatMessageConsumer = new TwitchChatMessageMonitorConsumer ( _db , _api , _receivedMessageProcessingQueue ) ;
97103 }
98104
@@ -109,8 +115,8 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
109115 throw new Exception ( "Unable to log in as bot user" ) ;
110116 }
111117
112- TwitchClientProxy . Instance . TwitchUsername = Constants . BotUsername ;
113- TwitchClientProxy . Instance . TwitchOAuthToken = botApi . OAuth ? . AccessToken ;
118+ this . _client . TwitchUsername = Constants . BotUsername ;
119+ this . _client . TwitchOAuthToken = botApi . OAuth ? . AccessToken ;
114120
115121 _botRules = AppDomain . CurrentDomain . GetAssemblies ( )
116122 . SelectMany ( a => a . GetTypes ( ) )
@@ -133,7 +139,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
133139 /// The starting point for running the bots' functionality.
134140 /// </summary>
135141 /// <param name="stoppingToken">The stopping token.</param>
136- private async Task Main ( CancellationToken stoppingToken ) {
142+ private async Task Main ( CancellationToken stoppingToken = new ( ) ) {
137143 try {
138144 while ( ! stoppingToken . IsCancellationRequested ) {
139145 using ( IServiceScope scope = _serviceScopeFactory . CreateAsyncScope ( ) ) {
@@ -174,8 +180,8 @@ private async Task Main(CancellationToken stoppingToken) {
174180 // its chat limits so that "verified bots" like us don't get special treatment anymore. The only thing
175181 // that skips the chat limits is if it's a channel you're a mod in.
176182 foreach ( TwitchModeratedChannel channel in moddedChannels ) {
177- await TwitchClientProxy . Instance . AddMessageCallback ( channel . broadcaster_login , OnTwitchMessageReceived ) ;
178- await TwitchClientProxy . Instance . AddBannedCallback ( channel . broadcaster_login , OnTwitchBanReceived ) ;
183+ await this . _client . AddMessageCallback ( channel . broadcaster_login , OnTwitchMessageReceived ) ;
184+ await this . _client . AddBannedCallback ( channel . broadcaster_login , OnTwitchBanReceived ) ;
179185 }
180186 }
181187
0 commit comments