Search in sources :

Example 1 with SendMessage

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);
}
Also used : SendMessage(com.pengrad.telegrambot.request.SendMessage)

Example 2 with 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));
}
Also used : Message(com.pengrad.telegrambot.model.Message) SendMessage(com.pengrad.telegrambot.request.SendMessage) Optional(java.util.Optional)

Example 3 with SendMessage

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);
}
Also used : SendMessage(com.pengrad.telegrambot.request.SendMessage)

Example 4 with 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);
}
Also used : Restaurant(org.wyvie.chehov.bot.commands.dailymenu.restaurant.Restaurant) SendMessage(com.pengrad.telegrambot.request.SendMessage)

Example 5 with 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);
}
Also used : SendResponse(com.pengrad.telegrambot.response.SendResponse) SendMessage(com.pengrad.telegrambot.request.SendMessage)

Aggregations

SendMessage (com.pengrad.telegrambot.request.SendMessage)13 SendResponse (com.pengrad.telegrambot.response.SendResponse)4 Message (com.pengrad.telegrambot.model.Message)3 Chat (com.pengrad.telegrambot.model.Chat)2 TelegramBot (com.pengrad.telegrambot.TelegramBot)1 Update (com.pengrad.telegrambot.model.Update)1 User (com.pengrad.telegrambot.model.User)1 Keyboard (com.pengrad.telegrambot.model.request.Keyboard)1 ReplyKeyboardRemove (com.pengrad.telegrambot.model.request.ReplyKeyboardRemove)1 Optional (java.util.Optional)1 ByteString (okio.ByteString)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 Restaurant (org.wyvie.chehov.bot.commands.dailymenu.restaurant.Restaurant)1