blob: 40fa93e882332f9754fff9a96c376a5573e02771 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package com.juick.command;
import com.juick.User;
import com.juick.server.helpers.TagStats;
import com.juick.service.TagService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @author ma1uta
*/
@Component
@Getter
public class ShowTags implements Command {
private static final Pattern PATTERN = Pattern.compile("\\*", Pattern.CASE_INSENSITIVE);
private final TagService tagService;
@Autowired
public ShowTags(TagService tagService) {
this.tagService = tagService;
}
@Override
public Pattern pattern() {
return PATTERN;
}
@Override
public String help() {
return "* - Show your tags";
}
@Override
public String execute(User sender, MessageListener protocolListener, String command) {
List<TagStats> tags = getTagService().getUserTagStats(sender.getUid());
return "Your tags: (tag - messages)\n" +
tags.stream()
.map(t -> String.format("\n*%s - %d", t.getTag().getName(), t.getUsageCount())).collect(Collectors.joining());
}
}
|