From 1138c1a2a92bb79afb231c3dff7a93d3a73cecca Mon Sep 17 00:00:00 2001 From: acw0 Date: Sat, 25 Jul 2020 07:17:34 -0400 Subject: [PATCH] Clean up getting guild/member --- PluralKit.Bot/Commands/Misc.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/PluralKit.Bot/Commands/Misc.cs b/PluralKit.Bot/Commands/Misc.cs index 4f464fb0..f95bb1d7 100644 --- a/PluralKit.Bot/Commands/Misc.cs +++ b/PluralKit.Bot/Commands/Misc.cs @@ -94,10 +94,12 @@ namespace PluralKit.Bot { public async Task PermCheckGuild(Context ctx) { DiscordGuild guild; + DiscordMember senderGuildUser; if (ctx.Guild != null && !ctx.HasNext()) { guild = ctx.Guild; + senderGuildUser = (DiscordMember)ctx.Author; } else { @@ -106,14 +108,10 @@ namespace PluralKit.Bot { throw new PKSyntaxError($"Could not parse `{guildIdStr}` as an ID."); guild = ctx.Client.GetGuild(guildId); - if (guild == null) - throw Errors.GuildNotFound(guildId); + if (guild == null) throw Errors.GuildNotFound(guildId); + senderGuildUser = await guild.GetMember(ctx.Author.Id); + if (senderGuildUser == null) throw Errors.GuildNotFound(guildId); } - - // Ensure people can't query guilds they're not in + get their own permissions (for view access checking) - var senderGuildUser = await guild.GetMember(ctx.Author.Id); - if (senderGuildUser == null) - throw new PKError("You must be a member of the guild you are querying."); var requiredPermissions = new [] {