-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
50 lines (41 loc) · 1021 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
43
44
45
46
47
48
49
50
#include <fstream>
#include <thread>
#include "PracticalSocket.h"
#include "IRC.h"
using json = nlohmann::json;
int main(int argc, char *argv[]) {
if (argc < 2)
{
std::cerr << "Invalid number of args" << std::endl;
exit(1);
}
json config;
std::string cfg ("");
std::string line;
std::ifstream f(argv[1]);
if (f.is_open()) {
while (getline(f, line)) {
cfg += line;
}
f.close();
}
else {
std::cerr << argv[1] << " is not open" << std::endl;
exit(1);
}
config = json::parse(cfg);
json server = config["connections"][0];
try {
if (argc >= 3)
config["connections"][0]["nick"] = argv[2];
// Establish connection with the server
IRC::Bot bot(config);
bot.run();
std::cout << std::endl;
// Destructor closes the socket
} catch (SocketException &e) {
std::cerr << e.what() << std::endl;
exit(1);
}
return 0;
}