aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/BlacklistTag.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-commands/src/main/java/com/juick/command/BlacklistTag.java')
-rw-r--r--juick-commands/src/main/java/com/juick/command/BlacklistTag.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/juick-commands/src/main/java/com/juick/command/BlacklistTag.java b/juick-commands/src/main/java/com/juick/command/BlacklistTag.java
new file mode 100644
index 00000000..2ce455dc
--- /dev/null
+++ b/juick-commands/src/main/java/com/juick/command/BlacklistTag.java
@@ -0,0 +1,61 @@
+package com.juick.command;
+
+import com.juick.Tag;
+import com.juick.User;
+import com.juick.server.protocol.ProtocolListener;
+import com.juick.service.PrivacyQueriesService;
+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.regex.Pattern;
+
+/**
+ * @author ma1uta
+ */
+@Component
+@Getter
+public class BlacklistTag extends MultiArgsCommand {
+
+ private static final Pattern PATTERN = Pattern.compile("^bl\\s\\*(\\S+)$", Pattern.CASE_INSENSITIVE);
+
+ private final UserService userService;
+ private final TagService tagService;
+ private final PrivacyQueriesService privacyQueriesService;
+
+ @Autowired
+ public BlacklistTag(UserService userService, TagService tagService, PrivacyQueriesService privacyQueriesService) {
+ this.userService = userService;
+ this.tagService = tagService;
+ this.privacyQueriesService = privacyQueriesService;
+ }
+
+ @Override
+ public Pattern pattern() {
+ return PATTERN;
+ }
+
+ @Override
+ public String help() {
+ return "BL *tag - add *tag to your blacklist";
+ }
+
+ @Override
+ protected String execute(User sender, ProtocolListener protocolListener, String... arguments) {
+ User blUser = getUserService().getUserByName(arguments[0]);
+ if (blUser != null) {
+ Tag tag = getTagService().getTag(arguments[0], false);
+ if (tag != null) {
+ PrivacyQueriesService.PrivacyResult result = getPrivacyQueriesService().blacklistTag(sender, tag);
+ if (result == PrivacyQueriesService.PrivacyResult.Added) {
+ return "Tag added to your blacklist";
+ } else {
+ return "Tag removed from your blacklist";
+ }
+ }
+ }
+ return "Tag not found";
+ }
+}