.antispamignore will now be properly toggled off, and ignore the channel

This commit is contained in:
Toastie 2025-03-20 21:57:41 +13:00
parent c522abe856
commit 2eb973ccd3
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7

View file

@ -27,6 +27,7 @@ public class ProtectionService : IReadyExecutor, IEService
private readonly UserPunishService _punishService;
private readonly INotifySubscriber _notifySub;
private readonly ShardData _shardData;
private readonly Channel<PunishQueueItem> _punishUserQueue =
Channel.CreateUnbounded<PunishQueueItem>(new()
{
@ -176,10 +177,7 @@ public class ProtectionService : IReadyExecutor, IEService
try
{
if (!_antiSpamGuilds.TryGetValue(channel.Guild.Id, out var spamSettings)
|| spamSettings.AntiSpamSettings.IgnoredChannels.Contains(new()
{
ChannelId = channel.Id
}))
|| spamSettings.AntiSpamSettings.IgnoredChannels.Any(x => x.ChannelId == channel.Id))
return;
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id,
@ -282,13 +280,15 @@ public class ProtectionService : IReadyExecutor, IEService
Seconds = seconds,
UserThreshold = userThreshold,
PunishDuration = minutesDuration
}, _ => new()
},
_ => new()
{
Action = action,
Seconds = seconds,
UserThreshold = userThreshold,
PunishDuration = minutesDuration
}, () => new()
},
() => new()
{
GuildId = guildId
});
@ -370,14 +370,16 @@ public class ProtectionService : IReadyExecutor, IEService
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MuteTime = stats.AntiSpamSettings.MuteTime,
RoleId = stats.AntiSpamSettings.RoleId
}, (old) => new()
},
(old) => new()
{
GuildId = guildId,
Action = stats.AntiSpamSettings.Action,
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MuteTime = stats.AntiSpamSettings.MuteTime,
RoleId = stats.AntiSpamSettings.RoleId
}, () => new()
},
() => new()
{
GuildId = guildId
});
@ -405,7 +407,7 @@ public class ProtectionService : IReadyExecutor, IEService
if (spam.IgnoredChannels.All(x => x.ChannelId != channelId))
{
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);
added = true;
@ -417,7 +419,7 @@ public class ProtectionService : IReadyExecutor, IEService
uow.Set<AntiSpamIgnore>().Remove(toRemove);
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;
}
@ -468,13 +470,15 @@ public class ProtectionService : IReadyExecutor, IEService
ActionDurationMinutes = actionDurationMinutes,
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
RoleId = roleId
}, _ => new()
},
_ => new()
{
Action = action,
ActionDurationMinutes = actionDurationMinutes,
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
RoleId = roleId
}, () => new()
},
() => new()
{
GuildId = guildId
});