From 7216e11269d8d306fea5984ad66637ca13cb52e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Tue, 10 Jun 2025 16:31:48 -0400 Subject: [PATCH] feat: joining more chats for more data To help with debugging and gathering bot related activity and information, we will join all channels we are modded in except for those users that are explicitly banned. --- .../Services/MainService.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Nullinside.Api.TwitchBot/Services/MainService.cs b/src/Nullinside.Api.TwitchBot/Services/MainService.cs index 5859b05..f9cf143 100644 --- a/src/Nullinside.Api.TwitchBot/Services/MainService.cs +++ b/src/Nullinside.Api.TwitchBot/Services/MainService.cs @@ -180,13 +180,22 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) { // Join all the channels we're a mod in. Why do we limit it to channels we are a mod in? Twitch changed // its chat limits so that "verified bots" like us don't get special treatment anymore. The only thing // that skips the chat limits is if it's a channel you're a mod in. - foreach (User channel in usersWithBotEnabled) { - if (string.IsNullOrWhiteSpace(channel.TwitchUsername)) { + var bannedUsers = (await GetBannedUsers(db, stoppingToken)) + .Where(u => !string.IsNullOrWhiteSpace(u.TwitchId)) + .Select(u => u.TwitchId!.Trim()) + .ToHashSet(); + var allModdedAndNotBannedUsers = moddedChannels + .Where(m => !bannedUsers.Contains(m.broadcaster_id)); + var joinChannels = usersWithBotEnabled + .Select(u => u.TwitchUsername) + .Concat(allModdedAndNotBannedUsers.Select(j => j.broadcaster_login)); + foreach (var channel in joinChannels) { + if (string.IsNullOrWhiteSpace(channel)) { continue; } - await _client.AddMessageCallback(channel.TwitchUsername, OnTwitchMessageReceived); - await _client.AddBannedCallback(channel.TwitchUsername, OnTwitchBanReceived); + await _client.AddMessageCallback(channel, OnTwitchMessageReceived); + await _client.AddBannedCallback(channel, OnTwitchBanReceived); } } @@ -290,7 +299,7 @@ orderby user.TwitchLastScanned /// The database. /// The stopping token. /// The list of users with the bot enabled. - private async Task?> GetBannedUsers(INullinsideContext db, CancellationToken stoppingToken) { + private async Task> GetBannedUsers(INullinsideContext db, CancellationToken stoppingToken) { return await (from user in db.Users orderby user.TwitchLastScanned