@@ -152,6 +152,13 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
152
152
if ( null == usersWithBotEnabled ) {
153
153
continue ;
154
154
}
155
+
156
+ // Get the list of users that are banned.
157
+ List < User > ? bannedUsers = await GetBannedUsers ( db , stoppingToken ) ;
158
+ if ( null == bannedUsers ) {
159
+ bannedUsers = Enumerable . Empty < User > ( ) . ToList ( ) ;
160
+ }
161
+ var bannedUserIds = bannedUsers . Select ( u => u . TwitchId ) . ToList ( ) ;
155
162
156
163
// Get the bot user's information.
157
164
User ? botUser = await db . Users . AsNoTracking ( )
@@ -173,6 +180,8 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
173
180
174
181
// Trim channels we aren't a mod in
175
182
IEnumerable < TwitchModeratedChannel > moddedChannels = await botApi . GetUserModChannels ( Constants . BotId ) ;
183
+ moddedChannels = moddedChannels . Where ( m => ! bannedUserIds . Contains ( m . broadcaster_id ) ) . ToList ( ) ;
184
+
176
185
usersWithBotEnabled = usersWithBotEnabled
177
186
. Where ( u => moddedChannels
178
187
. Select ( m => m . broadcaster_id )
@@ -281,6 +290,23 @@ orderby user.TwitchLastScanned
281
290
. AsNoTracking ( )
282
291
. ToListAsync ( stoppingToken ) ;
283
292
}
293
+
294
+ /// <summary>
295
+ /// Retrieve all users that are banned from using the bot.
296
+ /// </summary>
297
+ /// <param name="db">The database.</param>
298
+ /// <param name="stoppingToken">The stopping token.</param>
299
+ /// <returns>The list of users with the bot enabled.</returns>
300
+ private async Task < List < User > ? > GetBannedUsers ( INullinsideContext db , CancellationToken stoppingToken ) {
301
+ return await
302
+ ( from user in db . Users
303
+ orderby user . TwitchLastScanned
304
+ where user . TwitchId != Constants . BotId &&
305
+ user . IsBanned
306
+ select user )
307
+ . AsNoTracking ( )
308
+ . ToListAsync ( stoppingToken ) ;
309
+ }
284
310
285
311
/// <summary>
286
312
/// Performs the scan on a user.
@@ -299,16 +325,16 @@ private async Task DoScan(User user, User botUser, CancellationToken stoppingTok
299
325
using ( IServiceScope scope = _serviceScopeFactory . CreateAsyncScope ( ) ) {
300
326
await using ( var db = scope . ServiceProvider . GetRequiredService < INullinsideContext > ( ) ) {
301
327
// Get the API
302
- ITwitchApiProxy ? botApi = await db . ConfigureApiAndRefreshToken ( botUser , this . _api , stoppingToken ) ;
303
- if ( null == _botRules || null == user . TwitchConfig || null == botApi ) {
328
+ this . _api . Configure ( botUser ) ;
329
+ if ( null == _botRules || null == user . TwitchConfig ) {
304
330
return ;
305
331
}
306
332
307
333
// Run the rules that scan the chats and the accounts.
308
334
foreach ( IBotRule rule in _botRules ) {
309
335
try {
310
336
if ( rule . ShouldRun ( user . TwitchConfig ) ) {
311
- await rule . Handle ( user , user . TwitchConfig , botApi , db , stoppingToken ) ;
337
+ await rule . Handle ( user , user . TwitchConfig , this . _api , db , stoppingToken ) ;
312
338
}
313
339
}
314
340
catch ( Exception e ) {
0 commit comments