summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--main.cpp112
-rw-r--r--triggers.txt21
3 files changed, 130 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore index e33439a..42be889 100644 --- a/.gitignore +++ b/.gitignore
@@ -1,2 +1,3 @@
1kankri 1kankri
2*.o 2*.o
3config.yml
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);
diff --git a/triggers.txt b/triggers.txt new file mode 100644 index 0000000..d0b8d1a --- /dev/null +++ b/triggers.txt
@@ -0,0 +1,21 @@
1I'm a fabulous pony
2I'm a reliable pony
3I'm a shy pony
4I'm a awesome pony
5I'm a smart pony
6I am a human being
7I am a pretty pegasus
8I'm a musical pony
9I'm a bragging pony
10I am a unicorn stallion
11I am a unicorn mare
12I'm a fun pony
13Revert to normal
14I love my pony ears
15I don't want my pony ears
16I am the Batman
17I am Bruce Wayne
18I'm a classical pony
19I'm a valiant pony
20My wings are so pretty!
21I am a very, very fat pony \ No newline at end of file