-
Notifications
You must be signed in to change notification settings - Fork 0
/
Irc.h
201 lines (175 loc) · 5.05 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
// Author: Jakub Fajkus
// Project: ISA IRC bot
// Last revision: 17.11.2017
//
#ifndef ISA_IRC_H
#define ISA_IRC_H
#include "IrcServer.h"
#include "SyslogServer.h"
#include "utils.h"
#include "Channel.h"
class Irc {
private:
IrcServer *irc_server;
SyslogServer *syslog_server;
vector<string> keywords;
vector<Channel> channels;
string channels_string;
/**
* Proccesses the PRIVMSG or NOTICE message
*
* @param response Response string
* @param tokens Response string split by space
*/
void handle_privmsg(string response, vector<string> tokens);
/**
* Check if the given tokens contain the given keywords
*
* @param tokens
* @param keywords
*
* @return True, if at least one keyword is present in the tokens, false otherwise
*/
bool contains_keywords(vector<string> tokens, vector<string> keywords);
/**
* Handles the error messages
*
* @param tokens Tokens of the message
*/
void handle_error_messages(vector<string> tokens);
/**
* Get the channel object.
*
* If the object is not found, it is created.
*
* @param name Name of the channel
* @return Channel
*/
Channel *get_channel(string &name);
/**
* Adds the user to the channel
*
* @param channel Channel name
* @param nickname User nickname
*/
void add_user_to_channel(string channel, string nickname);
/**
* Removes the user from the channel
*
* @param channel Channel name
* @param nickname User nickname
*/
void remove_user_from_channel(string channel, string nickname);
/**
* Get the user's nickname from the message
*
* @param message The message string
*
* @return User's nickname. If the nickname could not be found, empty string is returned
*/
string get_nickname_from_message(string message);
/**
* Get vector of strings of all queued messages for the user
*
* @param nickname User's nickname
* @param channel Channel name
* @return All user's messages for the chanel
*/
vector<string> get_messages_for_user(string nickname, string channel);
/**
* Send all queued messages to the user
*
* @param nickname User's nickname
* @param channel Channel name
*/
void send_messages_to_user(string nickname, string channel);
/**
* Queue a new message for the user to given channel
*
* @param nickname User's nickname
* @param channel Channel name
* @param message Mesage content
*/
void add_message_for_user(string nickname, string channel, string message);
/**
* Handles the name reply from the server.
*
* The server sends a list of nicknames connected to a channel.
* The method adds all nicknames to the channel
*
* @param tokens Message tokens
*/
void handle_name_reply(vector<string> tokens);
/**
* Handles the JOIN message.
*
* Add the user to a channel
*
* @param response Message string
* @param tokens Message tokens
*/
void handle_join(string response, vector<string> tokens);
/**
* Handles the PART message
*
* Remove the user from the specified channels
*
* @param response Message string
* @param tokens Message tokens
*/
void handle_part(string response, vector<string> tokens);
/**
* Handles the QUIT message
*
* Remove the user from all channels
*
* @param response Message string
*/
void handle_quit(string response);
/**
* Handles the KICK message of an user.
*
* Remove user from the channel
*
* This does not handle the KICK of the bot itself.
*
* @param response Message string
*/
void handle_kick(vector<string> response);
/**
* Handles the NICK message
*
* Removes the user's old nickname from all channels.
* Add the user's new nickname to all channels
*
* @param response Message string
* @param tokens Message tokens
*/
void handle_nick(string response, vector<string> tokens);
public:
/**
* Creates an object and creates channels based on the channels string given
*
* @param irc_server IRC server connection
* @param syslog_server Syslog server connection
* @param keywords Keywords which will be logged to the syslog server if present in a user's message
* @param channels Channels to connect to. It's coma separated list of channel names(insluding the # and & characters)
*/
Irc(IrcServer *irc_server, SyslogServer *syslog_server, vector<string> keywords, string channels);
/**
* Initialize the connection with the IRC server
*
* Connects to all channels given
*/
void init_connection();
/**
* Start the main program loop, in which messages from the IRC server are received and processed.
*/
void listen();
/**
* Closs the conneciton with the IRC and syslog servers.
*/
void quit();
};
#endif //ISA_IRC_H