Users who have manage messages perm in the channel will now be excluded from link and invite filtering

This commit is contained in:
Kwoth
2024-04-24 23:13:32 +00:00
parent e1d027eaf5
commit a04a427af2

View File

@@ -33,13 +33,13 @@ public sealed class FilterService : IExecOnMessage
{ {
var ids = client.GetGuildIds(); var ids = client.GetGuildIds();
var configs = uow.Set<GuildConfig>() var configs = uow.Set<GuildConfig>()
.AsQueryable() .AsQueryable()
.Include(x => x.FilteredWords) .Include(x => x.FilteredWords)
.Include(x => x.FilterLinksChannelIds) .Include(x => x.FilterLinksChannelIds)
.Include(x => x.FilterWordsChannelIds) .Include(x => x.FilterWordsChannelIds)
.Include(x => x.FilterInvitesChannelIds) .Include(x => x.FilterInvitesChannelIds)
.Where(gc => ids.Contains(gc.GuildId)) .Where(gc => ids.Contains(gc.GuildId))
.ToList(); .ToList();
InviteFilteringServers = new(configs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId)); InviteFilteringServers = new(configs.Where(gc => gc.FilterInvites).Select(gc => gc.GuildId));
InviteFilteringChannels = InviteFilteringChannels =
@@ -168,6 +168,10 @@ public sealed class FilterService : IExecOnMessage
if (usrMsg is null) if (usrMsg is null)
return false; return false;
// if user has manage messages perm, don't filter
if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages)
return false;
if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id)) if ((InviteFilteringChannels.Contains(usrMsg.Channel.Id) || InviteFilteringServers.Contains(guild.Id))
&& usrMsg.Content.IsDiscordInvite()) && usrMsg.Content.IsDiscordInvite())
{ {
@@ -200,6 +204,10 @@ public sealed class FilterService : IExecOnMessage
if (usrMsg is null) if (usrMsg is null)
return false; return false;
// if user has manage messages perm, don't filter
if (usrMsg.Channel is ITextChannel ch && usrMsg.Author is IGuildUser gu && gu.GetPermissions(ch).ManageMessages)
return false;
if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id)) if ((LinkFilteringChannels.Contains(usrMsg.Channel.Id) || LinkFilteringServers.Contains(guild.Id))
&& usrMsg.Content.TryGetUrlPath(out _)) && usrMsg.Content.TryGetUrlPath(out _))
{ {
@@ -226,9 +234,10 @@ public sealed class FilterService : IExecOnMessage
public async Task<ServerFilterSettings> GetFilterSettings(ulong guildId) public async Task<ServerFilterSettings> GetFilterSettings(ulong guildId)
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var gc = uow.GuildConfigsForId(guildId, set => set var gc = uow.GuildConfigsForId(guildId,
.Include(x => x.FilterInvitesChannelIds) set => set
.Include(x => x.FilterLinksChannelIds)); .Include(x => x.FilterInvitesChannelIds)
.Include(x => x.FilterLinksChannelIds));
return new() return new()
{ {