-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRC.h
123 lines (87 loc) · 2.59 KB
/
IRC.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef IRCBOT_IRC_H
#define IRCBOT_IRC_H
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#include "PracticalSocket.h"
#include "Module.h"
using json = nlohmann::json;
//using namespace std;
namespace IRC {
// TODO add servername handling
struct Prefix {
std::string nick = "";
std::string user = "";
std::string host = "";
std::string mask = "";
};
struct ParsedLine {
IRC::Prefix prefix;
std::string cmd = "";
std::vector<std::string> params;
};
struct CommandLine : ParsedLine {
std::string command = "";
std::vector<std::string> args;
std::string channel;
};
ParsedLine parse(std::string s);
bool parsePrefix(std::string s, Prefix &p);
bool parseMessage(ParsedLine line, CommandLine &out);
class Connection;
class Module;
class Bot {
public:
Bot(json config);
bool run();
private:
json config;
std::vector<IRC::Connection> connections;
};
class Connection {
public:
Connection(std::string _host, unsigned short _port, json config, IRC::Bot *bot);
~Connection();
void setNick(std::string _nick);
void setUser(std::string _user);
void setRealname(std::string _realname);
void useNickServ(bool b);
void setNickServUser(std::string ns_user);
void setNickServPass(std::string pass);
void connect();
void shutdown(std::string s);
void shutdown();
void send(std::string s);
void cmd(std::string cmd, std::vector<std::string> *args);
void msg(std::string target, std::string msg);
void readLoop();
void dataReceived(const char *buffer);
void process(ParsedLine line);
void handleCommand(CommandLine line);
TCPSocket *socket;
void log(std::string s);
void registerModule(Module *mod);
void SendNextCap();
void PauseCap();
void ResumeCap();
private:
unsigned int capPaused = 0;
std::vector<IRC::Module *> modules;
const int RCVBUFSIZE = 1024;
std::string host;
unsigned short port;
std::vector<std::string> capQueue;
std::string inputBuffer;
std::string nick;
std::string user;
std::string realname;
bool _useNickServ;
std::string ns_user;
std::string ns_pass;
json config;
std::map<std::string, std::string> cmds;
IRC::Bot *bot;
bool connected = false;
};
}
#endif //IRCBOT_IRC_H