FontBot/src/main.cpp

65 lines
1.4 KiB
C++

#include <Log.h>
#include <TAPIInlineQuery.h>
#include <TAPIMarkup.h>
#include <TAPIManager.h>
#include <functional> //std bind
#include <signal.h> // signal
#include <fstream>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
#include "bot.h"
static bool run = true;
void sig_handler(int sig_num) {
Log::info << "signalHandler triggered";
run = false;
(void) sig_num;
}
class CommandStart : public TelegramAPI::Command {
public:
CommandStart() : TelegramAPI::Command("/start") {}
virtual bool process(TelegramAPI::Manager* m, const TelegramAPI::Message& msg) {
TelegramAPI::InlineKeyboard kb;
kb.addButton(TelegramAPI::InlineButton::createSwitchInlineQuery("Open in Chat"), 0);
return m->sendMessage(msg.chat.id, "This bot is inline only.", kb);
}
};
int main(int argc, const char** argv) {
Log::init();
Log::setConsoleLogLevel(Log::Level::TRACE);
Log::addLogfile("log.txt", Log::Level::WARN);
#if __unix__
Log::setColoredOutput(true);
#endif
Log::info << "Hello, World!";
//read config
std::ifstream configfile("config.json");
json j;
configfile >> j;
FontBot bot;
TelegramAPI::Manager tapi(j["telegram"]["apikey"]);
std::unique_ptr<TelegramAPI::Command> cmd(new CommandStart());
tapi.registerCommand(std::move(cmd));
namespace pl = std::placeholders;
tapi.setInlineQueryHandler(std::bind(&FontBot::handleInline, &bot, pl::_1, pl::_2));
signal(SIGINT, sig_handler);
while(run) {
tapi.getUpdates();
}
Log::stop();
return 0;
}