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

@@ -229,9 +229,12 @@ public class ProxyService
if (originalMsg == null)
throw new PKError("Could not reproxy message.");
var messageChannel = await _rest.GetChannelOrNull(msg.Channel!);
var rootChannel = messageChannel.IsThread() ? await _rest.GetChannelOrNull(messageChannel.ParentId!.Value) : messageChannel;
// Get a MessageContext for the original message
MessageContext ctx =
await _repo.GetMessageContext(msg.Sender, msg.Guild!.Value, msg.Channel);
await _repo.GetMessageContext(msg.Sender, msg.Guild!.Value, rootChannel.Id, msg.Channel);
// Make sure proxying is enabled here
if (ctx.InBlacklist)
@@ -250,8 +253,6 @@ public class ProxyService
ProxyTags = member.ProxyTags.FirstOrDefault(),
};
var messageChannel = await _rest.GetChannelOrNull(msg.Channel!);
var rootChannel = messageChannel.IsThread() ? await _rest.GetChannelOrNull(messageChannel.ParentId!.Value) : messageChannel;
var threadId = messageChannel.IsThread() ? messageChannel.Id : (ulong?)null;
var guild = await _rest.GetGuildOrNull(msg.Guild!.Value);
var guildMember = await _rest.GetGuildMember(msg.Guild!.Value, trigger.Author.Id);