1#include <boost/algorithm/string.hpp>
2#include <boost/date_time/posix_time/conversion.hpp>
3#include <boost/date_time/posix_time/posix_time.hpp>
6#include <leptonica/allheaders.h>
8#include <tgbot/tgbot.h>
14#include "tgbot/types/Message.h"
26 "`/start` - _start the bot_\n"
27 "`/help` - _show this message_\n"
28 "`/info` - _show compilation machine information_\n"
29 "`/ocr` - _optical Character Recognition with tesseract_\n"
30 "`/metar <ICAO Code>` - _get METAR information_\n"
39#elif defined(__APPLE__)
51#elif defined(__i386__)
55#elif defined(__arm64__)
61 "CLANG " __clang_version__
62#elif defined(__GNUC__)
63 "GCC (GNU C Compiler) " __GNUC__
79 bot->getEvents().onCommand(
"start", [bot](TgBot::Message::Ptr message) {
81 bot->getApi().sendMessage(message->chat->id,
"Hi!");
90 bot->getEvents().onCommand(
"help", [bot](TgBot::Message::Ptr message) {
92 bot->getApi().sendMessage(message->chat->id,
HELP_MESSAGE,
false, 0,
102 bot->getEvents().onCommand(
"info", [bot](TgBot::Message::Ptr message) {
104 bot->getApi().sendMessage(message->chat->id,
INFO_MESSAGE,
false, 0,
114 bot->getEvents().onCommand(
"ocr", [bot](TgBot::Message::Ptr message) {
117 TgBot::Message::Ptr reply = message->replyToMessage;
119 if (reply ==
nullptr) {
121 boost::posix_time::to_time_t(
122 boost::posix_time::second_clock::universal_time()),
124 bot->getApi().sendMessage(message->chat->id,
125 "You should reply to a message");
129 TgBot::File::Ptr file =
130 bot->getApi().getFile(reply->photo[reply->photo.size() - 1]->fileId);
134 std::string fileContent = bot->getApi().downloadFile(file->filePath);
137 pixReadMem(
reinterpret_cast<const l_uint8 *
>(fileContent.c_str()),
140 if (pixImage ==
nullptr) {
142 boost::posix_time::to_time_t(
143 boost::posix_time::second_clock::universal_time()),
157 bot->getEvents().onCommand(
"metar", [bot](TgBot::Message::Ptr message) {
160 std::vector<std::string> text;
161 boost::split(text, message->text, [](
char c) { return c ==
' '; });
163 bot->getApi().sendMessage(message->chat->id,
164 "āļø METAR for " + text[1] +
"\nš " +
166 false, message->messageId);
const std::string INFO_MESSAGE
const std::string HELP_MESSAGE
const std::string PARSE_MODE("Markdown")
Telegram parse mode.
void register_handlers(TgBot::Bot *bot)
Register all the handlers for bot commands.