Skip to content

Commit b96771f

Browse files
SlashCommandEducator should check length (#783)
1 parent fdee956 commit b96771f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

application/src/main/java/org/togetherjava/tjbot/features/basic/SlashCommandEducator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* then educates the user about using slash commands, such as {@code /foo} instead.
2020
*/
2121
public final class SlashCommandEducator extends MessageReceiverAdapter {
22+
private static final int MAX_COMMAND_LENGTH = 30;
2223
private static final String SLASH_COMMAND_POPUP_ADVICE_PATH = "slashCommandPopupAdvice.png";
2324
private static final Predicate<String> IS_MESSAGE_COMMAND = Pattern.compile("""
2425
[.!?] #Start of message command
@@ -33,7 +34,8 @@ public void onMessageReceived(MessageReceivedEvent event) {
3334
}
3435

3536
String content = event.getMessage().getContentRaw();
36-
if (IS_MESSAGE_COMMAND.test(content)) {
37+
38+
if (IS_MESSAGE_COMMAND.test(content) && content.length() < MAX_COMMAND_LENGTH) {
3739
sendAdvice(event.getMessage());
3840
}
3941
}

application/src/test/java/org/togetherjava/tjbot/features/basic/SlashCommandEducatorTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ private static Stream<String> provideMessageCommands() {
6565
}
6666

6767
private static Stream<String> provideOtherMessages() {
68-
return Stream.of(" a ", "foo", "#foo", "/foo", "!!!", "?!?!?", "?", ".,-", "!f", "! foo");
68+
return Stream.of(" a ", "foo", "#foo", "/foo", "!!!", "?!?!?", "?", ".,-", "!f", "! foo",
69+
"thisIsAWordWhichLengthIsMoreThanThirtyLetterSoItShouldNotReply",
70+
".isLetter and .isNumber are available");
71+
6972
}
7073
}

0 commit comments

Comments
 (0)