Clean up getting guild/member

This commit is contained in:
acw0 2020-07-25 07:17:34 -04:00 committed by Astrid
parent bf07294f5f
commit 1138c1a2a9

View File

@ -94,10 +94,12 @@ namespace PluralKit.Bot {
public async Task PermCheckGuild(Context ctx) public async Task PermCheckGuild(Context ctx)
{ {
DiscordGuild guild; DiscordGuild guild;
DiscordMember senderGuildUser;
if (ctx.Guild != null && !ctx.HasNext()) if (ctx.Guild != null && !ctx.HasNext())
{ {
guild = ctx.Guild; guild = ctx.Guild;
senderGuildUser = (DiscordMember)ctx.Author;
} }
else else
{ {
@ -106,15 +108,11 @@ namespace PluralKit.Bot {
throw new PKSyntaxError($"Could not parse `{guildIdStr}` as an ID."); throw new PKSyntaxError($"Could not parse `{guildIdStr}` as an ID.");
guild = ctx.Client.GetGuild(guildId); guild = ctx.Client.GetGuild(guildId);
if (guild == null) if (guild == null) throw Errors.GuildNotFound(guildId);
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 [] var requiredPermissions = new []
{ {
Permissions.AccessChannels, Permissions.AccessChannels,