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.
54 lines
1.9 KiB
54 lines
1.9 KiB
package org.telegram.commands;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.telegram.database.DatabaseManager;
|
|
import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
|
|
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
|
import org.telegram.telegrambots.meta.api.objects.Chat;
|
|
import org.telegram.telegrambots.meta.api.objects.User;
|
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
|
import org.telegram.telegrambots.meta.generics.TelegramClient;
|
|
|
|
/**
|
|
* This command simply replies with a hello to the users command and
|
|
* sends them the 'kind' words back, which they send via command parameters
|
|
*
|
|
* @author Timo Schulz (Mit0x2)
|
|
*/
|
|
@Slf4j
|
|
public class HelloCommand extends BotCommand {
|
|
|
|
private static final String LOGTAG = "HELLOCOMMAND";
|
|
|
|
public HelloCommand() {
|
|
super("hello", "Say hallo to this bot");
|
|
}
|
|
|
|
@Override
|
|
public void execute(TelegramClient telegramClient, User user, Chat chat, String[] arguments) {
|
|
|
|
if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) {
|
|
return;
|
|
}
|
|
|
|
String userName = chat.getUserName();
|
|
if (userName == null || userName.isEmpty()) {
|
|
userName = user.getFirstName() + " " + user.getLastName();
|
|
}
|
|
|
|
StringBuilder messageTextBuilder = new StringBuilder("Hello ").append(userName);
|
|
if (arguments != null && arguments.length > 0) {
|
|
messageTextBuilder.append("\n");
|
|
messageTextBuilder.append("Thank you so much for your kind words:\n");
|
|
messageTextBuilder.append(String.join(" ", arguments));
|
|
}
|
|
|
|
SendMessage answer = new SendMessage(chat.getId().toString(), messageTextBuilder.toString());
|
|
|
|
try {
|
|
telegramClient.execute(answer);
|
|
} catch (TelegramApiException e) {
|
|
log.error("Error", e);
|
|
}
|
|
}
|
|
}
|