Passed
Push — master ( 482350...d5f627 )
by Roannel Fernández
03:16
created

execute(Update,String[])   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
package com.github.netkorp.overridebasiccommand.commands;
2
3
import com.github.netkorp.telegram.framework.annotations.TelegramCommand;
4
import com.github.netkorp.telegram.framework.commands.abstracts.AbstractSimpleCommand;
5
import com.github.netkorp.telegram.framework.commands.interfaces.HelpCommand;
6
import com.github.netkorp.telegram.framework.managers.CommandManager;
7
import org.telegram.telegrambots.meta.api.objects.Update;
8
9
import java.util.StringJoiner;
10
11
@TelegramCommand(name = "assistance", secure = false)
12
public class OwnHelpCommand extends AbstractSimpleCommand implements HelpCommand {
13
14
    /**
15
     * Processes the data sent by the users.
16
     *
17
     * @param update the received message.
18
     * @param args   the parameters passed to the command execution.
19
     */
20
    @Override
21
    public void execute(Update update, String[] args) {
22
        StringJoiner stringJoiner = new StringJoiner(System.lineSeparator());
23
        stringJoiner.add("Commands:");
24
        commandManager.getAvailableNonSecureCommands()
25
                .forEach(command -> stringJoiner.add(String.format("%s - <b>%s</b>", CommandManager.getCommandFullName(command), command.description())));
26
        bot.sendMessage(stringJoiner.toString(), update.getMessage().getChatId(), true);
27
    }
28
29
    /**
30
     * Returns the command's description, used to be displayed in help message.
31
     *
32
     * @return the command's description.
33
     */
34
    @Override
35
    public String description() {
36
        return "Displays an assistance message";
37
    }
38
}
39