Compare commits

...

2 commits

3 changed files with 68 additions and 57 deletions
CHANGELOG.md
src/EllieBot
EllieBot.csproj
Modules/Administration/Protection

View file

@ -2,6 +2,13 @@
*a,c,f,r,o* *a,c,f,r,o*
## [6.0.12] - 20.03.2025
### Fixed
- `.antispamignore` fixed for the last time hopefully
- protection commands are some of the oldest commands, and they might get overhauled in future updates
- please report if you find any other weird issue with them
## [6.0.11] - 20.03.2025 ## [6.0.11] - 20.03.2025
### Changed ### Changed

View file

@ -4,7 +4,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings> <ImplicitUsings>true</ImplicitUsings>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages> <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<Version>6.0.11</Version> <Version>6.0.12</Version>
<!-- Output/build --> <!-- Output/build -->
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory> <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>

View file

@ -27,6 +27,7 @@ public class ProtectionService : IReadyExecutor, IEService
private readonly UserPunishService _punishService; private readonly UserPunishService _punishService;
private readonly INotifySubscriber _notifySub; private readonly INotifySubscriber _notifySub;
private readonly ShardData _shardData; private readonly ShardData _shardData;
private readonly Channel<PunishQueueItem> _punishUserQueue = private readonly Channel<PunishQueueItem> _punishUserQueue =
Channel.CreateUnbounded<PunishQueueItem>(new() Channel.CreateUnbounded<PunishQueueItem>(new()
{ {
@ -176,10 +177,7 @@ public class ProtectionService : IReadyExecutor, IEService
try try
{ {
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings) if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings)
|| spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new() || spamSettings.AntiSpamSettings.IgnoredChannels.Any(x => x.ChannelId == channel.Id))
{
ChannelId = channel.Id
}))
return; return;
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id,
@ -275,23 +273,25 @@ public class ProtectionService : IReadyExecutor, IEService
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow.GetTable<AntiRaidSetting>() await uow.GetTable<AntiRaidSetting>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = guildId, GuildId = guildId,
Action = action, Action = action,
Seconds = seconds, Seconds = seconds,
UserThreshold = userThreshold, UserThreshold = userThreshold,
PunishDuration = minutesDuration PunishDuration = minutesDuration
}, _ => new() },
{ _ => new()
Action = action, {
Seconds = seconds, Action = action,
UserThreshold = userThreshold, Seconds = seconds,
PunishDuration = minutesDuration UserThreshold = userThreshold,
}, () => new() PunishDuration = minutesDuration
{ },
GuildId = guildId () => new()
}); {
GuildId = guildId
});
return stats; return stats;
@ -364,23 +364,25 @@ public class ProtectionService : IReadyExecutor, IEService
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow.GetTable<AntiSpamSetting>() await uow.GetTable<AntiSpamSetting>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = guildId, GuildId = guildId,
Action = stats.AntiSpamSettings.Action, Action = stats.AntiSpamSettings.Action,
MessageThreshold = stats.AntiSpamSettings.MessageThreshold, MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MuteTime = stats.AntiSpamSettings.MuteTime, MuteTime = stats.AntiSpamSettings.MuteTime,
RoleId = stats.AntiSpamSettings.RoleId RoleId = stats.AntiSpamSettings.RoleId
}, (old) => new() },
{ (old) => new()
GuildId = guildId, {
Action = stats.AntiSpamSettings.Action, GuildId = guildId,
MessageThreshold = stats.AntiSpamSettings.MessageThreshold, Action = stats.AntiSpamSettings.Action,
MuteTime = stats.AntiSpamSettings.MuteTime, MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
RoleId = stats.AntiSpamSettings.RoleId MuteTime = stats.AntiSpamSettings.MuteTime,
}, () => new() RoleId = stats.AntiSpamSettings.RoleId
{ },
GuildId = guildId () => new()
}); {
GuildId = guildId
});
return stats; return stats;
} }
@ -405,7 +407,7 @@ public class ProtectionService : IReadyExecutor, IEService
if (spam.IgnoredChannels.All(x => x.ChannelId != channelId)) if (spam.IgnoredChannels.All(x => x.ChannelId != channelId))
{ {
if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache temp.AntiSpamSettings.IgnoredChannels.Add(obj);
spam.IgnoredChannels.Add(obj); spam.IgnoredChannels.Add(obj);
added = true; added = true;
@ -417,7 +419,7 @@ public class ProtectionService : IReadyExecutor, IEService
uow.Set<AntiSpamIgnore>().Remove(toRemove); uow.Set<AntiSpamIgnore>().Remove(toRemove);
if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
temp.AntiSpamSettings.IgnoredChannels.Remove(toRemove); // remove from local cache temp.AntiSpamSettings.IgnoredChannels.RemoveAll(x => x.ChannelId == channelId);
added = false; added = false;
} }
@ -462,22 +464,24 @@ public class ProtectionService : IReadyExecutor, IEService
await uow.GetTable<AntiAltSetting>() await uow.GetTable<AntiAltSetting>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = guildId, GuildId = guildId,
Action = action, Action = action,
ActionDurationMinutes = actionDurationMinutes, ActionDurationMinutes = actionDurationMinutes,
MinAge = TimeSpan.FromMinutes(minAgeMinutes), MinAge = TimeSpan.FromMinutes(minAgeMinutes),
RoleId = roleId RoleId = roleId
}, _ => new() },
{ _ => new()
Action = action, {
ActionDurationMinutes = actionDurationMinutes, Action = action,
MinAge = TimeSpan.FromMinutes(minAgeMinutes), ActionDurationMinutes = actionDurationMinutes,
RoleId = roleId MinAge = TimeSpan.FromMinutes(minAgeMinutes),
}, () => new() RoleId = roleId
{ },
GuildId = guildId () => new()
}); {
GuildId = guildId
});
_antiAltGuilds[guildId] = new(new() _antiAltGuilds[guildId] = new(new()
{ {