From 9b201b07dc6caa147ea79b359e448f2649353039 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 25 Feb 2018 09:04:17 +0300 Subject: xmpp: recommend command --- .../src/main/java/com/juick/server/XMPPBot.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'juick-server/src/main/java/com') 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) -- cgit v1.2.3