feat: respect Discord permissions in pk;message and pk;edit
This commit is contained in:
@@ -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>();
|
||||
|
Reference in New Issue
Block a user