From e0612f90a8e67e76efc185df5a33ababdc87d307 Mon Sep 17 00:00:00 2001 From: anthorob Date: Sat, 21 Dec 2024 21:12:28 -0500 Subject: [PATCH] fix(MessageCommandContext): missing check for channel when option is of type STRING --- .../context/MessageCommandContext.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/bobert/netneutrality/context/MessageCommandContext.java b/src/main/java/me/bobert/netneutrality/context/MessageCommandContext.java index 7570f7b..b319386 100644 --- a/src/main/java/me/bobert/netneutrality/context/MessageCommandContext.java +++ b/src/main/java/me/bobert/netneutrality/context/MessageCommandContext.java @@ -131,8 +131,8 @@ public class MessageCommandContext extends CommandContext { case STRING -> { String str = args[index]; - if (str.contains("<@") && str.contains(">")) { - invalidateContext(data, "expected a string at index " + index + " but a role/user/channel was provided"); + if ((str.contains("<@") || str.contains("<#")) && str.contains(">")) { + invalidateContext(data, "expected a string at position " + (index + 1) + " but a role/user/channel was provided"); break; } @@ -216,7 +216,7 @@ public class MessageCommandContext extends CommandContext { break; } - invalidateContext(data, "provided argument at index " + roleMentionIndex + " is not a valid role."); + invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid role."); } case USER -> { if (mentions.getMembers().size() > memberMentionIndex) { @@ -232,7 +232,7 @@ public class MessageCommandContext extends CommandContext { break; } - invalidateContext(data, "provided argument is not a valid user."); + invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid user."); } case MENTIONABLE -> { if (mentions.getRoles().size() > roleMentionIndex) { @@ -258,14 +258,14 @@ public class MessageCommandContext extends CommandContext { break; } - invalidateContext(data, "provided argument is not a valid user or role."); + invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid user or role."); } case CHANNEL -> { if (mentions.getChannels().size() > channelMentionIndex) { GuildChannel channel = mentions.getChannels().get(channelMentionIndex++); if (!requiredChannelTypes.contains(channel.getType())) { - invalidateContext(data, "not a valid channel type at index " + (channelMentionIndex -1) + + invalidateContext(data, "not a valid channel type at index " + (index + 1) + " , valid types are: " + validTypes(requiredChannelTypes)); break; } @@ -276,7 +276,7 @@ public class MessageCommandContext extends CommandContext { } } - invalidateContext(data, "provided argument is not a valid channel."); + invalidateContext(data, "provided argument at position " + (index + 1) + " is not a valid channel."); } } } catch (IndexOutOfBoundsException e) { @@ -285,7 +285,7 @@ public class MessageCommandContext extends CommandContext { throw new IllegalArgumentException("Required option " + data.getName() + " was not found at index " + index); } } catch (NumberFormatException ignored) { - invalidateContext(data, "the argument provided was not a number."); + invalidateContext(data, "the argument provided is not a number."); } if (value != null) {