Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make .config <enum item> parse case-insensitively, and list possible values on failure #505

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Izzy-Moonbot/Modules/ConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ await context.Channel.SendMessageAsync(
Enum? output = null;
if (value != null)
{
if (!Enum.TryParse(enumType, value, out var res))
if (!Enum.TryParse(enumType, value, true /* ignoreCase */, out var res))
throw new FormatException(); // Trip "invalid content" catch below.
output = res as Enum;
}
Expand All @@ -273,7 +273,8 @@ await context.Channel.SendMessageAsync($"I've set `{configItemKey}` to the follo
catch (FormatException)
{
await context.Channel.SendMessageAsync(
$"I couldn't set `{configItemKey}` to the content provided because you provided content that I couldn't turn into this specific enum type ({enumType.Name}). Please try again.",
$"I couldn't set `{configItemKey}` to `{value}` because that's not a possible value for the {enumType.Name} enum type.\n" +
$"Possible values are: {String.Join(", ", enumType.GetEnumNames().Select(n => $"`{n}`"))}",
allowedMentions: AllowedMentions.None);
}
break;
Expand Down
Loading