From 59e0c016bcb3e5f5260bf35bed63994fc9df3016 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 30 Jan 2018 13:30:20 +0300 Subject: xmpp: S @username --- .../src/main/java/com/juick/components/JuickBot.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'juick-xmpp/src/main') diff --git a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java index 7a25f5d5..2884fdd4 100644 --- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java @@ -528,6 +528,24 @@ public class JuickBot implements StanzaListener, AutoCloseable { } return "No favorite messages, try to \"like\" something ;)"; } + // TODO: target notification + @UserCommand(pattern = "^(s|u)\\s+\\@(\\S+)$", help = "S @username - subscribe to user" + + "\nU @username - unsubscribe from user", patternFlags = Pattern.CASE_INSENSITIVE) + public String commandSubscribeUser(User user, Jid from, String... args) { + boolean subscribe = args[0].equalsIgnoreCase("s"); + User toUser = userService.getUserByName(args[1]); + if (subscribe) { + if (subscriptionService.subscribeUser(user, toUser)) { + return "Subscribed to @" + toUser.getName(); + } + } else { + if (subscriptionService.unSubscribeUser(user, toUser)) { + return "Unsubscribed from @" + toUser.getName(); + } + return "You was not subscribed to @" + toUser.getName(); + } + return "Error"; + } @UserCommand(pattern = "^(s|u)\\s+\\*(\\S+)$", help = "S *tag - subscribe to tag" + "\nU *tag - unsubscribe from tag", patternFlags = Pattern.CASE_INSENSITIVE) public String commandSubscribeTag(User user, Jid from, String... args) { -- cgit v1.2.3