add channel-specific EveryonePermissions

This commit is contained in:
spiral 2021-08-15 00:38:37 -04:00
parent 0b0ea5af1c
commit 4761804082
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31

View File

@ -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);