diff --git a/Myriad/Extensions/PermissionExtensions.cs b/Myriad/Extensions/PermissionExtensions.cs index 8b718dce..48fc9718 100644 --- a/Myriad/Extensions/PermissionExtensions.cs +++ b/Myriad/Extensions/PermissionExtensions.cs @@ -39,7 +39,8 @@ public static class PermissionExtensions PermissionsFor(cache, channelId, member.User.Id, member); public static async Task PermissionsFor(this IDiscordCache cache, ulong channelId, ulong userId, - GuildMemberPartial? member, bool isWebhook = false) + GuildMemberPartial? member, bool isWebhook = false, + bool isThread = false) { if (!(await cache.TryGetChannel(channelId) is Channel channel)) // todo: handle channel not found better @@ -55,7 +56,7 @@ public static class PermissionExtensions if (isWebhook) return EveryonePermissions(guild); - return PermissionsFor(guild, rootChannel, userId, member); + return PermissionsFor(guild, rootChannel, userId, member, isThread: isThread); } public static PermissionSet EveryonePermissions(this Guild guild) => @@ -78,11 +79,11 @@ public static class PermissionExtensions return perms; } - public static PermissionSet PermissionsFor(Guild guild, Channel channel, MessageCreateEvent msg) => - PermissionsFor(guild, channel, msg.Author.Id, msg.Member); + public static PermissionSet PermissionsFor(Guild guild, Channel channel, MessageCreateEvent msg, bool isThread = false) => + PermissionsFor(guild, channel, msg.Author.Id, msg.Member, isThread: isThread); public static PermissionSet PermissionsFor(Guild guild, Channel channel, ulong userId, - GuildMemberPartial? member) + GuildMemberPartial? member, bool isThread = false) { if (channel.Type == Channel.ChannelType.Dm) return PermissionSet.Dm; @@ -100,7 +101,7 @@ public static class PermissionExtensions if ((perms & PermissionSet.ViewChannel) == 0) perms &= ~NeedsViewChannel; - if ((perms & PermissionSet.SendMessages) == 0) + if ((perms & PermissionSet.SendMessages) == 0 && (!isThread || (perms & PermissionSet.SendMessagesInThreads) == 0)) perms &= ~NeedsSendMessages; return perms; diff --git a/Myriad/Types/PermissionSet.cs b/Myriad/Types/PermissionSet.cs index 2873a3ff..177ebd18 100644 --- a/Myriad/Types/PermissionSet.cs +++ b/Myriad/Types/PermissionSet.cs @@ -34,6 +34,7 @@ public enum PermissionSet: ulong ManageRoles = 0x10000000, ManageWebhooks = 0x20000000, ManageEmojis = 0x40000000, + SendMessagesInThreads = 0x04000000000, // Special: None = 0, diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index ca85c396..113f3ffd 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -100,7 +100,7 @@ public class ProxyService // Check if the sender account can mention everyone/here + embed links // we need to "mirror" these permissions when proxying to prevent exploits - var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, message); + var senderPermissions = PermissionExtensions.PermissionsFor(guild, rootChannel, message, isThread: rootChannel.Id != channel.Id); var allowEveryone = senderPermissions.HasFlag(PermissionSet.MentionEveryone); var allowEmbeds = senderPermissions.HasFlag(PermissionSet.EmbedLinks);