diff options
-rw-r--r-- | juick-xmpp/src/main/java/com/juick/components/JuickBot.java | 18 | ||||
-rw-r--r-- | juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java | 4 |
2 files changed, 20 insertions, 2 deletions
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) { diff --git a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java index 537445ea..784c29b2 100644 --- a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java +++ b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java @@ -95,8 +95,8 @@ public class XMPPServerTests extends AbstractJUnit4SpringContextTests { @Test public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG")); - // tag help have two lines, others have 1 - assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(18)); + // tag and user help have two lines, others have 1 + assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(20)); } @Test |