From 476180408209a53863ac3db7bbfb97ba1a0ae96a Mon Sep 17 00:00:00 2001 From: spiral Date: Sun, 15 Aug 2021 00:38:37 -0400 Subject: [PATCH] add channel-specific EveryonePermissions --- Myriad/Extensions/PermissionExtensions.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Myriad/Extensions/PermissionExtensions.cs b/Myriad/Extensions/PermissionExtensions.cs index dc324590..e5479c4d 100644 --- a/Myriad/Extensions/PermissionExtensions.cs +++ b/Myriad/Extensions/PermissionExtensions.cs @@ -38,6 +38,22 @@ namespace Myriad.Extensions public static PermissionSet EveryonePermissions(this Guild guild) => guild.Roles.FirstOrDefault(r => r.Id == guild.Id)?.Permissions ?? PermissionSet.Dm; + public static PermissionSet EveryonePermissions(this IDiscordCache cache, Channel channel) + { + if (channel.Type == Channel.ChannelType.Dm) + return PermissionSet.Dm; + + var overwrite = channel.PermissionOverwrites?.FirstOrDefault(r => r.Id == channel.GuildId); + if (overwrite == null) + return cache.GetGuild(channel.GuildId!.Value).EveryonePermissions(); + + var perms = PermissionSet.None; + perms &= ~overwrite.Deny; + perms |= overwrite.Allow; + + return perms; + } + public static PermissionSet PermissionsFor(Guild guild, Channel channel, MessageCreateEvent msg) => PermissionsFor(guild, channel, msg.Author.Id, msg.Member);