-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
42 lines (41 loc) · 987 Bytes
/
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
#include "Database.h"
#include "GreekBot.h"
#include "Utils.h"
#include <csignal>
#include <cstdio>
#include <thread>
int main(int argc, const char** argv) {
/* Set the main thread to block certain signals */
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTSTP);
sigaddset(&set, SIGTERM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
/* Check arguments! */
if (argc != 2) {
std::puts("You forgot to give me a token!");
return EXIT_FAILURE;
}
/* Initialize the database and the bot client */
cDatabase::Initialize();
cGreekBot client(argv[1]);
/* Wait for a termination signal in order to stop the bot gracefully */
std::thread t(&cGreekBot::Run, &client);
for (int sig = 0;;) {
sigwait(&set, &sig);
switch (sig) {
case SIGINT:
case SIGTSTP:
case SIGTERM:
cUtils::PrintErr("Interrupt received. Terminating...");
client.RequestExit();
break;
default:
continue;
}
break;
}
t.join();
return EXIT_SUCCESS;
}