|
1
|
|
|
package com.github.netkorp.telegram.framework.commands.basic; |
|
2
|
|
|
|
|
3
|
|
|
import com.github.netkorp.telegram.framework.annotations.CommandGroup; |
|
4
|
|
|
import com.github.netkorp.telegram.framework.commands.abstracts.AbstractCommand; |
|
5
|
|
|
import com.github.netkorp.telegram.framework.commands.interfaces.HelpCommand; |
|
6
|
|
|
import org.apache.logging.log4j.util.Strings; |
|
7
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; |
|
8
|
|
|
import org.springframework.stereotype.Component; |
|
9
|
|
|
import org.telegram.telegrambots.meta.api.objects.Update; |
|
10
|
|
|
|
|
11
|
|
|
import java.util.StringJoiner; |
|
12
|
|
|
|
|
13
|
|
|
@Component |
|
14
|
|
|
@CommandGroup("Basic") |
|
15
|
|
|
@ConditionalOnSingleCandidate(HelpCommand.class) |
|
16
|
|
|
public class BasicHelpCommand extends AbstractCommand implements HelpCommand { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Returns the commands that will be executed on the chat. |
|
20
|
|
|
* |
|
21
|
|
|
* @return Command to be executed. |
|
22
|
|
|
*/ |
|
23
|
|
|
@Override |
|
24
|
|
|
public String getName() { |
|
25
|
|
|
return "help"; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Processes the data of the commands. |
|
30
|
|
|
* |
|
31
|
|
|
* @param update The received message. |
|
32
|
|
|
*/ |
|
33
|
|
|
@Override |
|
34
|
|
|
public void execute(Update update) { |
|
35
|
|
|
StringJoiner stringJoiner = new StringJoiner("\n"); |
|
36
|
|
|
stringJoiner.add("You can control me by sending these commands:\n"); |
|
37
|
|
|
commandManager.getCommandsByGroup().forEach((group, commands) -> { |
|
38
|
|
|
if (!Strings.isEmpty(group)) { |
|
39
|
|
|
stringJoiner.add(String.format("\n<b>%s</b>", group)); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
commands.forEach(command -> stringJoiner.add(String.format("%s - %s", command.command(), command.description()))); |
|
42
|
|
|
}); |
|
43
|
|
|
bot.sendMessage(stringJoiner.toString(), update.getMessage().getChatId(), true); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns the description of the commands. |
|
48
|
|
|
* |
|
49
|
|
|
* @return The description. |
|
50
|
|
|
*/ |
|
51
|
|
|
@Override |
|
52
|
|
|
public String description() { |
|
53
|
|
|
return "Shows this message"; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|