change chat id to chat object to be able to work with username

This commit is contained in:
tschulz 2016-05-20 12:03:00 +02:00
parent 5fe18aefa3
commit 1bb4d12983
3 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.api.commands;
import org.telegram.telegrambots.api.objects.Chat;
import org.telegram.telegrambots.bots.AbsSender;
/**
@ -69,7 +70,7 @@ public abstract class BotCommand extends AbsSender {
* execute the command
*
* @param arguments passed arguments
* @param chatId id of the chat, to be able to send replies
* @param chat the chat, to be able to send replies
*/
public abstract void execute(String[] arguments, long chatId);
public abstract void execute(String[] arguments, Chat chat);
}

View File

@ -76,7 +76,7 @@ public final class CommandRegistry implements ICommandRegistry {
if (commandRegistryMap.containsKey(command)) {
String[] parameters = Arrays.copyOfRange(commandSplit, 1, commandSplit.length);
commandRegistryMap.get(command).execute(parameters, message.getChatId());
commandRegistryMap.get(command).execute(parameters, message.getChat());
return true;
}
}

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.commands;
import org.telegram.telegrambots.BotLogger;
import org.telegram.telegrambots.TelegramApiException;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Chat;
/**
* standard help command, which gets registered by default, to supply a list of all available commands
@ -20,10 +21,11 @@ public class HelpBotCommand extends BotCommand {
}
@Override
public void execute(String[] arguments, long chatId) {
public void execute(String[] arguments, Chat chat) {
for (BotCommand registeredBotCommand : commandRegistry.getRegisteredCommands()) {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(chatId);
sendMessage.setChatId(chat.getId());
sendMessage.enableHtml(true);
sendMessage.setText("<b>" + COMMAND_INIT_CHARACTER + registeredBotCommand.getCommandIdentifier() + "</b>\n" + registeredBotCommand.getDescription());