fix(bot): make EmbedLinks permission check work with threads
This commit is contained in:
parent
71c61e93b5
commit
97666a62df
@ -39,7 +39,8 @@ public static class PermissionExtensions
|
|||||||
PermissionsFor(cache, channelId, member.User.Id, member);
|
PermissionsFor(cache, channelId, member.User.Id, member);
|
||||||
|
|
||||||
public static async Task<PermissionSet> PermissionsFor(this IDiscordCache cache, ulong channelId, ulong userId,
|
public static async Task<PermissionSet> 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))
|
if (!(await cache.TryGetChannel(channelId) is Channel channel))
|
||||||
// todo: handle channel not found better
|
// todo: handle channel not found better
|
||||||
@ -55,7 +56,7 @@ public static class PermissionExtensions
|
|||||||
if (isWebhook)
|
if (isWebhook)
|
||||||
return EveryonePermissions(guild);
|
return EveryonePermissions(guild);
|
||||||
|
|
||||||
return PermissionsFor(guild, rootChannel, userId, member);
|
return PermissionsFor(guild, rootChannel, userId, member, isThread: isThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PermissionSet EveryonePermissions(this Guild guild) =>
|
public static PermissionSet EveryonePermissions(this Guild guild) =>
|
||||||
@ -78,11 +79,11 @@ public static class PermissionExtensions
|
|||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PermissionSet PermissionsFor(Guild guild, Channel channel, MessageCreateEvent msg) =>
|
public static PermissionSet PermissionsFor(Guild guild, Channel channel, MessageCreateEvent msg, bool isThread = false) =>
|
||||||
PermissionsFor(guild, channel, msg.Author.Id, msg.Member);
|
PermissionsFor(guild, channel, msg.Author.Id, msg.Member, isThread: isThread);
|
||||||
|
|
||||||
public static PermissionSet PermissionsFor(Guild guild, Channel channel, ulong userId,
|
public static PermissionSet PermissionsFor(Guild guild, Channel channel, ulong userId,
|
||||||
GuildMemberPartial? member)
|
GuildMemberPartial? member, bool isThread = false)
|
||||||
{
|
{
|
||||||
if (channel.Type == Channel.ChannelType.Dm)
|
if (channel.Type == Channel.ChannelType.Dm)
|
||||||
return PermissionSet.Dm;
|
return PermissionSet.Dm;
|
||||||
@ -100,7 +101,7 @@ public static class PermissionExtensions
|
|||||||
if ((perms & PermissionSet.ViewChannel) == 0)
|
if ((perms & PermissionSet.ViewChannel) == 0)
|
||||||
perms &= ~NeedsViewChannel;
|
perms &= ~NeedsViewChannel;
|
||||||
|
|
||||||
if ((perms & PermissionSet.SendMessages) == 0)
|
if ((perms & PermissionSet.SendMessages) == 0 && (!isThread || (perms & PermissionSet.SendMessagesInThreads) == 0))
|
||||||
perms &= ~NeedsSendMessages;
|
perms &= ~NeedsSendMessages;
|
||||||
|
|
||||||
return perms;
|
return perms;
|
||||||
|
@ -34,6 +34,7 @@ public enum PermissionSet: ulong
|
|||||||
ManageRoles = 0x10000000,
|
ManageRoles = 0x10000000,
|
||||||
ManageWebhooks = 0x20000000,
|
ManageWebhooks = 0x20000000,
|
||||||
ManageEmojis = 0x40000000,
|
ManageEmojis = 0x40000000,
|
||||||
|
SendMessagesInThreads = 0x04000000000,
|
||||||
|
|
||||||
// Special:
|
// Special:
|
||||||
None = 0,
|
None = 0,
|
||||||
|
@ -100,7 +100,7 @@ public class ProxyService
|
|||||||
|
|
||||||
// Check if the sender account can mention everyone/here + embed links
|
// Check if the sender account can mention everyone/here + embed links
|
||||||
// we need to "mirror" these permissions when proxying to prevent exploits
|
// 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 allowEveryone = senderPermissions.HasFlag(PermissionSet.MentionEveryone);
|
||||||
var allowEmbeds = senderPermissions.HasFlag(PermissionSet.EmbedLinks);
|
var allowEmbeds = senderPermissions.HasFlag(PermissionSet.EmbedLinks);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user