aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/server')
-rw-r--r--juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java32
1 files changed, 14 insertions, 18 deletions
diff --git a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java
index 2597ddbc..6ad177a8 100644
--- a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java
+++ b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java
@@ -15,10 +15,7 @@ import org.apache.commons.lang3.reflect.MethodUtils;
import javax.inject.Inject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -68,10 +65,10 @@ public class JuickProtocol {
.findFirst();
if (!cmd.isPresent()) {
// default command - post as new message
- return postMessage(user, userInput);
+ return postMessage(user, userInput.trim());
} else {
Matcher matcher = Pattern.compile(cmd.get().getAnnotation(UserCommand.class).pattern(),
- cmd.get().getAnnotation(UserCommand.class).patternFlags()).matcher(userInput);
+ cmd.get().getAnnotation(UserCommand.class).patternFlags()).matcher(userInput.trim());
List<String> groups = new ArrayList<>();
while (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); i++) {
@@ -92,17 +89,16 @@ public class JuickProtocol {
return new ProtocolReply("New message posted.\n#" + mid + " " + baseUri + mid);
}
- @UserCommand(pattern = "^#(\\++)$", help = "#+ - Show last Juick messages (#++ - second page, ...)")
+ @UserCommand(pattern = "^#\\+$", help = "#+ - Show last Juick messages")
public ProtocolReply commandLast(User user, String... arguments) {
- // number of + is the page count
- int page = arguments[0].length() - 1;
- List<Integer> mids = messagesService.getAll(user.getUid(), page);
+ List<Integer> mids = messagesService.getAll(user.getUid(), 0);
List<Message> messages = messagesService.getMessages(mids);
- return new ProtocolReply("Last messages: \n" + String.join("\n", messages.stream().map(PlainTextFormatter::formatPost)
- .collect(Collectors.toList())));
+ return new ProtocolReply("Last messages: \n"
+ + messages.stream().sorted(Collections.reverseOrder()).map(PlainTextFormatter::formatPostSummary)
+ .collect(Collectors.joining("\n\n")));
}
- @UserCommand(pattern = "^\\s*bl\\s*$", patternFlags = Pattern.CASE_INSENSITIVE,
+ @UserCommand(pattern = "^bl$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "BL - Show your blacklist")
public ProtocolReply commandBL(User user_from, String... arguments) {
List<User> blusers;
@@ -238,7 +234,7 @@ public class JuickProtocol {
return new ProtocolReply("User not found");
}
- @UserCommand(pattern = "^\\s*d\\s*\\#([0-9]+)\\s*$", patternFlags = Pattern.CASE_INSENSITIVE,
+ @UserCommand(pattern = "^d\\s*\\#([0-9]+)$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "D #12345 - delete the message")
public ProtocolReply commandDel(User user, String... args) {
int mid = NumberUtils.toInt(args[0], 0);
@@ -248,7 +244,7 @@ public class JuickProtocol {
return new ProtocolReply("Error");
}
- @UserCommand(pattern = "^\\s*login\\s*$", patternFlags = Pattern.CASE_INSENSITIVE,
+ @UserCommand(pattern = "^login$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "LOGIN - log in to Juick website")
public ProtocolReply commandLogin(User user, String... arguments) {
return new ProtocolReply(baseUri + "?" + userService.getHashByUID(user.getUid()));
@@ -265,7 +261,7 @@ public class JuickProtocol {
messages.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList())));
}
- @UserCommand(pattern = "^\\s*(on|off)\\s*$", patternFlags = Pattern.CASE_INSENSITIVE,
+ @UserCommand(pattern = "^(on|off)$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "ON/OFF - Enable/disable subscriptions delivery")
public ProtocolReply commandOnOff(User user, String[] input) {
UserService.ActiveStatus newStatus;
@@ -285,7 +281,7 @@ public class JuickProtocol {
}
}
- @UserCommand(pattern = "^\\s*ping\\s*$", patternFlags = Pattern.CASE_INSENSITIVE,
+ @UserCommand(pattern = "^ping$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "PING - returns you a PONG")
public ProtocolReply commandPing(User user, String[] input) {
return new ProtocolReply("PONG");
@@ -409,7 +405,7 @@ public class JuickProtocol {
return new ProtocolReply("Error");
}
- @UserCommand(pattern = "^\\s*help\\s*$", patternFlags = Pattern.CASE_INSENSITIVE,
+ @UserCommand(pattern = "^help$", patternFlags = Pattern.CASE_INSENSITIVE,
help = "HELP - returns this help message")
public ProtocolReply commandHelp(User user, String[] input) {
List<String> commandsHelp = Arrays.stream(getClass().getDeclaredMethods())