aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/ShowBlacklist.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/ShowBlacklist.java')
-rw-r--r--juick-commands/src/main/java/com/juick/command/ShowBlacklist.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/ShowBlacklist.java b/juick-commands/src/main/java/com/juick/command/ShowBlacklist.java
new file mode 100644
index 00000000..bd4df7df
--- /dev/null
+++ b/juick-commands/src/main/java/com/juick/command/ShowBlacklist.java
@@ -0,0 +1,68 @@
+package com.juick.command;
+
+import com.juick.User;
+import com.juick.server.protocol.ProtocolListener;
+import com.juick.service.TagService;
+import com.juick.service.UserService;
+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 ShowBlacklist implements Command {
+
+ private static final Pattern PATTERN = Pattern.compile("^bl$", Pattern.CASE_INSENSITIVE);
+
+ private final UserService userService;
+ private final TagService tagService;
+
+ @Autowired
+ public ShowBlacklist(UserService userService, TagService tagService) {
+ this.userService = userService;
+ this.tagService = tagService;
+ }
+
+ @Override
+ public Pattern pattern() {
+ return PATTERN;
+ }
+
+ @Override
+ public String help() {
+ return "BL - Show your blacklist";
+ }
+
+ @Override
+ public String execute(User sender, ProtocolListener protocolListener, String command) {
+ List<User> blusers = getUserService().getUserBLUsers(sender.getUid());
+ List<String> bltags = getTagService().getUserBLTags(sender.getUid());
+
+ StringBuilder txt = new StringBuilder();
+ if (bltags.size() > 0) {
+ for (String bltag : bltags) {
+ txt.append("*").append(bltag).append("\n");
+ }
+
+ if (blusers.size() > 0) {
+ txt.append("\n");
+ }
+ }
+ if (blusers.size() > 0) {
+ for (User bluser : blusers) {
+ txt.append("@").append(bluser.getName()).append("\n");
+ }
+ }
+ if (txt.length() == 0) {
+ txt.append("You don't have any users or tags in your blacklist.");
+ }
+
+ return txt.toString();
+ }
+}