You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
|
10 years ago
|
package org.telegram.commands;
|
||
|
|
|
||
|
|
import org.telegram.database.DatabaseManager;
|
||
|
|
import org.telegram.telegrambots.TelegramApiException;
|
||
|
|
import org.telegram.telegrambots.api.methods.send.SendMessage;
|
||
|
|
import org.telegram.telegrambots.api.objects.Chat;
|
||
|
|
import org.telegram.telegrambots.api.objects.User;
|
||
|
|
import org.telegram.telegrambots.bots.AbsSender;
|
||
|
|
import org.telegram.telegrambots.bots.commands.BotCommand;
|
||
|
|
import org.telegram.telegrambots.bots.commands.ICommandRegistry;
|
||
|
|
import org.telegram.telegrambots.logging.BotLogger;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This command helps the user to find the command they need
|
||
|
|
*
|
||
|
|
* @author Timo Schulz (Mit0x2)
|
||
|
|
*/
|
||
|
|
public class HelpCommand extends BotCommand {
|
||
|
|
|
||
|
|
private static final String LOGTAG = "HELPCOMMAND";
|
||
|
|
|
||
|
|
private final ICommandRegistry commandRegistry;
|
||
|
|
|
||
|
|
public HelpCommand(ICommandRegistry commandRegistry) {
|
||
|
|
super("help", "Get all the commands this bot provides");
|
||
|
|
this.commandRegistry = commandRegistry;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
|
||
|
|
|
||
|
|
if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n");
|
||
|
|
helpMessageBuilder.append("These are the registered commands for this Bot:\n\n");
|
||
|
|
|
||
|
|
for (BotCommand botCommand : commandRegistry.getRegisteredCommands()) {
|
||
|
|
helpMessageBuilder.append(botCommand.toString()).append("\n\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
SendMessage helpMessage = new SendMessage();
|
||
|
|
helpMessage.setChatId(chat.getId().toString());
|
||
|
|
helpMessage.enableHtml(true);
|
||
|
|
helpMessage.setText(helpMessageBuilder.toString());
|
||
|
|
|
||
|
|
try {
|
||
|
|
absSender.sendMessage(helpMessage);
|
||
|
|
} catch (TelegramApiException e) {
|
||
|
|
BotLogger.error(LOGTAG, e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|