From 4e98a51363d5857a7bdf8092f4f704b560c3db25 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 27 Oct 2019 21:58:04 +0100 Subject: [PATCH] Fix PermCheck permissions and no-guild invocation syntax --- PluralKit.Bot/Commands/MiscCommands.cs | 34 ++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/PluralKit.Bot/Commands/MiscCommands.cs b/PluralKit.Bot/Commands/MiscCommands.cs index 4ddf56e3..cc78562d 100644 --- a/PluralKit.Bot/Commands/MiscCommands.cs +++ b/PluralKit.Bot/Commands/MiscCommands.cs @@ -58,17 +58,31 @@ namespace PluralKit.Bot.Commands { public async Task PermCheckGuild(Context ctx) { - var guildIdStr = ctx.PopArgument() ?? throw new PKSyntaxError("You must pass a server ID."); - if (!ulong.TryParse(guildIdStr, out var guildId)) throw new PKSyntaxError($"Could not parse `{guildIdStr.SanitizeMentions()}` as an ID."); - - // TODO: will this call break for sharding if you try to request a guild on a different bot instance? - var guild = ctx.Client.GetGuild(guildId) as IGuild; - if (guild == null) - throw Errors.GuildNotFound(guildId); - + IGuild guild; + + if (ctx.Guild != null && !ctx.HasNext()) + { + guild = ctx.Guild; + } + else + { + var guildIdStr = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must pass a server ID or run this command as ."); + if (!ulong.TryParse(guildIdStr, out var guildId)) + throw new PKSyntaxError($"Could not parse `{guildIdStr.SanitizeMentions()}` as an ID."); + + // TODO: will this call break for sharding if you try to request a guild on a different bot instance? + guild = ctx.Client.GetGuild(guildId); + if (guild == null) + throw Errors.GuildNotFound(guildId); + } + var requiredPermissions = new [] { - ChannelPermission.ViewChannel, // Manage Messages automatically grants Send and Add Reactions, but not Read + ChannelPermission.ViewChannel, + ChannelPermission.SendMessages, + ChannelPermission.AddReactions, + ChannelPermission.AttachFiles, + ChannelPermission.EmbedLinks, ChannelPermission.ManageMessages, ChannelPermission.ManageWebhooks }; @@ -116,7 +130,7 @@ namespace PluralKit.Bot.Commands { var channelsList = string.Join("\n", channels .OrderBy(c => c.Position) .Select(c => $"#{c.Name}")); - eb.AddField($"Missing *{missingPermissionNames}*", channelsList); + eb.AddField($"Missing *{missingPermissionNames}*", channelsList.Truncate(1000)); eb.WithColor(Color.Red); } }