Skip to content

Commit 0ba592f

Browse files
Merge pull request #94 from nullinside-development-group/feat/join
feat: joining more chats for more data
2 parents d193157 + 7216e11 commit 0ba592f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/Nullinside.Api.TwitchBot/Services/MainService.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,22 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) {
180180
// Join all the channels we're a mod in. Why do we limit it to channels we are a mod in? Twitch changed
181181
// its chat limits so that "verified bots" like us don't get special treatment anymore. The only thing
182182
// that skips the chat limits is if it's a channel you're a mod in.
183-
foreach (User channel in usersWithBotEnabled) {
184-
if (string.IsNullOrWhiteSpace(channel.TwitchUsername)) {
183+
var bannedUsers = (await GetBannedUsers(db, stoppingToken))
184+
.Where(u => !string.IsNullOrWhiteSpace(u.TwitchId))
185+
.Select(u => u.TwitchId!.Trim())
186+
.ToHashSet();
187+
var allModdedAndNotBannedUsers = moddedChannels
188+
.Where(m => !bannedUsers.Contains(m.broadcaster_id));
189+
var joinChannels = usersWithBotEnabled
190+
.Select(u => u.TwitchUsername)
191+
.Concat(allModdedAndNotBannedUsers.Select(j => j.broadcaster_login));
192+
foreach (var channel in joinChannels) {
193+
if (string.IsNullOrWhiteSpace(channel)) {
185194
continue;
186195
}
187196

188-
await _client.AddMessageCallback(channel.TwitchUsername, OnTwitchMessageReceived);
189-
await _client.AddBannedCallback(channel.TwitchUsername, OnTwitchBanReceived);
197+
await _client.AddMessageCallback(channel, OnTwitchMessageReceived);
198+
await _client.AddBannedCallback(channel, OnTwitchBanReceived);
190199
}
191200
}
192201

@@ -290,7 +299,7 @@ orderby user.TwitchLastScanned
290299
/// <param name="db">The database.</param>
291300
/// <param name="stoppingToken">The stopping token.</param>
292301
/// <returns>The list of users with the bot enabled.</returns>
293-
private async Task<List<User>?> GetBannedUsers(INullinsideContext db, CancellationToken stoppingToken) {
302+
private async Task<List<User>> GetBannedUsers(INullinsideContext db, CancellationToken stoppingToken) {
294303
return await
295304
(from user in db.Users
296305
orderby user.TwitchLastScanned

0 commit comments

Comments
 (0)