From b61b9a62cd2f60a7bb920cc54f72d20c9acbc354 Mon Sep 17 00:00:00 2001 From: Ed Halley <1223980+hariedo@users.noreply.github.com> Date: Thu, 29 May 2025 21:28:12 -0500 Subject: [PATCH] Immunize Mods in IntroductionWatcherService.cs Moderators can post multiple messages, users cannot --- .../Moderation/IntroductionWatcherService.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/DiscordBot/Services/Moderation/IntroductionWatcherService.cs b/DiscordBot/Services/Moderation/IntroductionWatcherService.cs index 58b98387..6a82aa91 100644 --- a/DiscordBot/Services/Moderation/IntroductionWatcherService.cs +++ b/DiscordBot/Services/Moderation/IntroductionWatcherService.cs @@ -1,5 +1,6 @@ using Discord.WebSocket; using DiscordBot.Settings; +using DiscordBot.Services.UnityHelp; namespace DiscordBot.Services; @@ -15,6 +16,8 @@ public class IntroductionWatcherService private readonly HashSet _uniqueUsers = new HashSet(MaxMessagesToTrack + 1); private readonly Queue _orderedUsers = new Queue(MaxMessagesToTrack + 1); + private SocketRole ModeratorRole { get; set; } + private const int MaxMessagesToTrack = 1000; public IntroductionWatcherService(DiscordSocketClient client, ILoggingService loggingService, BotSettings settings) @@ -22,6 +25,8 @@ public IntroductionWatcherService(DiscordSocketClient client, ILoggingService lo _client = client; _loggingService = loggingService; + ModeratorRole = _client.GetGuild(settings.GuildId).GetRole(settings.ModeratorRoleId); + if (!settings.IntroductionWatcherServiceEnabled) { LoggingService.LogServiceDisabled(ServiceName, nameof(settings.IntroductionWatcherServiceEnabled)); @@ -43,7 +48,10 @@ private async Task MessageReceived(SocketMessage message) // We only watch the introduction channel if (_introductionChannel == null || message.Channel.Id != _introductionChannel.Id) return; - + + if (message.Author.HasRoleGroup(ModeratorRole)) + return; + if (_uniqueUsers.Contains(message.Author.Id)) { await message.DeleteAsync(); @@ -61,4 +69,4 @@ await _loggingService.LogChannelAndFile( await Task.CompletedTask; } -} \ No newline at end of file +}