mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +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
|
|
@ -1,7 +1,9 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Autofac;
|
||||
|
||||
using Myriad.Extensions;
|
||||
using Myriad.Types;
|
||||
|
||||
using PluralKit.Core;
|
||||
|
|
@ -57,6 +59,28 @@ namespace PluralKit.Bot
|
|||
return ctx;
|
||||
}
|
||||
|
||||
public static async Task<bool> CheckPermissionsInGuildChannel(this Context ctx, Channel channel, PermissionSet neededPerms)
|
||||
{
|
||||
var guild = ctx.Cache.GetGuild(channel.GuildId.Value);
|
||||
if (guild == null)
|
||||
return false;
|
||||
|
||||
var guildMember = ctx.Member;
|
||||
|
||||
if (ctx.Guild?.Id != channel.GuildId)
|
||||
{
|
||||
guildMember = await ctx.Rest.GetGuildMember(channel.GuildId.Value, ctx.Author.Id);
|
||||
if (guildMember == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
var userPermissions = PermissionExtensions.PermissionsFor(guild, channel, ctx.Author.Id, guildMember);
|
||||
if ((userPermissions & neededPerms) == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CheckBotAdmin(this Context ctx)
|
||||
{
|
||||
var botConfig = ctx.Services.Resolve<BotConfig>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue