mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat: respect Discord permissions in pk;message and pk;edit
This commit is contained in:
parent
48d4009c69
commit
343fafe9f0
5 changed files with 64 additions and 24 deletions
|
|
@ -169,29 +169,15 @@ namespace PluralKit.Bot
|
|||
throw new PKSyntaxError("You need to specify a channel.");
|
||||
|
||||
var error = "Channel not found or you do not have permissions to access it.";
|
||||
|
||||
var channel = await ctx.MatchChannel();
|
||||
if (channel == null || channel.GuildId == null)
|
||||
throw new PKError(error);
|
||||
|
||||
var guild = _cache.GetGuild(channel.GuildId.Value);
|
||||
if (guild == null)
|
||||
if (!await ctx.CheckPermissionsInGuildChannel(channel, PermissionSet.ViewChannel))
|
||||
throw new PKError(error);
|
||||
|
||||
var guildMember = await _rest.GetGuildMember(channel.GuildId.Value, ctx.Author.Id);
|
||||
if (guildMember == null)
|
||||
throw new PKError(error);
|
||||
|
||||
|
||||
|
||||
var botPermissions = _bot.PermissionsIn(channel.Id);
|
||||
var webhookPermissions = _cache.EveryonePermissions(channel);
|
||||
var userPermissions = PermissionExtensions.PermissionsFor(guild, channel, ctx.Author.Id, guildMember);
|
||||
|
||||
if ((userPermissions & PermissionSet.ViewChannel) == 0)
|
||||
throw new PKError(error);
|
||||
|
||||
|
||||
|
||||
// We use a bitfield so we can set individual permission bits
|
||||
ulong missingPermissions = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue