|
4 | 4 | import org.springframework.stereotype.Service; |
5 | 5 | import telegram.bot.dto.basicStatistic.BasicStatistic; |
6 | 6 | import telegram.bot.dto.contributeStatistic.ContributeStatistic; |
| 7 | +import telegram.bot.repository.UserRepository; |
7 | 8 | import telegram.bot.util.MarkdownV2Util; |
8 | 9 | import telegram.bot.util.NormalizeUsername; |
9 | 10 |
|
10 | 11 | import java.util.regex.Pattern; |
11 | 12 |
|
12 | 13 | import static telegram.bot.enums.CommandName.START; |
| 14 | +import static telegram.bot.enums.CommandName.STATS; |
13 | 15 | import static telegram.bot.enums.CommandName.THERE_IS_NO_SUCH_COMMAND; |
14 | 16 | import static telegram.bot.enums.Message.NO_COMMAND; |
15 | 17 | import static telegram.bot.enums.Message.START_MESSAGE; |
16 | 18 | import static telegram.bot.enums.Message.STATISTIC_MESSAGE; |
| 19 | +import static telegram.bot.enums.Message.USER_COUNT_STATISTIC; |
17 | 20 |
|
18 | 21 | @Service |
19 | 22 | @AllArgsConstructor |
20 | 23 | public class MessageService { |
21 | 24 | private final MarkdownV2Util markdownV2Util; |
22 | 25 | private final NormalizeUsername normalizeUsername; |
| 26 | + private final UserRepository repository; |
23 | 27 |
|
24 | 28 | public String generateMessage(String message, GitHubService gitHubService) { |
25 | 29 | var theIsNoSuchCommand = Pattern.compile(THERE_IS_NO_SUCH_COMMAND.getMessage()); |
26 | 30 |
|
27 | 31 | if (START.getMessage().equals(message)) { |
28 | 32 | return markdownV2Util.escapeMarkdownV2(START_MESSAGE.getMessage()); |
29 | 33 | } |
| 34 | + if (STATS.getMessage().equals(message)) { |
| 35 | + var statisticMessage = USER_COUNT_STATISTIC.getMessage() + repository.count(); |
| 36 | + return markdownV2Util.escapeMarkdownV2(statisticMessage); |
| 37 | + } |
30 | 38 | if (theIsNoSuchCommand.matcher(message).matches()) { |
31 | 39 | return markdownV2Util.escapeMarkdownV2(NO_COMMAND.getMessage()); |
32 | 40 | } |
|
0 commit comments