Esempio n. 1
0
 public function __construct($argc, $argv)
 {
     $this->xbot = new xbot();
     // new xbot
     if ($argc > 1 && $argv[1] == 'debug') {
         self::$debug = true;
     }
     // argc
     $conf = file_get_contents('github.conf');
     self::$config = json_decode($conf, true);
     if (self::$config == null) {
         self::debug('failed config parse, you may have comments in it, remove them :)');
         die;
     }
     // config can't be parsed.
     self::debug('connecting to mysql (' . self::$config['mysql']['host'] . ':' . self::$config['mysql']['db'] . ')');
     self::$db = mysql_connect(self::$config['mysql']['host'], self::$config['mysql']['user'], self::$config['mysql']['pass']);
     mysql_select_db(self::$config['mysql']['db'], self::$db);
     // connect to mysql
     foreach (self::$config['networks'] as $network => $net_data) {
         self::debug('connecting to (' . $network . ':' . $net_data['port'] . ') as ' . $net_data['nick']);
     }
     $this->xbot->connect(self::$config);
     self::debug('connected to networks');
     // connect the bot
     $this->xbot->timer->add(array('bot', 'listen_data', array($this->xbot)), 5, 0);
     $this->xbot->timer->add(array('bot', 'get_new_data', array($this->xbot)), self::$config['options']['new_data_interval'], 0);
     // set up some timers, we only actually go hunting for new data every 30 seconds, then if new data is found its stored
     // the stored data is checked by listen_data every 5 seconds. We only check every 30 seconds because for huge repos like
     // rails/rails, which I developed this on it can be quite intensive, and plus the more often we check the quicker
     // we can run out of api calls (unless you get on the whitelist)
     $this->xbot->main('bot', 'main');
     // boot the main loop w/ a callback*/
 }
Esempio n. 2
0
 public function main($xbot, $ircdata)
 {
     if ($xbot->events->on_ping($xbot->ircdata)) {
         if (!mysql_ping(self::$db)) {
             mysql_close(self::$db);
             self::$db = mysql_connect(self::$config['mysql']['host'], self::$config['mysql']['user'], self::$config['mysql']['pass']);
             mysql_select_db(self::$config['mysql']['db'], self::$db);
             // connect to mysql
         }
     }
     // ping
     self::log_chans($ircdata);
     if ($ircdata->type == 'privmsg' && $ircdata->target[0] == '#') {
         $message = explode(' ', $ircdata->message);
         $nmessage = $message;
         if (in_array(strtolower($message[0]), self::$config['bot_triggers'])) {
             unset($nmessage[0]);
             $rmessage = implode(' ', $nmessage);
             if (strtolower($message[1]) == 'quote') {
                 if (isset($message[2]) && isset($message[3]) && is_numeric($message[2]) && is_numeric($message[3]) && $message[2] >= 0 && $message[3] <= 30 && $message[3] > $message[2]) {
                     $from = $message[2];
                     $to = $message[3];
                     $chan = $ircdata->target;
                     // set some variables
                     $mybuffer = self::$buffer[$chan];
                     $pop = array_pop($mybuffer);
                     $mybuffer = array_reverse($mybuffer);
                     // do some SHUFFLING!!
                     $mybuffer = array_slice($mybuffer, $from, $to);
                     $mybuffer = implode("\r\n", $mybuffer);
                     // get what we need.
                     mysql_query("INSERT INTO `" . self::$config['mysql']['table'] . "` (`quote`,`by`,`date`) VALUES('" . $mybuffer . "','" . $from . "','" . time() . "')");
                     // INSERT into the database
                     return false;
                 } else {
                     return false;
                 }
                 // it isnt.
                 // check if the format is right..
             }
             // sam, quote.
             if (strtolower($message[1]) == 'info') {
                 $num_of_items = mysql_query("SELECT `id` FROM `" . self::$config['mysql']['table'] . "`");
                 $num_of_items = mysql_num_rows($num_of_items);
                 $uptime = self::format_time(timer::$uptime);
                 $reply = self::$config['info_info'];
                 $reply = str_replace('{items}', $num_of_items, $reply);
                 $reply = str_replace('{uptime}', $uptime, $reply);
                 $reply = str_replace('{queries}', self::$queries, $reply);
                 self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                 // msg to the channel.
                 return false;
             }
             // sam, info.
             if (strtolower($message[1]) == 'join') {
                 if (!in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is a non admin trying to f**k around with our shit? :/
                 $chan = $message[2];
                 $key = $message[3];
                 // chan, and key, if a key is needed
                 if ($chan == null) {
                     return false;
                 }
                 // error
                 $xbot->join($ircdata->from, $chan, $key);
                 // join the channel :)
                 return false;
             }
             // Samantha, join
             if (strtolower($message[1]) == 'part') {
                 if (!in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is a non admin trying to f**k around with our shit? :/
                 $chan = $message[2];
                 $message = $xbot->get_data_after($message, 3);
                 // chan, and message
                 if ($chan == null) {
                     return false;
                 }
                 // error
                 $xbot->part($ircdata->from, $chan, $message);
                 // part the channel :)
                 return false;
             }
             // Samantha, part
             if (strtolower($message[1]) == 'nick') {
                 if (!in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is a non admin trying to f**k around with our shit? :/
                 $new_nick = $message[2];
                 // chan, and message
                 if ($new_nick == null) {
                     return false;
                 }
                 // error
                 self::$config['networks'][$from]['nick'] = $new_nick;
                 $xbot->nick($ircdata->from, $new_nick);
                 // change nick
                 return false;
             }
             // Samantha, nick
             if (strtolower($message[1]) == 'quiet') {
                 if (self::$quiet) {
                     return false;
                 }
                 // is samantha in quiet mode?!
                 if (!in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is a non admin trying to f**k around with our shit? :/
                 self::$quiet = true;
                 $reply = array_rand(self::$config['quiet_replies']);
                 $reply = self::$config['quiet_replies'][$reply];
                 $reply = str_replace('{nick}', $ircdata->nick, $reply);
                 // find a random reply, and replace {shit} with shit, etc. lol
                 self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                 // msg to the channel.
                 return false;
             }
             // Samantha, quiet
             if (strtolower($message[1]) == 'wakeup') {
                 if (!self::$quiet) {
                     return false;
                 }
                 // is samantha in quiet mode?!
                 if (!in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is a non admin trying to f**k around with our shit? :/
                 self::$quiet = false;
                 $reply = array_rand(self::$config['wakeup_replies']);
                 $reply = self::$config['wakeup_replies'][$reply];
                 $reply = str_replace('{nick}', $ircdata->nick, $reply);
                 // find a random reply, and replace {shit} with shit, etc. lol
                 self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                 // msg to the channel.
                 return false;
             }
             // Samantha, wakeup
             if (self::$quiet) {
                 return false;
             }
             // is samantha in quiet mode?!
             if (strtolower($message[1]) == 'who' && strtolower($message[2]) == 'told' && strtolower($message[3]) == 'you' && strtolower($message[4]) == 'about' && isset($message[5])) {
                 $key = $xbot->get_data_after($message, 5);
                 // could be a "shauns feet smell of cheese" < eg, multiple keys
                 if (substr($key, -1, 1) == '?' || substr($key, -1, 1) == '.' || substr($key, -1, 1) == '!') {
                     $key = substr($key, 0, -1);
                 }
                 // replace the value shit
                 $key = mysql_real_escape_string($key);
                 // escape the string, so theres no crap in it.
                 $info_query = mysql_query("SELECT `key`,`value`,`date`,`setby`,`locked` FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                 // have we found a reply?
                 if (mysql_num_rows($info_query) == 0) {
                     $reply = array_rand(self::$config['dont_know_replies']);
                     $reply = self::$config['dont_know_replies'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     $reply = str_replace('{key}', $key, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 } else {
                     $info_row = mysql_fetch_array($info_query);
                     // grab the row
                     self::msg($xbot, $ircdata->from, $ircdata->target, $info_row['setby'] . ' told me about ' . $key . ' on ' . date('F j, Y, g:i a', $info_row['date']));
                     return false;
                 }
             }
             // Samantha, who told you about *
             if (strtolower($message[1]) == 'forget' && isset($message[2])) {
                 $key = mysql_real_escape_string($xbot->get_data_after($message, 2));
                 // escape the string, so theres no crap in it.
                 $info_query = mysql_query("SELECT `key`,`locked` FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                 // have we found a reply?
                 if (mysql_num_rows($info_query) == 0) {
                     $reply = array_rand(self::$config['dont_know_replies']);
                     $reply = self::$config['dont_know_replies'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     $reply = str_replace('{key}', $key, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 } else {
                     $info_row = mysql_fetch_array($info_query);
                     // grab the row
                     if ($info_row['locked'] == 1 && !in_array($ircdata->host, self::$config['admin_hosts'])) {
                         $reply = array_rand(self::$config['info_locked']);
                         $reply = self::$config['info_locked'][$reply];
                         $reply = str_replace('{nick}', $ircdata->nick, $reply);
                         // find a random reply, and replace {shit} with shit, etc. lol
                         self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                         // msg to the channel.
                         return false;
                     }
                     // is it locked? :/
                     mysql_query("DELETE FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                     // delete the record
                     $reply = array_rand(self::$config['info_forgot']);
                     $reply = self::$config['info_forgot'][$reply];
                     $reply = str_replace('{key}', $key, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // yes we have
             }
             // Samantha, forget
             if (strtolower($message[1]) == 'lock' || strtolower($message[1]) == 'unlock' && isset($message[2])) {
                 if (!in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is a non admin trying to f**k around with our shit? :/
                 $key = mysql_real_escape_string($xbot->get_data_after($message, 2));
                 // escape the string, so theres no crap in it.
                 $info_query = mysql_query("SELECT `key`,`locked` FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                 // have we found a reply?
                 if (mysql_num_rows($info_query) == 0) {
                     $reply = array_rand(self::$config['dont_know_replies']);
                     $reply = self::$config['dont_know_replies'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     $reply = str_replace('{key}', $key, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 } else {
                     $tinyint = $message[1] == 'lock' ? 1 : 0;
                     mysql_query("UPDATE `" . self::$config['mysql']['table'] . "` SET `locked` = '" . $tinyint . "' WHERE `key` = '" . $key . "'");
                     // update
                     $reply = array_rand(self::$config['info_confirm']);
                     $reply = self::$config['info_confirm'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // yes we have
             }
             // Samantha, lock * && Samantha, unlock *
             if (preg_match('/(.*): (.*)/is', $rmessage)) {
                 $keys = explode(':', $rmessage, 2);
                 $key = mysql_real_escape_string(trim($keys[0]));
                 $key = str_replace('\\', '', $key);
                 // replace \ with '' because \ is our reply delimeter.
                 $value = mysql_real_escape_string(trim($keys[1]));
                 // escape the string, so theres no crap in it.
                 if (in_array($key, self::$config['system_phrases'])) {
                     $reply = array_rand(self::$config['info_reserved']);
                     $reply = self::$config['info_reserved'][$reply];
                     // find a random reply
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is this a reserved word?
                 $info_query = mysql_query("SELECT `key`,`value`,`locked` FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                 // have we found a reply?
                 if (mysql_num_rows($info_query) == 0) {
                     $setby = mysql_real_escape_string($ircdata->nick);
                     $date = time();
                     mysql_query("INSERT INTO `" . self::$config['mysql']['table'] . "` (`key`,`value`,`setby`,`date`) VALUES('" . $key . "','" . $value . "','" . $setby . "','" . $date . "')");
                     // update
                     $reply = array_rand(self::$config['info_confirm']);
                     $reply = self::$config['info_confirm'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 } else {
                     $info_row = mysql_fetch_array($info_query);
                     // fetch the row
                     if (strtolower(trim($info_row['value'])) == strtolower(trim($value))) {
                         self::msg($xbot, $ircdata->from, $ircdata->target, 'I know :D');
                         // msg to the channel.
                         return false;
                     }
                     // we know -.-
                     $reply = array_rand(self::$config['info_notnew']);
                     $reply = self::$config['info_notnew'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     $reply = str_replace('{key}', stripslashes($info_row['key']), $reply);
                     $reply = str_replace('{value}', stripslashes($info_row['value']), $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // yes we have*/
             }
             // Samantha, *: * (assignment) (changed this, easier i guess)
             if (isset($message[1]) && strpos($rmessage, ':') === false) {
                 $keys = preg_split('/\\\\/si', $xbot->get_data_after($message, 1), -1, PREG_SPLIT_NO_EMPTY);
                 $key = trim($keys[0]);
                 // could be a "shauns feet smell of cheese" < eg, multiple keys
                 ++self::$queries;
                 if (substr($key, -1, 1) == '?' || substr($key, -1, 1) == '.' || substr($key, -1, 1) == '!') {
                     $key = substr($key, 0, -1);
                 }
                 // replace the value shit
                 $key = mysql_real_escape_string($key);
                 // escape the string, so theres no crap in it.
                 $info_query = mysql_query("SELECT `key`,`value`,`locked`,`setby` FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                 // have we found a reply?
                 if (mysql_num_rows($info_query) == 0) {
                     $reply = array_rand(self::$config['dont_know_replies']);
                     $reply = self::$config['dont_know_replies'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     $reply = str_replace('{key}', $key, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 } else {
                     $info_row = mysql_fetch_array($info_query);
                     // fetch the row
                     $reply = array_rand(self::$config['info_replies']);
                     $reply = self::$config['info_replies'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     $reply = str_replace('{key}', stripslashes($info_row['key']), $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     $value = stripslashes($info_row['value']);
                     $value = str_replace('<reply>', trim($keys[1]), $value);
                     $value = str_replace('<encode_reply>', str_replace(' ', '+', trim($keys[1])), $value);
                     $value = str_replace('<wiki_encode>', str_replace(' ', '_', trim($keys[1])), $value);
                     $value = str_replace('<nick>', $info_row['setby'], $value);
                     $value = str_replace('<me>', bot::$config['networks']['irc.gamergrid.net']['nick'], $value);
                     $value = str_replace('<who>', $ircdata->nick, $value);
                     // replace <reply> and stuff
                     $reply = str_replace('{value}', $value, $reply);
                     // replace {value} last, because we've modified it with expansions :D
                     if (trim(substr($value, 0, 8)) == '<action>') {
                         $xbot->action($ircdata->from, $ircdata->target, substr($value, 8));
                     } else {
                         self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     }
                     // msg to the channel.
                     return false;
                 }
                 // yes we have
             }
             // Samantha, * (phrase)
         }
         // Samantha, message here
         if (self::$quiet) {
             return false;
         }
         // is samantha in quiet mode?!
         unset($nmessage[0], $nmessage[1]);
         $nrmessage = implode(' ', $nmessage);
         if (strtolower($message[0]) == 'no' && in_array(strtolower($message[1]), self::$config['bot_triggers']) && preg_match('/(.*) \\b(' . self::$config['assignment_regex'] . ')\\b/is', $nrmessage)) {
             $keys = preg_split('/\\b(' . self::$config['assignment_regex'] . ')\\b/i', $nrmessage, -1, PREG_SPLIT_DELIM_CAPTURE);
             $key = mysql_real_escape_string(trim($keys[0]));
             $key = str_replace('\\', '', $key);
             // replace \ with '' because \ is our reply delimeter.
             // escape the string, so theres no crap in it.
             if (in_array($key, self::$config['system_phrases'])) {
                 $reply = array_rand(self::$config['info_reserved']);
                 $reply = self::$config['info_reserved'][$reply];
                 // find a random reply
                 self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                 // msg to the channel.
                 return false;
             }
             // is this a reserved word?
             $info_query = mysql_query("SELECT `key`,`value`,`locked` FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
             // have we found a reply?
             if (mysql_num_rows($info_query) == 0) {
                 $reply = array_rand(self::$config['dont_know_replies']);
                 $reply = self::$config['dont_know_replies'][$reply];
                 $reply = str_replace('{nick}', $ircdata->nick, $reply);
                 $reply = str_replace('{key}', $key, $reply);
                 // find a random reply, and replace {shit} with shit, etc. lol
                 self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                 // msg to the channel.
                 return false;
             } else {
                 $info_row = mysql_fetch_array($info_query);
                 if ($info_row['locked'] == 1 && !in_array($ircdata->host, self::$config['admin_hosts'])) {
                     $reply = array_rand(self::$config['info_locked']);
                     $reply = self::$config['info_locked'][$reply];
                     $reply = str_replace('{nick}', $ircdata->nick, $reply);
                     // find a random reply, and replace {shit} with shit, etc. lol
                     self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                     // msg to the channel.
                     return false;
                 }
                 // is it locked? :/
                 $value = mysql_real_escape_string(trim($xbot->get_data_after($keys, 2)));
                 $setby = mysql_real_escape_string($ircdata->nick);
                 $date = time();
                 // bleh.. escape all the stuff we're about to insert into the database.
                 mysql_query("DELETE FROM `" . self::$config['mysql']['table'] . "` WHERE `key` = '" . $key . "'");
                 mysql_query("INSERT INTO `" . self::$config['mysql']['table'] . "` (`key`,`value`,`setby`,`date`) VALUES('" . $key . "','" . $value . "','" . $setby . "','" . $date . "')");
                 // update
                 $reply = array_rand(self::$config['info_confirm']);
                 $reply = self::$config['info_confirm'][$reply];
                 $reply = str_replace('{nick}', $ircdata->nick, $reply);
                 // find a random reply, and replace {shit} with shit, etc. lol
                 self::msg($xbot, $ircdata->from, $ircdata->target, $reply);
                 // msg to the channel.
                 return false;
             }
             // yes we have
         }
         // no Samantha, * is * (reassignment)
     }
     // only trigger on channel privmsgs
 }