From 33ba0b268141ac6c3d2ab72dd75a0fba874aaf61 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 7 Apr 2022 15:21:11 +0300 Subject: [PATCH 1/3] Fix CommandClientImpl#getParts thrown an IOB --- .../jdautilities/command/impl/CommandClientImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index dbd47911..7490b506 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -822,10 +822,13 @@ private MessageParts getParts(MessageReceivedEvent event) { if(rawContent.startsWith("<@"+ event.getJDA().getSelfUser().getId()+">") || rawContent.startsWith("<@!"+ event.getJDA().getSelfUser().getId()+">")) { // Since we now use substring into makeMessageParts function and a indexOf here, we need to do a +1 to get the good substring - // On top of that we need to do another +1 because the default @mention prefix will always be followed by a space - // So we need to add 2 characters to get the correct substring - final int prefixLength = rawContent.indexOf('>') + 2; - return makeMessageParts(rawContent, prefixLength); + final var mentionEndIndex = rawContent.indexOf('>') + 1; + // Make sure that the content isn't just the mention + if (rawContent.length() >= mentionEndIndex + 1) { + // On top of that we need to do another +1 because the default @mention prefix will always be followed by a space + final int prefixLength = rawContent.indexOf('>') + 2; + return makeMessageParts(rawContent, prefixLength); + } } } From 4d782f8412c61b13c7e1a7e91b0ec6013a2b3fa6 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 7 Apr 2022 15:30:47 +0300 Subject: [PATCH 2/3] Don't use `var` --- .../jagrosh/jdautilities/command/impl/CommandClientImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index 7490b506..dbe5750a 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -822,7 +822,7 @@ private MessageParts getParts(MessageReceivedEvent event) { if(rawContent.startsWith("<@"+ event.getJDA().getSelfUser().getId()+">") || rawContent.startsWith("<@!"+ event.getJDA().getSelfUser().getId()+">")) { // Since we now use substring into makeMessageParts function and a indexOf here, we need to do a +1 to get the good substring - final var mentionEndIndex = rawContent.indexOf('>') + 1; + final int mentionEndIndex = rawContent.indexOf('>') + 1; // Make sure that the content isn't just the mention if (rawContent.length() >= mentionEndIndex + 1) { // On top of that we need to do another +1 because the default @mention prefix will always be followed by a space From 59c4bca85cdcea047bab579fab7421d051767cd1 Mon Sep 17 00:00:00 2001 From: matyrobbrt Date: Wed, 20 Apr 2022 13:50:15 +0300 Subject: [PATCH 3/3] Update command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java Co-authored-by: freya02 <41875020+freya022@users.noreply.github.com> --- .../jagrosh/jdautilities/command/impl/CommandClientImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index dbe5750a..d95d13f4 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -819,8 +819,8 @@ private MessageParts getParts(MessageReceivedEvent event) { // Check for prefix or alternate prefix (@mention cases) if(prefix.equals(DEFAULT_PREFIX) || (altprefix != null && altprefix.equals(DEFAULT_PREFIX))) { - if(rawContent.startsWith("<@"+ event.getJDA().getSelfUser().getId()+">") || - rawContent.startsWith("<@!"+ event.getJDA().getSelfUser().getId()+">")) { + if(rawContent.startsWith("<@"+ event.getJDA().getSelfUser().getId()+"> ") || //Ensure that there is a space between the command and the mention + rawContent.startsWith("<@!"+ event.getJDA().getSelfUser().getId()+"> ")) { // Since we now use substring into makeMessageParts function and a indexOf here, we need to do a +1 to get the good substring final int mentionEndIndex = rawContent.indexOf('>') + 1; // Make sure that the content isn't just the mention