diff options
author | Vitaly Takmazov | 2018-02-25 09:04:17 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-21 11:45:00 +0300 |
commit | 9b201b07dc6caa147ea79b359e448f2649353039 (patch) | |
tree | 02f732c7ba6e249a4b65998c4584c14d1c0cb91c /juick-server | |
parent | 1e4198d2aad02eca56157fcd24425a1eaa6041ee (diff) |
xmpp: recommend command
Diffstat (limited to 'juick-server')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/XMPPBot.java | 21 | ||||
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/server/XMPPBot.java b/juick-server/src/main/java/com/juick/server/XMPPBot.java index a07dbe86..6215576a 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPBot.java +++ b/juick-server/src/main/java/com/juick/server/XMPPBot.java @@ -517,6 +517,27 @@ public class XMPPBot implements StanzaListener, AutoCloseable { } return "No favorite messages, try to \"like\" something ;)"; } + @UserCommand(pattern = "^\\!\\s+#(\\d+)", help = "! #12345 - recommend message") + public String commandRecommend(User user, Jid from, String... arguments) { + int mid = NumberUtils.toInt(arguments[0], 0); + if (mid > 0) { + com.juick.Message msg = messagesService.getMessage(mid); + if (msg != null) { + if (msg.getUser() == user) { + return "You can't recommend your own messages."; + } + MessagesService.RecommendStatus status = messagesService.recommendMessage(mid, user.getUid()); + switch (status) { + case Added: + return "Message is added to your recommendations"; + case Deleted: + return "Message deleted from your recommendations."; + } + } + return "Message not found"; + } + return "Message not found"; + } // TODO: target notification @UserCommand(pattern = "^(s|u)\\s+\\@(\\S+)$", help = "S @username - subscribe to user" + "\nU @username - unsubscribe from user", patternFlags = Pattern.CASE_INSENSITIVE) diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java index fcc1a777..4bf8ac9e 100644 --- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java +++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java @@ -385,7 +385,7 @@ public class ServerTests extends AbstractJUnit4SpringContextTests { public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG")); // subscription commands have two lines, others have 1 - assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(24)); + assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(25)); } @Test |