diff --git a/src/Nullinside.Api.TwitchBot/ChatRules/HostHub.cs b/src/Nullinside.Api.TwitchBot/ChatRules/HostHub.cs new file mode 100644 index 0000000..4f1425c --- /dev/null +++ b/src/Nullinside.Api.TwitchBot/ChatRules/HostHub.cs @@ -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; + +/// +/// Handles "hosthub.vip" spam. +/// +public class HostHub : AChatRule { + /// + public override bool ShouldRun(TwitchUserConfig config) { + return config is { Enabled: true, BanKnownBots: true }; + } + + /// + public override async Task 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; + } +} \ No newline at end of file