-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (46 loc) · 1.38 KB
/
main.cpp
File metadata and controls
60 lines (46 loc) · 1.38 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "commands.hpp"
#include "bot.hpp"
#include <iostream>
#include <fstream>
#include <csignal>
using namespace std;
unique_ptr<Bot> pearlbot;
struct settings {
vector<discord::member> gang;
};
settings bot_setting;
void signalHandler(int sig);
int main() {
// grab the token in token.txt
string token;
ifstream txt_file{"token.txt"};
getline(txt_file, token);
pearlbot = unique_ptr<Bot>(new Bot(token, '$'));
signal(SIGSEGV, signalHandler);
signal(SIGTERM, signalHandler);
signal(SIGABRT, signalHandler);
// upload settings
try {
ifstream settings("settings.json");
stringstream settings_buf;
settings_buf << settings.rdbuf();
auto dump = nlohmann::json::parse(settings_buf);
pearlbot->whitelist.push_back({dump["owner"].get<uint64_t>()});
for(auto it = dump["gang"].begin(); it != dump["gang"].end(); ++it) {
bot_setting.gang.push_back({(*it).get<uint64_t>()});
}
for(auto it = dump["whitelist"].begin(); it != dump["whitelist"].end(); ++it) {
bot_setting.gang.push_back({(*it).get<uint64_t>()});
}
for(auto it = dump["blacklist"].begin(); it != dump["blacklist"].end(); ++it) {
bot_setting.gang.push_back({(*it).get<uint64_t>()});
}
} catch(const std::exception &e) {
std::cout << e.what() << std::endl;
}
return pearlbot->run();
}
void signalHandler(int sig) {
pearlbot.reset();
exit(sig);
}