@@ -84,6 +84,11 @@ public class MainService : BackgroundService {
84
84
/// </summary>
85
85
private readonly ITwitchApiProxy _api ;
86
86
87
+ /// <summary>
88
+ /// The twitch client for sending/receiving chat messages.
89
+ /// </summary>
90
+ private readonly ITwitchClientProxy _client ;
91
+
87
92
/// <summary>
88
93
/// Initializes a new instance of the <see cref="MainService" /> class.
89
94
/// </summary>
@@ -93,6 +98,7 @@ public MainService(IServiceScopeFactory serviceScopeFactory) {
93
98
_scope = _serviceScopeFactory . CreateScope ( ) ;
94
99
_db = _scope . ServiceProvider . GetRequiredService < INullinsideContext > ( ) ;
95
100
_api = _scope . ServiceProvider . GetRequiredService < ITwitchApiProxy > ( ) ;
101
+ _client = _scope . ServiceProvider . GetRequiredService < ITwitchClientProxy > ( ) ;
96
102
_chatMessageConsumer = new TwitchChatMessageMonitorConsumer ( _db , _api , _receivedMessageProcessingQueue ) ;
97
103
}
98
104
@@ -109,8 +115,8 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
109
115
throw new Exception ( "Unable to log in as bot user" ) ;
110
116
}
111
117
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 ;
114
120
115
121
_botRules = AppDomain . CurrentDomain . GetAssemblies ( )
116
122
. SelectMany ( a => a . GetTypes ( ) )
@@ -133,7 +139,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
133
139
/// The starting point for running the bots' functionality.
134
140
/// </summary>
135
141
/// <param name="stoppingToken">The stopping token.</param>
136
- private async Task Main ( CancellationToken stoppingToken ) {
142
+ private async Task Main ( CancellationToken stoppingToken = new ( ) ) {
137
143
try {
138
144
while ( ! stoppingToken . IsCancellationRequested ) {
139
145
using ( IServiceScope scope = _serviceScopeFactory . CreateAsyncScope ( ) ) {
@@ -174,8 +180,8 @@ private async Task Main(CancellationToken stoppingToken) {
174
180
// its chat limits so that "verified bots" like us don't get special treatment anymore. The only thing
175
181
// that skips the chat limits is if it's a channel you're a mod in.
176
182
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 ) ;
179
185
}
180
186
}
181
187
0 commit comments