Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Nullinside.Api.TwitchBot/ChatRules/HostHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Nullinside.Api.Common.Twitch;
using Nullinside.Api.Model;
using Nullinside.Api.Model.Ddl;

using TwitchLib.Client.Models;

namespace Nullinside.Api.TwitchBot.ChatRules;

/// <summary>
/// Handles "hosthub.vip" spam.
/// </summary>
public class HostHub : AChatRule {
/// <inheritdoc />
public override bool ShouldRun(TwitchUserConfig config) {
return config is { Enabled: true, BanKnownBots: true };
}

/// <inheritdoc />
public override async Task<bool> Handle(string channelId, TwitchApiProxy botProxy, ChatMessage message,
NullinsideContext db, CancellationToken stoppingToken = new()) {
// The number of spaces per message may change, so normalize that and lowercase it for comparison.
string normalized = string.Concat(message.Message.Split(" ").Where(s => !string.IsNullOrWhiteSpace(s)))
.ToLowerInvariant();

// Message will contain the site name with different domains.
if (message.IsFirstMessage && normalized.Contains("hosthub.")) {
await BanAndLog(channelId, botProxy, new[] { (message.UserId, message.Username) },
"[Bot] Spam (HostHub)", db, stoppingToken);
return false;
}

return true;
}
}