SklavaBot 0.1.0
Telegram Bot in C++
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <boost/date_time/posix_time/conversion.hpp>
2#include <boost/date_time/posix_time/posix_time.hpp>
3#include <chrono>
4#include <cstdlib>
5#include <iostream>
6#include <string>
7#include <tgbot/tgbot.h>
8
9#include "commands.hpp"
10#include "error_codes.hpp"
11#include "utils.hpp"
12
13#define BOT_TOKEN std::getenv("BOT_TOKEN")
14
15int main(int argc, char *argv[]) {
16 std::cout << "Starting Bot...\n";
17
18 if (BOT_TOKEN == NULL) {
19 std::cerr << "BOT_TOKEN variable isn't sourced\n";
20 return EXIT_FAILURE;
21 }
22
23 TgBot::Bot bot(std::string(BOT_TOKEN));
24 bot.getApi().deleteWebhook(true);
25
27
28 while (true) {
29 try {
30 std::cout << "Bot username: " << bot.getApi().getMe()->username.c_str()
31 << "\n";
32 TgBot::TgLongPoll longPoll(bot);
33 while (true) {
34 longPoll.start();
35 }
36 } catch (TgBot::TgException &e) {
37 tools::log_cmd(e.what(), "TG_BOT",
38 boost::posix_time::to_time_t(
39 boost::posix_time::second_clock::universal_time()),
41 bot.getApi().deleteWebhook(true);
42 }
43 }
44
46
47 return EXIT_SUCCESS;
48}
#define EXIT_SUCCESS
#define EXIT_FAILURE
int main(int argc, char *argv[])
Definition main.cpp:15
#define BOT_TOKEN
Definition main.cpp:13
void register_handlers(TgBot::Bot *bot)
Register all the handlers for bot commands.
Definition commands.cpp:71
const std::string Error
Definition utils.hpp:46
void log_cmd(std::string command, std::string user, std::int32_t timestamp, const std::string log_type)
Function to print a better log.
Definition utils.cpp:17
void flush()
Flush stdin.
Definition utils.cpp:12