From 7e360b3ddaceb65f5cd14eae895085dcae2f9bef Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 10 Aug 2013 13:50:10 -0400 Subject: Implemented everything except soundex and kicking --- .gitignore | 1 + main.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- triggers.txt | 21 +++++++++++ 3 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 triggers.txt diff --git a/.gitignore b/.gitignore index e33439a..42be889 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ kankri *.o +config.yml diff --git a/main.cpp b/main.cpp index 1ef7833..408f1b2 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,7 @@ #include #include #include +#include /* * @@ -25,6 +26,7 @@ char* nick; int port; char* password; char* channel; +std::list > phonemes; char* _(const char* str) { @@ -33,6 +35,72 @@ char* _(const char* str) return res; } +std::string soundex(std::string input) +{ + //UHH +} + +std::string stripspecial(std::string input) +{ + std::string result; + for (char* p=_(input.c_str()); *p!=0; ++p) + { + if (*p > 64 && *p < 91) + { + result.push_back(*p); + } else if (*p == 32) + { + result.push_back(' '); + } else if (*p > 96 && *p < 123) + { + result.push_back(*p+32); + } else { + result.push_back(' '); + } + } + + return result; +} + +std::list tokenize(std::string input) +{ + std::list results; + std::string cur; + for (char* p=_(input.c_str()); *p!=0; ++p) + { + if (*p == ' ') + { + if (cur.compare("") != 0) + { + results.push_back(cur); + cur = std::string(""); + } + } else { + cur.push_back(*p); + } + } + + if (cur.compare("") != 0) + { + results.push_back(cur); + } + + return results; +} + +std::list phonemize(std::string input) +{ + std::string r = stripspecial(input); + std::list tf = tokenize(r); + std::list result; + for (std::list::iterator it=tf.begin(); it!=tf.end(); ++it) + { + result.push_back(soundex(*it)); + } + + return result; +} + int message(char* params, irc_reply_data* hostd, void* conn) { std::string str(params); @@ -43,6 +111,26 @@ int message(char* params, irc_reply_data* hostd, void* conn) } // Examine content of strings + std::list sounds = phonemize(str); + for (std::list >::iterator it=phonemes.begin(); it!=phonemes.end(); ++it) + { + std::list::iterator jt = it->begin(); + for (std::list::iterator kt=sounds.begin(); kt!=sounds.end(); ++kt) + { + if (kt->compare(*jt) == 0) + { + jt++; + + if (jt == it->end()) + { + // The user used a trigger! + ((IRC*) conn)->privmsg(channel, _("Triggered.")); + } + } else { + jt = it->begin(); + } + } + } return 0; } @@ -50,7 +138,7 @@ int message(char* params, irc_reply_data* hostd, void* conn) int end_of_motd(char* params, irc_reply_data* hostd, void* conn) { IRC* irc_conn = (IRC*) conn; - irc_conn->privmsg(_("NickServ"), strcat(_("Identify "), password)); + //irc_conn->privmsg(_("NickServ"), strcat(_("Identify "), password)); irc_conn->join(channel); irc_conn->hook_irc_command(_("PRIVMSG"), &message); @@ -71,11 +159,27 @@ int main(int argc, char** argv) port = config["port"].as(); nick = _(config["nick"].as().c_str()); password = _(config["password"].as().c_str()); - channel = _(config["password"].as().c_str()); + channel = _(config["channel"].as().c_str()); + + FILE* triggers = fopen("triggers.txt", "r"); + if (triggers == NULL) + { + perror("Invalid triggers file."); + abort(); + } + + while (!feof(triggers)) + { + char* trigger_in = (char*) calloc(512, sizeof(char)); + fgets(trigger_in, 512, triggers); + std::string trigger(trigger_in); + free(trigger_in); + phonemes.push_back(phonemize(trigger)); + } IRC conn; - conn.hook_irc_command("266", &end_of_motd); - conn.start(hostname, port, nick, nick, nick, password); + conn.hook_irc_command(_("266"), &end_of_motd); + conn.start(hostname, port, nick, nick, nick, _("")); conn.message_loop(); 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 @@ +I'm a fabulous pony +I'm a reliable pony +I'm a shy pony +I'm a awesome pony +I'm a smart pony +I am a human being +I am a pretty pegasus +I'm a musical pony +I'm a bragging pony +I am a unicorn stallion +I am a unicorn mare +I'm a fun pony +Revert to normal +I love my pony ears +I don't want my pony ears +I am the Batman +I am Bruce Wayne +I'm a classical pony +I'm a valiant pony +My wings are so pretty! +I am a very, very fat pony \ No newline at end of file -- cgit 1.4.1