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
12 changes: 10 additions & 2 deletions DiscordBot/Services/Moderation/IntroductionWatcherService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Discord.WebSocket;
using DiscordBot.Settings;
using DiscordBot.Services.UnityHelp;

namespace DiscordBot.Services;

Expand All @@ -15,13 +16,17 @@ public class IntroductionWatcherService
private readonly HashSet<ulong> _uniqueUsers = new HashSet<ulong>(MaxMessagesToTrack + 1);
private readonly Queue<ulong> _orderedUsers = new Queue<ulong>(MaxMessagesToTrack + 1);

private SocketRole ModeratorRole { get; set; }

private const int MaxMessagesToTrack = 1000;

public IntroductionWatcherService(DiscordSocketClient client, ILoggingService loggingService, BotSettings settings)
{
_client = client;
_loggingService = loggingService;

ModeratorRole = _client.GetGuild(settings.GuildId).GetRole(settings.ModeratorRoleId);

if (!settings.IntroductionWatcherServiceEnabled)
{
LoggingService.LogServiceDisabled(ServiceName, nameof(settings.IntroductionWatcherServiceEnabled));
Expand All @@ -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();
Expand All @@ -61,4 +69,4 @@ await _loggingService.LogChannelAndFile(

await Task.CompletedTask;
}
}
}
Loading