-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.cpp
53 lines (45 loc) · 1.12 KB
/
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
51
52
53
#include <iostream>
#include <string>
#include <exception>
#include <string.h>
#include <regex>
#include <list>
#include "time.h"
#include "Irc.h"
#include "Message.h"
#define PRIVMSG ":(.+)\\!.+ (PRIVMSG|privmsg) (\\#\\w+) \\:(.+)"
int main(void) {
try {
bool auth = false;
int rows = 0;
Irc irc = Irc("irc.example.org", 6667, "nameBot");
irc.connect();
std::string message;
std::regex re(PRIVMSG);
std::smatch match;
while (true) {
message = irc.read();
if (strcmp(message.substr(0, 4).c_str(), "PING") == 0) {
irc.pingHandler(message);
}
Message* tmp = nullptr;
if (std::regex_search(message, match, re) && match.size() > 1) {
tmp = new Message(match[1].str(), match[4].str(), match[3].str());
std::cout << *tmp << std::endl;
delete tmp;
}
if ((rows == 6) && !auth) {
auth = true;
irc.join("#channel");
irc.sendMessage("#channel", "test");
}
//std::cout << message << std::endl;
rows++;
}
}
catch (std::exception& e) {
std::cout << "error " << e.what() << std::endl;
}
system("PAUSE");
return 0;
}