diff --git a/application/src/main/java/org/togetherjava/tjbot/features/basic/SlashCommandEducator.java b/application/src/main/java/org/togetherjava/tjbot/features/basic/SlashCommandEducator.java index 9a6e77464a..f2c0d7e24b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/basic/SlashCommandEducator.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/basic/SlashCommandEducator.java @@ -24,7 +24,7 @@ public final class SlashCommandEducator extends MessageReceiverAdapter { private static final Predicate IS_MESSAGE_COMMAND = Pattern.compile(""" [.!?] #Start of message command [a-zA-Z]{2,15} #Name of message command, e.g. 'close' - .* #Rest of the message + .*[^);] #Rest of the message (don't end with code stuff) """, Pattern.COMMENTS).asMatchPredicate(); @Override @@ -48,24 +48,25 @@ private void sendAdvice(Message message) { Try starting your message with a forward-slash `/` and Discord should open a popup showing you all available commands. A command might then look like `/foo` 👍"""; - createReply(message, content, SLASH_COMMAND_POPUP_ADVICE_PATH).queue(); + createReply(message, content).queue(); } - private static MessageCreateAction createReply(Message messageToReplyTo, String content, - String imagePath) { + private static MessageCreateAction createReply(Message messageToReplyTo, String content) { boolean useImage = true; - InputStream imageData = HelpSystemHelper.class.getResourceAsStream("/" + imagePath); + InputStream imageData = + HelpSystemHelper.class.getResourceAsStream("/" + SLASH_COMMAND_POPUP_ADVICE_PATH); if (imageData == null) { useImage = false; } MessageEmbed embed = new EmbedBuilder().setDescription(content) - .setImage(useImage ? "attachment://" + imagePath : null) + .setImage(useImage ? "attachment://" + SLASH_COMMAND_POPUP_ADVICE_PATH : null) .build(); MessageCreateAction action = messageToReplyTo.replyEmbeds(embed); if (useImage) { - action = action.addFiles(FileUpload.fromData(imageData, imagePath)); + action = action + .addFiles(FileUpload.fromData(imageData, SLASH_COMMAND_POPUP_ADVICE_PATH)); } return action; diff --git a/application/src/test/java/org/togetherjava/tjbot/features/basic/SlashCommandEducatorTest.java b/application/src/test/java/org/togetherjava/tjbot/features/basic/SlashCommandEducatorTest.java index 261e1db3af..3b7035dc20 100644 --- a/application/src/test/java/org/togetherjava/tjbot/features/basic/SlashCommandEducatorTest.java +++ b/application/src/test/java/org/togetherjava/tjbot/features/basic/SlashCommandEducatorTest.java @@ -67,7 +67,7 @@ private static Stream provideMessageCommands() { private static Stream provideOtherMessages() { return Stream.of(" a ", "foo", "#foo", "/foo", "!!!", "?!?!?", "?", ".,-", "!f", "! foo", "thisIsAWordWhichLengthIsMoreThanThirtyLetterSoItShouldNotReply", - ".isLetter and .isNumber are available"); - + ".isLetter and .isNumber are available", ".toString()", ".toString();", + "this is a test;"); } }