use of com.pengrad.telegrambot.request.SendMessage in project anton-pavlovich-bot by wyvie.
the class HelpCommandHandler method handle.
@Override
public void handle(Message message, String args) {
SendMessage sendMessage = new SendMessage(message.chat().id(), HELP_TEXT);
telegramBot.execute(sendMessage);
}
use of com.pengrad.telegrambot.request.SendMessage in project anton-pavlovich-bot by wyvie.
the class SlapCommand method handle.
@Override
public void handle(Message message, String args) {
String username = null;
String object = DEFAULT_OBJECT;
Message replied = message.replyToMessage();
if (replied != null) {
username = toUsername(replied.from());
if (StringUtils.hasLength(args))
object = args;
} else if (StringUtils.hasLength(args)) {
String argun = args;
if (argun.startsWith("@"))
argun = argun.substring(1);
if (argun.contains(" ")) {
int position = argun.indexOf(' ');
object = argun.substring(position + 1);
argun = argun.substring(0, position);
}
Optional<UserEntity> userEntity = userRepository.findByUsername(argun);
if (userEntity.isPresent())
username = "@" + argun;
}
if (username == null) {
logger.debug("Could not find username");
sendMessage(message.chat().id(), MESSAGE.replaceAll("%USER1%", toUsername(message.from())).replaceAll("%USER2%", "themselves").replaceAll("%OBJECT%", object));
return;
}
sendMessage(message.chat().id(), MESSAGE.replaceAll("%USER1%", toUsername(message.from())).replaceAll("%USER2%", username).replaceAll("%OBJECT%", object));
}
use of com.pengrad.telegrambot.request.SendMessage in project anton-pavlovich-bot by wyvie.
the class SlapCommand method sendMessage.
private void sendMessage(long chatId, String message) {
SendMessage sendMessage = new SendMessage(chatId, message);
telegramBot.execute(sendMessage);
}
use of com.pengrad.telegrambot.request.SendMessage in project anton-pavlovich-bot by wyvie.
the class DailyMenuCommandHandler method handle.
@Override
public void handle(Message message, String args) {
logger.debug("args is '" + args + "'");
int dayOfWeek = LocalDateTime.now().getDayOfWeek().getValue();
if (dayOfWeek > 5) {
SendMessage sendMessage = new SendMessage(message.chat().id(), "Only available on week days.");
telegramBot.execute(sendMessage);
return;
}
Restaurant restaurant = restaurantMap.get(args);
String textToSend;
if (restaurant == null) {
textToSend = "Please specify one of the following restaurants:\n";
StringBuilder sb = new StringBuilder("");
restaurantMap.forEach((k, v) -> {
if (sb.length() > 0)
sb.append(", ");
sb.append(k);
});
textToSend += sb.toString();
} else {
textToSend = restaurant.menu();
if (StringUtils.isEmpty(textToSend))
textToSend = "Something went wrong. I could not fetch menu for you." + "I am so very, very sorry. :'(";
}
SendMessage sendMessage = new SendMessage(message.chat().id(), textToSend);
telegramBot.execute(sendMessage);
}
use of com.pengrad.telegrambot.request.SendMessage in project anton-pavlovich-bot by wyvie.
the class HelpCommand method sendMessage.
private void sendMessage(long chatId, String messageText) {
SendMessage sendMessage = new SendMessage(chatId, messageText);
sendMessage = sendMessage.parseMode(ParseMode.HTML);
SendResponse response = telegramBot.execute(sendMessage);
}
Aggregations