summary refs log tree commit diff stats
path: root/main.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2013-08-10 13:50:10 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2013-08-10 13:50:10 -0400
commit7e360b3ddaceb65f5cd14eae895085dcae2f9bef (patch)
tree75462ef8e22ea6568c8bbb13bd672ac0f32be6a5 /main.cpp
parentc5bf41e4c8ba513602e835c50ea815d6cc9de335 (diff)
downloadkankri-7e360b3ddaceb65f5cd14eae895085dcae2f9bef.tar.gz
kankri-7e360b3ddaceb65f5cd14eae895085dcae2f9bef.tar.bz2
kankri-7e360b3ddaceb65f5cd14eae895085dcae2f9bef.zip
Implemented everything except soundex and kicking HEAD master
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp112
1 files changed, 108 insertions, 4 deletions
diff --git a/main.cpp b/main.cpp index 1ef7833..408f1b2 100644 --- a/main.cpp +++ b/main.cpp
@@ -15,6 +15,7 @@
15#include <deque> 15#include <deque>
16#include <algorithm> 16#include <algorithm>
17#include <yaml-cpp/yaml.h> 17#include <yaml-cpp/yaml.h>
18#include <list>
18 19
19/* 20/*
20 * 21 *
@@ -25,6 +26,7 @@ char* nick;
25int port; 26int port;
26char* password; 27char* password;
27char* channel; 28char* channel;
29std::list<std::list<std::string> > phonemes;
28 30
29char* _(const char* str) 31char* _(const char* str)
30{ 32{
@@ -33,6 +35,72 @@ char* _(const char* str)
33 return res; 35 return res;
34} 36}
35 37
38std::string soundex(std::string input)
39{
40 //UHH
41}
42
43std::string stripspecial(std::string input)
44{
45 std::string result;
46 for (char* p=_(input.c_str()); *p!=0; ++p)
47 {
48 if (*p > 64 && *p < 91)
49 {
50 result.push_back(*p);
51 } else if (*p == 32)
52 {
53 result.push_back(' ');
54 } else if (*p > 96 && *p < 123)
55 {
56 result.push_back(*p+32);
57 } else {
58 result.push_back(' ');
59 }
60 }
61
62 return result;
63}
64
65std::list<std::string> tokenize(std::string input)
66{
67 std::list<std::string> results;
68 std::string cur;
69 for (char* p=_(input.c_str()); *p!=0; ++p)
70 {
71 if (*p == ' ')
72 {
73 if (cur.compare("") != 0)
74 {
75 results.push_back(cur);
76 cur = std::string("");
77 }
78 } else {
79 cur.push_back(*p);
80 }
81 }
82
83 if (cur.compare("") != 0)
84 {
85 results.push_back(cur);
86 }
87
88 return results;
89}
90
91std::list<std::string> phonemize(std::string input)
92{
93 std::string r = stripspecial(input);
94 std::list<std::string> tf = tokenize(r);
95 std::list<std::string> result;
96 for (std::list<std::string>::iterator it=tf.begin(); it!=tf.end(); ++it)
97 {
98 result.push_back(soundex(*it));
99 }
100
101 return result;
102}
103
36int message(char* params, irc_reply_data* hostd, void* conn) 104int message(char* params, irc_reply_data* hostd, void* conn)
37{ 105{
38 std::string str(params); 106 std::string str(params);
@@ -43,6 +111,26 @@ int message(char* params, irc_reply_data* hostd, void* conn)
43 } 111 }
44 112
45 // Examine content of strings 113 // Examine content of strings
114 std::list<std::string> sounds = phonemize(str);
115 for (std::list<std::list<std::string> >::iterator it=phonemes.begin(); it!=phonemes.end(); ++it)
116 {
117 std::list<std::string>::iterator jt = it->begin();
118 for (std::list<std::string>::iterator kt=sounds.begin(); kt!=sounds.end(); ++kt)
119 {
120 if (kt->compare(*jt) == 0)
121 {
122 jt++;
123
124 if (jt == it->end())
125 {
126 // The user used a trigger!
127 ((IRC*) conn)->privmsg(channel, _("Triggered."));
128 }
129 } else {
130 jt = it->begin();
131 }
132 }
133 }
46 134
47 return 0; 135 return 0;
48} 136}
@@ -50,7 +138,7 @@ int message(char* params, irc_reply_data* hostd, void* conn)
50int end_of_motd(char* params, irc_reply_data* hostd, void* conn) 138int end_of_motd(char* params, irc_reply_data* hostd, void* conn)
51{ 139{
52 IRC* irc_conn = (IRC*) conn; 140 IRC* irc_conn = (IRC*) conn;
53 irc_conn->privmsg(_("NickServ"), strcat(_("Identify "), password)); 141 //irc_conn->privmsg(_("NickServ"), strcat(_("Identify "), password));
54 irc_conn->join(channel); 142 irc_conn->join(channel);
55 irc_conn->hook_irc_command(_("PRIVMSG"), &message); 143 irc_conn->hook_irc_command(_("PRIVMSG"), &message);
56 144
@@ -71,11 +159,27 @@ int main(int argc, char** argv)
71 port = config["port"].as<int>(); 159 port = config["port"].as<int>();
72 nick = _(config["nick"].as<std::string>().c_str()); 160 nick = _(config["nick"].as<std::string>().c_str());
73 password = _(config["password"].as<std::string>().c_str()); 161 password = _(config["password"].as<std::string>().c_str());
74 channel = _(config["password"].as<std::string>().c_str()); 162 channel = _(config["channel"].as<std::string>().c_str());
163
164 FILE* triggers = fopen("triggers.txt", "r");
165 if (triggers == NULL)
166 {
167 perror("Invalid triggers file.");
168 abort();
169 }
170
171 while (!feof(triggers))
172 {
173 char* trigger_in = (char*) calloc(512, sizeof(char));
174 fgets(trigger_in, 512, triggers);
175 std::string trigger(trigger_in);
176 free(trigger_in);
177 phonemes.push_back(phonemize(trigger));
178 }
75 179
76 IRC conn; 180 IRC conn;
77 conn.hook_irc_command("266", &end_of_motd); 181 conn.hook_irc_command(_("266"), &end_of_motd);
78 conn.start(hostname, port, nick, nick, nick, password); 182 conn.start(hostname, port, nick, nick, nick, _(""));
79 conn.message_loop(); 183 conn.message_loop();
80 184
81 return (EXIT_SUCCESS); 185 return (EXIT_SUCCESS);