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
15
int
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
26
Bot::register_handlers
(&bot);
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()),
40
LOG::Error
);
41
bot.getApi().deleteWebhook(
true
);
42
}
43
}
44
45
tools::flush
();
46
47
return
EXIT_SUCCESS
;
48
}
commands.hpp
error_codes.hpp
EXIT_SUCCESS
#define EXIT_SUCCESS
Definition
error_codes.hpp:1
EXIT_FAILURE
#define EXIT_FAILURE
Definition
error_codes.hpp:2
main
int main(int argc, char *argv[])
Definition
main.cpp:15
BOT_TOKEN
#define BOT_TOKEN
Definition
main.cpp:13
Bot::register_handlers
void register_handlers(TgBot::Bot *bot)
Register all the handlers for bot commands.
Definition
commands.cpp:71
LOG::Error
const std::string Error
Definition
utils.hpp:46
tools::log_cmd
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
tools::flush
void flush()
Flush stdin.
Definition
utils.cpp:12
utils.hpp
main.cpp
Generated on Tue Jun 6 2023 18:20:31 for SklavaBot by
1.9.7