From 434ea38eeb489f5c095ce55a16ef6dcca9489335 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 2 Mar 2017 17:01:00 +0300 Subject: juick-xmpp: command users duplicated from protocol --- .../main/java/com/juick/components/XMPPServer.java | 2 ++ .../java/com/juick/components/s2s/JuickBot.java | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'juick-xmpp/src/main/java/com/juick/components') diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index b5518e33..68f043e5 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -62,6 +62,8 @@ public class XMPPServer implements AutoCloseable { public PMQueriesService pmQueriesService; @Inject public SubscriptionService subscriptionService; + @Inject + public ShowQueriesService showQueriesService; private Jid jid; diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java index 6e89355a..e6efd500 100644 --- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java @@ -297,6 +297,8 @@ public class JuickBot implements StanzaListener, AutoCloseable { return true; } else if (commandlen == 2 && command.equalsIgnoreCase("#+")) { return commandLast(msg.getFrom()); + } else if (command.equalsIgnoreCase("@")) { + return commandUsers(msg.getFrom()); } else if (xmpp.messagesService.isReadonly()) { return commandMaintenance(msg.getFrom()); } @@ -424,6 +426,31 @@ public class JuickBot implements StanzaListener, AutoCloseable { return true; } + boolean commandUsers(Jid jidFrom) { + StringBuilder msg = new StringBuilder(); + msg.append("Recommended blogs"); + User currentUser = xmpp.userService.getUserByJID(jidFrom.asBareJid().toEscapedString()); + List recommendedUsers = xmpp.showQueriesService.getRecommendedUsers(currentUser); + if (recommendedUsers.size() > 0) { + for (String user : recommendedUsers) { + msg.append("\n@").append(user); + } + } else { + msg.append("\nNo recommendations now. Subscribe to more blogs. ;)"); + } + msg.append("\n\nTop 10 personal blogs:"); + List topUsers = xmpp.showQueriesService.getTopUsers(); + if (topUsers.size() > 0) { + for (String user : topUsers) { + msg.append("\n@").append(user); + } + } else { + msg.append("\nNo top users. Empty DB? ;)"); + } + sendReply(jidFrom, msg.toString()); + return true; + } + private boolean commandMaintenance(Jid jidFrom) { sendReply(jidFrom, "Комментирование временно недоступно"); return true; -- cgit v1.2.3