-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
46 lines (35 loc) · 1.14 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <cstdlib>
#include <chrono>
#include <string>
#include <tgbot/tgbot.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
#include "utils.hpp"
#include "commands.hpp"
#include "error_codes.hpp"
#define BOT_TOKEN std::getenv("BOT_TOKEN")
int main(int argc, char *argv[]) {
std::cout << "Starting Bot...\n";
if(BOT_TOKEN == NULL) {
std::cerr << "BOT_TOKEN variable isn't sourced\n";
return EXIT_FAILURE;
}
TgBot::Bot bot(std::string(BOT_TOKEN));
bot.getApi().deleteWebhook(true);
register_handlers(&bot);
while(true){
try {
std::cout << "Bot username: " << bot.getApi().getMe()->username.c_str() << "\n";
TgBot::TgLongPoll longPoll(bot);
while (true) {
longPoll.start();
}
} catch (TgBot::TgException& e) {
log_cmd(e.what(), "TG_BOT", boost::posix_time::to_time_t(boost::posix_time::second_clock::universal_time()), LOG::Error);
bot.getApi().deleteWebhook(true);
}
}
flush();
return EXIT_SUCCESS;
}