From d9c644ec0e983d6d163cf301b79842fb050846c8 Mon Sep 17 00:00:00 2001 From: acw0 Date: Sat, 1 Aug 2020 14:31:46 -0400 Subject: [PATCH] Change "channel not found" error messages to be more ambiguous; also, put them in Errors instead of inline --- PluralKit.Bot/Commands/ServerConfig.cs | 18 +++++++++++------- PluralKit.Bot/Errors.cs | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index b21ea868..d6fa8fcb 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -25,9 +25,11 @@ namespace PluralKit.Bot ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server"); DiscordChannel channel = null; - if (ctx.HasNext()) - channel = await ctx.MatchChannel() ?? throw new PKSyntaxError("You must pass a #channel to set."); - if (channel != null && channel.GuildId != ctx.Guild.Id) throw new PKError("That channel is not in this server!"); + if (!ctx.HasNext()) + throw new PKSyntaxError("You must pass a #channel to set."); + var channelString = ctx.PeekArgument(); + channel = await ctx.MatchChannel(); + if (channel == null || channel.GuildId != ctx.Guild.Id) throw Errors.ChannelNotFound(channelString); var patch = new GuildPatch {LogChannel = channel?.Id}; await _db.Execute(conn => conn.UpsertGuild(ctx.Guild.Id, patch)); @@ -48,8 +50,9 @@ namespace PluralKit.Bot else if (!ctx.HasNext()) throw new PKSyntaxError("You must pass one or more #channels."); else while (ctx.HasNext()) { - var channel = await ctx.MatchChannel() ?? throw new PKSyntaxError($"Channel \"{ctx.PopArgument()}\" not found."); - if (channel.GuildId != ctx.Guild.Id) throw new PKError($"Channel {ctx.Guild.Id} is not in this server."); + var channelString = ctx.PeekArgument(); + var channel = await ctx.MatchChannel(); + if (channel == null || channel.GuildId != ctx.Guild.Id) throw Errors.ChannelNotFound(channelString); affectedChannels.Add(channel); } @@ -127,8 +130,9 @@ namespace PluralKit.Bot else if (!ctx.HasNext()) throw new PKSyntaxError("You must pass one or more #channels."); else while (ctx.HasNext()) { - var channel = await ctx.MatchChannel() ?? throw new PKSyntaxError($"Channel \"{ctx.PopArgument()}\" not found."); - if (channel.GuildId != ctx.Guild.Id) throw new PKError($"Channel {ctx.Guild.Id} is not in this server."); + var channelString = ctx.PeekArgument(); + var channel = await ctx.MatchChannel(); + if (channel == null || channel.GuildId != ctx.Guild.Id) throw Errors.ChannelNotFound(channelString); affectedChannels.Add(channel); } diff --git a/PluralKit.Bot/Errors.cs b/PluralKit.Bot/Errors.cs index c2ab07ce..bef64691 100644 --- a/PluralKit.Bot/Errors.cs +++ b/PluralKit.Bot/Errors.cs @@ -114,5 +114,6 @@ namespace PluralKit.Bot { public static PKError AttachmentTooLarge => new PKError("PluralKit cannot proxy attachments over 8 megabytes (as webhooks aren't considered as having Discord Nitro) :("); public static PKError LookupNotAllowed => new PKError("You do not have permission to access this information."); + public static PKError ChannelNotFound(string channelString) => new PKError($"Channel \"{channelString}\" not found or is not in this server."); } } \ No newline at end of file