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 --- main.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 108 insertions(+), 4 deletions(-) (limited to 'main.cpp') 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); -- cgit 1.4.1