aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/Recommendations.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/Recommendations.java')
-rw-r--r--juick-commands/src/main/java/com/juick/command/Recommendations.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/Recommendations.java b/juick-commands/src/main/java/com/juick/command/Recommendations.java
new file mode 100644
index 00000000..c7f38003
--- /dev/null
+++ b/juick-commands/src/main/java/com/juick/command/Recommendations.java
@@ -0,0 +1,62 @@
+package com.juick.command;
+
+import com.juick.User;
+import com.juick.server.protocol.ProtocolListener;
+import com.juick.service.ShowQueriesService;
+import lombok.Getter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * @author ma1uta
+ */
+@Component
+@Getter
+public class Recommendations implements Command {
+
+ private static final Pattern PATTERN = Pattern.compile("@", Pattern.CASE_INSENSITIVE);
+
+ private final ShowQueriesService showQueriesService;
+
+ @Autowired
+ public Recommendations(ShowQueriesService showQueriesService) {
+ this.showQueriesService = showQueriesService;
+ }
+
+ @Override
+ public Pattern pattern() {
+ return PATTERN;
+ }
+
+ @Override
+ public String help() {
+ return "@ - Show recommendations and popular personal blogs";
+ }
+
+ @Override
+ public String execute(User sender, ProtocolListener protocolListener, String command) {
+ StringBuilder msg = new StringBuilder();
+ msg.append("Recommended blogs");
+ List<String> recommendedUsers = getShowQueriesService().getRecommendedUsers(sender);
+ 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<String> topUsers = getShowQueriesService().getTopUsers();
+ if (topUsers.size() > 0) {
+ for (String user : topUsers) {
+ msg.append("\n@").append(user);
+ }
+ } else {
+ msg.append("\nNo top users. Empty DB? ;)");
+ }
+ return msg.toString();
+ }
+}