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.

48 lines
1.6 KiB

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.logging.BotLogger;
/**
* This commands stops the conversation with the bot.
* Bot won't respond to user until he sends a start command
*
* @author Timo Schulz (Mit0x2)
*/
public class StopCommand extends BotCommand {
public static final String LOGTAG = "STOPCOMMAND";
/**
* Construct
*/
public StopCommand() {
super("stop", "With this command you can stop the Bot");
}
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
DatabaseManager dbManager = DatabaseManager.getInstance();
if (dbManager.getUserStateForCommandsBot(user.getId())) {
dbManager.setUserStateForCommandsBot(user.getId(), false);
String userName = user.getFirstName() + " " + user.getLastName();
SendMessage answer = new SendMessage();
answer.setChatId(chat.getId().toString());
answer.setText("Good bye " + userName + "\n" + "Hope to see you soon!");
try {
absSender.sendMessage(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}
}
}
}