-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.cpp
106 lines (81 loc) · 2.1 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
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
#include <iostream>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include "bot.h"
using namespace std;
int main()
{
try {
// Starts a new cleverbot with the variables set in the file 'config'
clever_bot::bot bot("config");
// Sets its name and joins a channel
//bot.nick("botche");
//bot.join("#murilo");
// Read handlers example (will be improved soon)
bot.add_read_handler([&bot](const std::string& m) {
std::istringstream iss(m);
std::string from, type, to, msg;
iss >> from >> type >> to >> msg;
if (msg == ":!time") {
std::time_t now = std::chrono::system_clock::to_time_t(
std::chrono::system_clock::now());
bot.message(to, std::ctime(&now));
}
});
bot.add_read_handler([&bot](const std::string& m) {
std::istringstream iss(m);
std::string from, type, to, cmd, nck, chann, key;
iss >> from >> type >> to >> cmd >> nck >> chann >> key;
if (cmd == ":!op" && bot.rightPass(key)) {
bot.op(nck, chann);
}
});
bot.add_read_handler([&bot](const std::string& m) {
std::istringstream iss(m);
std::string type, to, text;
iss >> type;
if (type == "PING") {
text = "";
while ((iss >> to)) {
text += to + " ";
}
bot.pong(text);
}
});
bot.add_read_handler([&bot](const std::string& m) {
std::istringstream iss(m);
std::string from, type, to, msg, text;
iss >> from >> type >> to >> msg;
if (msg == ":!echo") {
text = "";
while ((iss >> msg)) {
text += msg + " ";
}
if (text != "") {
bot.message(to, text);
}
}
});
bot.add_read_handler([&bot](const std::string& m) {
std::istringstream iss(m);
std::ostringstream oss;
std::string from, type, to, msg;
iss >> from >> type >> to >> msg;
if (msg == ":!rand") {
int mx, ans = std::rand();
if (iss >> mx) {
ans = ans % mx;
}
oss << ans;
bot.message(to, from + ": " + oss.str());
}
});
// Main execution
bot.loop();
}
catch (const std::exception& e) {
std::cout << e.what() << std::endl;
}
return 0;
}