fix(bot): make proxy/log blacklists work properly with threads

Handling of both blacklists was inconsistent when dealing with threads:
- proxy blacklist of root channel blacklists all threads
- log blacklist of root channel _did not apply_ to threads
- couldn't proxy blacklist threads while leaving root channel proxyable

This change fixes the inconsistencies:
- proxy _and_ log blacklist of root channel affects all threads
- now able to individually proxy/log blacklist threads, with root
  channel unaffected
This commit is contained in:
Iris System
2023-05-10 13:16:16 +12:00
parent 24f0fcd563
commit 66544b9d40
7 changed files with 34 additions and 26 deletions

View File

@@ -17,6 +17,7 @@ public class Checks
private readonly ProxyMatcher _matcher;
private readonly ProxyService _proxy;
private readonly DiscordApiClient _rest;
private readonly IDiscordCache _cache;
private readonly PermissionSet[] requiredPermissions =
{
@@ -26,12 +27,13 @@ public class Checks
};
// todo: make sure everything uses the minimum amount of REST calls necessary
public Checks(DiscordApiClient rest, BotConfig botConfig, ProxyService proxy, ProxyMatcher matcher)
public Checks(DiscordApiClient rest, BotConfig botConfig, ProxyService proxy, ProxyMatcher matcher, IDiscordCache cache)
{
_rest = rest;
_botConfig = botConfig;
_proxy = proxy;
_matcher = matcher;
_cache = cache;
}
public async Task PermCheckGuild(Context ctx)
@@ -230,11 +232,12 @@ public class Checks
if (channel == null)
throw new PKError("Unable to get the channel associated with this message.");
var rootChannel = await _cache.GetRootChannel(channel.Id);
if (channel.GuildId == null)
throw new PKError("PluralKit is not able to proxy messages in DMs.");
// using channel.GuildId here since _rest.GetMessage() doesn't return the GuildId
var context = await ctx.Repository.GetMessageContext(msg.Author.Id, channel.GuildId.Value, msg.ChannelId);
var context = await ctx.Repository.GetMessageContext(msg.Author.Id, channel.GuildId.Value, rootChannel.Id, msg.ChannelId);
var members = (await ctx.Repository.GetProxyMembers(msg.Author.Id, channel.GuildId.Value)).ToList();
// for now this is just server