Esempio n. 1
0
 function onChannelMessage()
 {
     if (libString::startsWith("!seen", $this->data['text'])) {
         return;
     }
     $this->saveVar($this->User->id, array('action' => 'PRIVMSG', 'server' => $this->Server->host, 'channel' => $this->Channel->name, 'nick' => $this->User->nick, 'text' => $this->data['text'], 'time' => $this->Bot->time));
 }
Esempio n. 2
0
 function onChannelMessage()
 {
     $link = libString::getLink($this->info['text']);
     if (!$link) {
         return;
     }
     if (substr(strtolower($link), 0, 7) == 'http://') {
         $link = substr($link, 7);
     }
     list($host, $get) = explode('/', $link, 2);
     if ($host == 'youtube.com' || $host == 'www.youtube.com') {
         return;
     }
     $get = '/' . $get;
     $res = libHTTP::GET($host, $get);
     if (!$res) {
         return;
     }
     if (substr($res['header']['Content-Type'], 0, 9) != 'text/html') {
         return;
     }
     $check = preg_match('#<title>(.*?)</title>#i', $res['raw'], $arr);
     if (!$check || empty($arr[1])) {
         return;
     }
     $title = html_entity_decode($arr[1], null, 'UTF-8');
     $title = strtr($title, array("\r" => ' ', "\n" => ' '));
     if ($title == '301 Moved') {
         return;
     }
     $this->sendOutput($title . " ( http://" . $link . " )");
 }
Esempio n. 3
0
 private function fetchFunctionDescription($func)
 {
     $HTTP = new HTTP('php.net');
     $html = $HTTP->GET('/' . $this->getConfig('language') . '/' . $func);
     if ($html === false) {
         $this->reply('Timeout on contacting ' . $host);
         return;
     }
     if (preg_match('/<span class=\\"refname\\">(.*?)<\\/span> &mdash; <span class=\\"dc\\-title\\">(.*?)<\\/span>/si', $html, $match)) {
         $match[2] = str_replace(array("\n", "\r"), ' ', strip_tags($match[2]));
         preg_match('/<div class=\\"methodsynopsis dc\\-description\\">(.*?)<\\/div>/si', $html, $descmatch);
         $decl = isset($descmatch[1]) ? strip_tags($descmatch[1]) : $match[1];
         $decl = html_entity_decode(str_replace(array("\n", "\r"), ' ', $decl));
         while (strstr($decl, '  ')) {
             $decl = str_replace('  ', ' ', $decl);
         }
         $decl = str_replace($func, "" . $func . "", $decl);
         $output = $decl . ' - ' . html_entity_decode($match[2]) . ' ( http://php.net/' . $func . ' )';
         $this->reply(libString::isUTF8($output) ? $output : utf8_encode($output));
     } else {
         // if several possibilities
         $output = '';
         if (preg_match_all('/<a href=\\"\\/manual\\/[a-z]+\\/(?:.*?)\\.php\\">(?:<b>)?(.*?)(?:<\\/b>)?<\\/a><br/i', $html, $matches, PREG_SET_ORDER)) {
             if ($this->redirects++ < 2) {
                 $this->fetchFunctionDescription($matches[0][1]);
             } else {
                 $this->reply($this->notfoundtext . ' http://php.net/search.php?show=wholesite&pattern=' . $this->data['text']);
             }
             return;
         } else {
             $output = $this->notfoundtext . ' http://php.net/search.php?show=wholesite&pattern=' . $func;
         }
         $this->reply(libString::isUTF8($output) ? $output : utf8_encode($output));
     }
 }
Esempio n. 4
0
 function isTriggered()
 {
     if (isset($this->info['text'])) {
         $target = $this->info['text'];
     } else {
         $target = $this->info['nick'];
     }
     $result = libHTTP::GET("www.rankk.org", "/profile/" . urlencode($target));
     var_dump($result);
     $result = implode("\n", $result['content']);
     if (preg_match("#<title>User Not Found</title>#", $result)) {
         $this->sendOutput($this->CONFIG['notfound_text']);
         return;
     }
     $nick = $target;
     preg_match("#>Rankk Title</td><td>(.*?)</td>#", $result, $arr);
     $title = $arr[1];
     preg_match("#>Rankked</td><td>(.*?)</td>#", $result, $arr);
     $rank = $arr[1];
     preg_match("#>Points</td><td>(.*?)</td>#", $result, $arr);
     $points = $arr[1];
     preg_match("#>Solved</td><td>(.*?)</td>#", $result, $arr);
     $solved = $arr[1];
     preg_match("#>Points</td><td>(.*?)</td>#", $result, $arr);
     $points = $arr[1];
     preg_match("#>Level</td><td>(.*?)</td>#", $result, $arr);
     $level = $arr[1];
     $output = sprintf($this->CONFIG['chall_text'], $nick, $title, $rank, $points, libString::end_s("point", $points), $solved, libString::end_s("challenge", $solved), $nick, $level);
     $this->sendOutput($output);
 }
Esempio n. 5
0
 function isTriggered()
 {
     clearstatcache();
     if (!file_exists("plugins/Electrica/cache") || filemtime("plugins/Electrica/cache") < time() - 60 * 20 && filectime("plugins/Electrica/cache") < time() - 60 * 20) {
         $this->cacheRanklist();
     }
     if (isset($this->info['text'])) {
         $target = $this->info['text'];
     } else {
         $target = $this->info['nick'];
     }
     $tmp = file_get_contents("plugins/Electrica/cache");
     $pos = stripos($tmp, '>' . $target . '<');
     if ($pos === false) {
         $this->sendOutput($this->CONFIG['notfound_text']);
         return;
     }
     $tmp1 = substr($tmp, 0, $pos);
     $rankpos = strrpos($tmp1, '<b>');
     preg_match("#^<b>(.*?)</b>#", substr($tmp1, $rankpos, 50), $arr);
     $rank = $arr[1];
     $tmp = substr($tmp, $pos - 100, 200);
     $target = preg_quote($target);
     preg_match('#<td align=center>(.*?)</td><td>(' . $target . ')</td><td align=right>(.*?)</td><td.*?>(.*?)</td>#i', $tmp, $arr);
     $output = sprintf($this->CONFIG['chall_text'], $arr[2], $rank, $arr[3], libString::end_s("challenge", $arr[3]), $arr[4]);
     $this->sendOutput($output);
 }
Esempio n. 6
0
 function showStats()
 {
     $sql = "SELECT COUNT(*) FROM slaps";
     $res = $this->MySQL->sendQuery($sql);
     $count = $res['result'][0]['COUNT(*)'];
     $output = sprintf($this->CONFIG['status_text'], $count, libString::end_s("way", $count));
     $this->sendOutput($output);
     return;
 }
Esempio n. 7
0
 function getStats($username, $html)
 {
     if (libString::startsWith('::', $html)) {
         return false;
     }
     $tmp = explode(':', $html);
     $data = array('username' => $username, 'rank' => $tmp[0], 'challs_solved' => $tmp[1], 'challs_total' => $tmp[2], 'users_total' => $tmp[3]);
     return $data;
 }
Esempio n. 8
0
 function isTriggered()
 {
     if (!isset($this->info['text'])) {
         $nick = $this->info['nick'];
     } else {
         $nick = $this->info['text'];
     }
     $domain = $this->CONFIG['domain'];
     $get = sprintf($this->CONFIG['get'], urlencode($nick));
     $result = libHTTP::GET($domain, $get);
     $result = implode($result['content'], "\n");
     if (preg_match("/There is no available information for/", $result)) {
         $this->sendOutput(sprintf($this->CONFIG['doesnt_exist'], $nick, $this->CONFIG['domain']));
         return;
     }
     preg_match('#<h3>User information of (VIP )?(.*?)</h3>#', $result, $arr);
     $nick = $arr[2];
     preg_match('#<b>Rank:</b>.*?<font color=".*?">(.*?)</font>#', $result, $arr);
     $rank = $arr[1];
     preg_match('#<b>Donated:</b>.*?<font color=".*?">(.*?)</font>#', $result, $arr);
     $donated = $arr[1];
     if ($donated == "This guy didn't donate anything yet!") {
         $donated = false;
     } else {
         $donated = str_replace(" ", "", $donated);
     }
     preg_match('#<b>Number of hacks:</b>.*?<td>(.*?)</td>#', $result, $arr);
     $solved = $arr[1];
     preg_match('#<b>Rankpoints:</b>.*?<td>(.*?)</td>#', $result, $arr);
     $rankpoints = $arr[1];
     preg_match('#<b>Visited:</b>.*?<td>(.*?)</td>#', $result, $arr);
     $visited = $arr[1];
     preg_match('#<b>Time spent overall:</b>.*?<td>(.*?)</td>#', $result, $arr);
     $timeSpent = $arr[1];
     preg_match('#<b>Last online:</b>.*?<td>(.*?)</td>#', $result, $arr);
     $lastOnline = trim($arr[1]);
     preg_match('#<b>User\'s current status:</b>.*?<td>(.*?)</td>#', $result, $arr);
     if ($arr[1] == "offline") {
         $online = false;
     } else {
         $online = true;
     }
     $output = sprintf($this->CONFIG['text_status'], $nick, $rank, $solved, libString::end_s("challenge", $solved), $rankpoints);
     $output .= " ";
     $output .= sprintf($this->CONFIG['text_visit'], $nick, $this->CONFIG['domain'], $visited, libTime::secondsToString($timeSpent));
     if ($donated) {
         $output .= " ";
         $output .= sprintf($this->CONFIG['text_donate'], $nick, $donated);
     }
     $output .= " ";
     if ($online) {
         $output .= sprintf($this->CONFIG['text_online'], $nick, $domain);
     } else {
         $output .= sprintf($this->CONFIG['text_lastonline'], $nick, $lastOnline);
     }
     $this->sendOutput($output);
 }
Esempio n. 9
0
 function getStats($username, $html)
 {
     if (libString::startsWith('This user doesn\'t exist!', $html)) {
         return false;
     }
     preg_match('/^(.+?) has solved (\\d+) out of (\\d+) challenges.(?: He is at position (\\d+?) out of (\\d+)!)?$/', $html, $arr);
     $data = array('username' => $arr[1], 'challs_solved' => $arr[2], 'challs_total' => $arr[3], 'rank' => isset($arr[4]) ? $arr[4] : false, 'users_total' => isset($arr[5]) ? $arr[5] : false);
     if (!$data['rank']) {
         $this->statsText = '{username} solved {challs_solved} (of {challs_total}) challenges. There is no information available about his/her rank at {url}';
     }
     return $data;
 }
Esempio n. 10
0
 function getStats($username, $html)
 {
     $HTTP = new HTTP('www.wechall.net');
     $html = $HTTP->GET('/wechallchalls.php?username='******'timeout';
     }
     if (libString::startsWith('The user', $html)) {
         return false;
     }
     preg_match('/^(.+?) solved (\\d+?) of (\\d+?) Challenges with (\\d+?) of (\\d+?) possible points \\(([\\d\\.]+?)%\\). Rank for the site WeChall: (\\d+)$/', $html, $arr);
     $html = $HTTP->GET('/wechall.php?username=noother');
     if ($html === false) {
         return 'timeout';
     }
     preg_match('/is ranked \\d+? from (\\d+),/', $html, $arr2);
     $data = array('username' => $arr[1], 'challs_solved' => $arr[2], 'challs_total' => $arr[3], 'points' => $arr[4], 'points_total' => $arr[5], 'points_percent' => $arr[6], 'rank' => $arr[7], 'users_total' => $arr2[1]);
     return $data;
 }
Esempio n. 11
0
 private function checkSpam($text)
 {
     $links = libString::getUrls($text);
     foreach ($links as $link) {
         $parts = parse_url($link);
         if ($parts['host'] == 'tinyurl.com' && isset($parts['path']) && !isset($path['query']) && ctype_alnum(substr($parts['path'], 1))) {
             if ($this->checkSpam(libInternet::tinyURLDecode($link))) {
                 return true;
             }
         } else {
             preg_match('/[^\\.]+\\.[^\\.]+$/', $parts['host'], $arr);
             $domain = $arr[0];
             if (in_array($domain, self::$bannedHosts)) {
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 12
0
 private function printPlayerStats($nick, $global = false)
 {
     $serverchannel = $this->Server->id . ':' . $this->Channel->id;
     if ($global) {
         $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\t`nick`, SUM(`played`) AS `played`, SUM(`started`) AS `started`, SUM(`lost`) AS `lost`, SUM(`clicks`) AS `clicks`\n\t\t\t\tFROM\n\t\t\t\t\t`roulette`\n\t\t\t\tWHERE\n\t\t\t\t\t`nick` = '" . addslashes($nick) . "'\n\t\t\t";
     } else {
         $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\t`roulette`\n\t\t\t\tWHERE\n\t\t\t\t\t`serverchannel` ='" . addslashes($serverchannel) . "'\n\t\t\t\t\tAND `nick` = '" . addslashes($nick) . "'\n\t\t\t";
     }
     $data = $this->MySQL->fetchRow($sql);
     if (!$data) {
         $this->reply($nick . ' has never played roulette.');
         return;
     }
     $this->reply(sprintf('%s has played %s, won %d and lost %d. %s started %s, pulled the trigger %s and found the chamber empty on %s.', $data['nick'], libString::plural('game', $data['played']), $data['played'] - $data['lost'], $data['lost'], $data['nick'], libString::plural('game', $data['started']), libString::plural('time', $data['clicks'] + $data['lost']), libString::plural('occasion', $data['clicks'])));
 }
Esempio n. 13
0
 function showPlayerStats($nick, $channel = null)
 {
     $sql = "SELECT\n\t\t\t\t\tnick,\n\t\t\t\t\tSUM(played) played,\n\t\t\t\t\tSUM(won) won,\n\t\t\t\t\tSUM(lost) lost,\n\t\t\t\t\tSUM(trigger_pulled) trigger_pulled,\n\t\t\t\t\tSUM(clicks) clicks\n\t\t\t\tFROM\n\t\t\t\t\troulette_stats\n\t\t\t\tWHERE\n\t\t\t\t\tnick='" . addslashes($nick) . "'\n\t\t\t\t\t" . (isset($channel) ? " AND channel='" . addslashes($channel) . "'" : "") . "\n\t\t\t\tGROUP BY\n\t\t\t\t\tnick";
     $res = $this->MySQL->sendQuery($sql);
     if ($res['count'] == 0) {
         $this->sendOutput(sprintf("%s has never played roulette.", $nick));
         return;
     }
     $stats = $res['result'][0];
     $text = "%s has played %s %s, won %s and lost %s. %s pulled the trigger %s %s and found the chamber empty on %s %s.";
     $this->sendOutput(sprintf($text, $stats['nick'], $stats['played'], libString::end_s("game", $stats['played']), $stats['won'], $stats['lost'], $stats['nick'], $stats['trigger_pulled'], libString::end_s("time", $stats['trigger_pulled']), $stats['clicks'], libString::end_s("ocassion", $stats['clicks'])));
 }
Esempio n. 14
0
 function onChannelMessage()
 {
     $this->init();
     $chars = strlen($this->info['text']);
     $words = sizeof(explode(" ", $this->info['text']));
     $smilies = libString::countSmilies($this->info['text']);
     $sql = "UPDATE stats SET chars = chars+" . $chars . ", words=words+" . $words . ", smilies=smilies+" . $smilies . ", `lines`=`lines`+1 WHERE channel='" . $this->channel . "' AND nick='" . $this->nick . "'";
     $this->MySQL->sendQuery($sql);
 }
Esempio n. 15
0
 private function getSaveName($session_id)
 {
     $name = $this->sessions[$session_id]['game_id'] . ':' . $session_id;
     $file = libString::normalizeString($name) . '_' . crc32($name) . '.sav';
     return $file;
 }
Esempio n. 16
0
 private function printPlayerStats($nick)
 {
     $ranking = $this->getVar('ranking', array());
     $stats = false;
     if (preg_match('/[^0-9]/', $nick)) {
         foreach ($ranking as $index => $rank) {
             if ($rank['nick'] == $nick) {
                 $stats = $rank;
                 $stats['rank'] = $index + 1;
                 break;
             }
         }
         if ($stats === false) {
             $this->reply($nick . ' has never played dice.');
             return;
         }
     } else {
         if (isset($ranking[$nick - 1])) {
             $stats = $ranking[$nick - 1];
             $stats['rank'] = $nick;
         } else {
             $this->reply("No one is on that rank.");
             return;
         }
     }
     $text = sprintf("%s has played %s, won %d and lost %d. %s is on rank %d of %d. %s's last game was %s ago.", $stats['nick'], libString::plural('game', $stats['played']), $stats['won'], $stats['played'] - $stats['won'], $stats['nick'], $stats['rank'], sizeof($ranking), $stats['nick'], libTime::secondsToString(time() - $stats['last_played']));
     if ($stats['rank'] != 1) {
         $text .= sprintf(" %s needs to win %s to rankup.", $stats['nick'], libString::plural('more game', $ranking[$stats['rank'] - 2]['won'] - $stats['won'] + 1));
     }
     $this->reply($text);
 }
Esempio n. 17
0
 public final function onPrivmsg()
 {
     $this->onMessage();
     $isQuery = $this->data['isQuery'];
     unset($this->data['isQuery']);
     if ($isQuery) {
         $this->onQuery();
     } else {
         $this->onChannelMessage();
     }
     $this->data['isQuery'] = $isQuery;
     foreach ($this->triggers as $trigger) {
         $trigger_len = strlen($trigger);
         if (libString::startsWith($trigger, $this->data['text'])) {
             if ($trigger_len == strlen($this->data['text'])) {
                 $this->data['trigger'] = $trigger;
                 unset($this->data['text']);
                 $this->isTriggered();
                 break;
             } elseif ($this->data['text'][$trigger_len] == ' ') {
                 $this->data['trigger'] = $trigger;
                 $this->data['text'] = substr($this->data['text'], $trigger_len + 1);
                 $this->isTriggered();
                 break;
             }
         }
     }
 }
Esempio n. 18
0
 function addWord($word)
 {
     $old_word = $word;
     $word = libString::convertUmlaute($word);
     $word = libString::capitalize($word);
     if (preg_match("/[^a-zA-Z]/", $word)) {
         $this->sendOutput("Your word must contain only letters.");
         return;
     }
     $sql = "SELECT id FROM hangman WHERE word='" . addslashes($word) . "'";
     $res = $this->MySQL->sendQuery($sql);
     if ($res['count'] != 0) {
         $this->sendOutput("This word is already in the database.");
         return;
     }
     $google_results = libInternet::googleResults($old_word);
     if ($google_results < $this->CONFIG['google_min']) {
         //$output = sprintf($this->CONFIG['googlemin_text'],
         //					$this->CONFIG['google_min']
         //				 );
         $this->sendOutput($this->CONFIG['googlemin_text']);
         return;
     }
     $blacklist = array("add", "del", "stats", "start", "stop");
     if (array_search(strtolower($word), $blacklist) !== false) {
         $this->sendOutput("Stuuuuupiiid!");
         return;
     }
     $sql = "INSERT INTO\n\t\t\t\t\thangman\n\t\t\t\t\t(word, author, created)\n\t\t\t\tVALUES (\n\t\t\t\t\t'" . addslashes($word) . "',\n\t\t\t\t\t'" . addslashes($this->info['nick']) . "',\n\t\t\t\t\tNOW()\n\t\t\t\t)";
     $this->MySQL->sendQuery($sql);
     $this->sendOutput("Word '" . $word . "' has been added to the database.");
     return;
 }
Esempio n. 19
0
 private function getData($irc_msg)
 {
     $parsed = $this->parseIRCMessage($irc_msg);
     if (!$parsed) {
         return false;
     }
     $data['command'] = $parsed['command'];
     $data['raw'] = $irc_msg;
     switch ($data['command']) {
         case '001':
             // First message sent by an IRC server after successful auth
             $data['server'] = $parsed['servername'];
             $data['my_nick'] = $parsed['params'][0];
             $data['welcome_message'] = $parsed['params'][1];
             $this->Me = new IRC_User($data['my_nick'], $this);
             $this->users[$this->Me->id] = $this->Me;
             $this->sendWhois($this->Me->nick);
             /*
             $this->NickServ = new IRC_User('NickServ', $this);
             $this->users[$this->NickServ->id] = $this->NickServ;
             
             
             if(false !== $var = $this->getVar('nickserv_identify_command')) {
             	$this->nickservIdentifyCommand = $var;
             } else {
             	$this->NickServ->privmsg('ACC '.$this->Me->nick);
             	$this->NickServ->privmsg('STATUS '.$this->Me->nick);
             }
             */
             break;
         case '005':
             // ISUPPORT
             for ($i = 1; $i < sizeof($parsed['params']) - 1; $i++) {
                 $tmp = explode('=', $parsed['params'][$i]);
                 $name = strtoupper($tmp[0]);
                 if (sizeof($tmp) == 2) {
                     $this->supports[$name] = $tmp[1];
                 } else {
                     $this->supports[$name] = true;
                 }
             }
             break;
         case '311':
             // WHOIS reply
             $User = $this->getUser($parsed['params'][1]);
             $User->user = $parsed['params'][2];
             $User->host = $parsed['params'][3];
             $User->realname = $parsed['params'][5];
             $User->banmask = $User->nick . '!' . $User->user . '@' . $User->host;
             $data['User'] = $User;
             break;
         case '315':
             // End of WHO list (Channel join complete)
             $data['Channel'] = $this->getChannel($parsed['params'][1]);
             break;
         case '324':
             // Server MODE reply
             $Channel = $this->getChannel($parsed['params'][1]);
             $modes = $parsed['params'][2];
             $Channel->modes = array();
             for ($i = 1; $i < strlen($modes); $i++) {
                 $Channel->modes[$modes[$i]] = true;
             }
             break;
         case '332':
             // Server "get" TOPIC reply (Also on channel join)
             $Channel = $this->getChannel($parsed['params'][1]);
             $Channel->topic = $parsed['params'][2];
             break;
         case '352':
             // Server WHO reply
             $Channel = $this->getChannel($parsed['params'][1]);
             $User = $this->getUser($parsed['params'][5]);
             $User->user = $parsed['params'][2];
             $User->host = $parsed['params'][3];
             $User->realname = substr($parsed['params'][7], 2);
             $User->banmask = $User->nick . '!' . $User->user . '@' . $User->host;
             if (!isset($Channel->users[$User->id])) {
                 $Channel->addUser($User);
             }
             $modes = $parsed['params'][6];
             $mode = '';
             // Get the most significant mode, ignoring * (IRC OP) and the first 'H' char which isn't a mode
             for ($i = 1; $i < strlen($modes); $i++) {
                 if ($modes[$i] != '*') {
                     $mode = $modes[$i];
                     break;
                 }
             }
             $User->modes[$Channel->id] = $mode;
             break;
         case '353':
             // Server NAMES reply
             $Channel = $this->getChannel($parsed['params'][2]);
             $users = explode(' ', $parsed['params'][3]);
             foreach ($users as $user) {
                 preg_match('/^([+@%])?(.+)$/', $user, $arr);
                 $mode = $arr[1];
                 $nick = $arr[2];
                 $User = $this->getUser($nick);
                 $User->modes[$Channel->id] = $mode;
             }
             break;
         case '366':
             // Server End of NAMES list
             $data['Channel'] = $this->getChannel($parsed['params'][1]);
             break;
         case '433':
             // Sent on connect if nickname is already in use
             $data['nick'] = $parsed['params'][1];
             break;
         case 'ERROR':
             // Sent when the server decides to close our connection
             $data['text'] = $parsed['params'][0];
             if (libString::endsWith('(Excess Flood)', $data['text'])) {
                 $this->onFlood();
                 $this->connectCooldown['cooldown'] = 20;
                 $this->connectCooldown['last_connect'] = time();
             } elseif (libString::endsWith('throttled', $data['text'])) {
                 $this->connectCooldown['cooldown'] = 60;
                 $this->connectCooldown['last_connect'] = time();
             }
             fclose($this->socket);
             $this->socket = false;
             break;
         case 'JOIN':
             // Sent when the bot or a user joins a channel
             $User = $this->getUser($parsed['nick']);
             $User->banmask = $parsed['banmask'];
             $User->user = $parsed['user'];
             $User->host = $parsed['host'];
             $User->mode = '';
             $Channel = $this->getChannel($parsed['params'][0]);
             $Channel->addUser($User);
             if ($User->id != $this->Me->id) {
                 $data['User'] = $User;
                 $data['Channel'] = $Channel;
             }
             break;
         case 'KICK':
             // Sent when a user gets kicked from a channel
             $User = $this->getUser($parsed['nick']);
             $Channel = $this->getChannel($parsed['params'][0]);
             $Victim = $this->getUser($parsed['params'][1]);
             $User->mode = $User->modes[$Channel->id];
             $Victim->mode = $Victim->modes[$Channel->id];
             $kick_message = $parsed['params'][2];
             if ($Victim->id == $this->Me->id) {
                 $Channel->remove();
             } else {
                 $data['Victim'] = $Victim;
                 $Channel->removeUser($Victim);
             }
             $data['User'] = $User;
             $data['Channel'] = $Channel;
             $data['kick_message'] = $kick_message;
             break;
         case 'MODE':
             // TODO: Fix this up - It's not really correct
             if (sizeof($parsed['params']) >= 3) {
                 // Sent if a mode for a user in a channel is changed
                 // TODO: Many modes with 1 command
                 $User = $this->getUser($parsed['nick']);
                 $Victim = $this->getUser($parsed['params'][2]);
                 $Channel = $this->getChannel($parsed['params'][0]);
                 $Channel->sendNames();
                 $data['User'] = $User;
                 $data['Channel'] = $Channel;
                 $data['Victim'] = $Victim;
                 $data['mode'] = $parsed['params'][1];
             } else {
                 if (isset($this->channels[$parsed['params'][0]])) {
                     // Sent when the channel modes are changed
                     $Channel = $this->getChannel($parsed['params'][0]);
                     $modes = $parsed['params'][1];
                     $action = '';
                     for ($i = 0; $i < strlen($modes); $i++) {
                         if ($modes[$i] == '+') {
                             $action = 'add';
                         } elseif ($modes[$i] == '-') {
                             $action = 'rm';
                         } else {
                             switch ($action) {
                                 case 'add':
                                     $Channel->modes[$modes[$i]] = true;
                                     break;
                                 case 'rm':
                                     unset($Channel->modes[$modes[$i]]);
                                     break;
                             }
                         }
                     }
                 } else {
                     // TODO: Sent on connect to show us our user modes on the server
                 }
             }
             break;
         case 'NICK':
             // Sent when a user or the bot changes nick
             $User = $this->getUser($parsed['nick']);
             if ($User->id != $this->Me->id) {
                 $data['User'] = $User;
             }
             $data['old_nick'] = $User->nick;
             $User->changeNick($parsed['params'][0]);
             break;
         case 'NOTICE':
             if (isset($parsed['nick'])) {
                 // Sent when a user sends a notice
                 $User = $this->getUser($parsed['nick']);
                 $text = $parsed['params'][1];
                 /*
                 if($User->id == 'nickserv') {
                 	// Sent when nickserv sends a notice
                 	$tmp = explode(' ', $parsed['params'][1]);
                 	if($tmp[0] == $this->Me->nick && $tmp[1] == 'ACC') {
                 		$this->nickservIdentifyCommand = 'ACC';
                 		$this->saveVar('nickserv_identify_command', 'ACC');
                 	} elseif($tmp[0] == 'STATUS' && $tmp[1] == $this->Me->nick) {
                 		$this->nickservIdentifyCommand = 'STATUS';
                 		$this->saveVar('nickserv_identify_command', 'STATUS');
                 	}
                 	
                 	$id = false;
                 	if($tmp[1] == 'ACC')        $id = strtolower($tmp[0]);
                 	elseif($tmp[0] == 'STATUS') $id = strtolower($tmp[1]);
                 	if($id && isset($this->users[$id])) $this->users[$id]->nickservStatus = $tmp[2];
                 }
                 */
                 $data['User'] = $User;
                 $data['text'] = $text;
             } else {
                 if (isset($parsed['servername'])) {
                     $data['servername'] = $parsed['servername'];
                 } else {
                     $parsed['servername'] = false;
                 }
                 // $data['target'] = $parsed['params'][0];
                 $data['message'] = $parsed['params'][1];
                 if ($this->floodCooldown === false && preg_match('/Message to .+? throttled/', $data['message'])) {
                     $this->onFlood();
                 }
             }
             break;
         case 'PART':
             // Sent when a user or the bot parts a channel
             $User = $this->getUser($parsed['nick']);
             $Channel = $this->getChannel($parsed['params'][0]);
             $User->mode = $User->modes[$Channel->id];
             unset($User->modes[$Channel->id]);
             if ($User->id == $this->Me->id) {
                 $Channel->remove();
             } else {
                 $Channel->removeUser($User);
                 $data['User'] = $User;
             }
             $data['Channel'] = $Channel;
             if (isset($parsed['params'][1])) {
                 $data['part_message'] = $parsed['params'][1];
             }
             break;
         case 'PING':
             // Ping message sent from the server to see if we're still alive
             $data['challenge'] = $parsed['params'][0];
             $this->sendPong($data['challenge']);
             break;
         case 'PONG':
             // Message sent by the server after we issued a PING
             $data['server'] = $parsed['params'][0];
             $data['challenge'] = $parsed['params'][1];
             $this->waitingForPong = false;
             break;
         case 'PRIVMSG':
             // Sent when a user sends a message to a channel where the bot is in, or to the bot itself
             if (!isset($this->users[strtolower($parsed['nick'])])) {
                 $this->sendWhois($parsed['nick']);
             }
             $data['User'] = $this->getUser($parsed['nick']);
             // TODO: fail with todo at parseIRCMessage
             $data['text'] = isset($parsed['params'][1]) ? $parsed['params'][1] : '';
             if (strtolower($parsed['params'][0]) == $this->Me->id) {
                 $data['isQuery'] = true;
                 $data['User']->mode = '';
             } else {
                 $data['isQuery'] = false;
                 $data['Channel'] = $this->getChannel($parsed['params'][0]);
                 $data['User']->mode = $data['User']->modes[$data['Channel']->id];
             }
             if ($data['text'][0] == "") {
                 $data['text'] = substr($data['text'], 1);
                 if (substr($data['text'], -1) == "") {
                     $data['text'] = substr($data['text'], 0, -1);
                 }
                 $data['command'] = 'vCTCP';
                 $tmp = explode(' ', $data['text'], 2);
                 $data['ctcp_command'] = strtoupper($tmp[0]);
                 if (isset($tmp[1])) {
                     $data['text'] = $tmp[1];
                 } else {
                     $data['text'] = '';
                 }
                 if ($data['ctcp_command'] == 'ACTION') {
                     unset($data['ctcp_command']);
                     $data['command'] = 'vACTION';
                 }
             }
             break;
         case 'TOPIC':
             // Sent when a user changes the topic
             $User = $this->getUser($parsed['nick']);
             $Channel = $this->getChannel($parsed['params'][0]);
             $Channel->topic = $parsed['params'][1];
             $data['User'] = $User;
             $data['Channel'] = $Channel;
             $data['topic'] = $parsed['params'][1];
             break;
         case 'QUIT':
             // Sent when a user quits the server
             $User = $this->getUser($parsed['nick']);
             $User->remove();
             $data['User'] = $User;
             // TODO: fail with todo at parseIRCMessage
             if (isset($parsed['params'][0])) {
                 $data['quit_message'] = $parsed['params'][0];
             } else {
                 $data['quit_message'] = '';
             }
             break;
     }
     return $data;
 }
Esempio n. 20
0
 private function getInfo()
 {
     $info = array();
     if (isset($this->splittedMessage['params'][1])) {
         $info['text'] = $this->splittedMessage['params'][1];
         if (!libString::isUTF8($info['text'])) {
             $info['text'] = utf8_encode($info['text']);
         }
         $info['text'] = trim($info['text']);
     }
     if (strtolower($this->splittedMessage['params'][0]) == strtolower($this->nick)) {
         $info['isQuery'] = true;
         $info['target'] = $this->splittedMessage['nick'];
     } else {
         $info['isQuery'] = false;
         $info['target'] = $this->splittedMessage['params'][0];
         $info['channel'] = $info['target'];
     }
     $info['prefix'] = $this->splittedMessage['prefix'];
     $info['host'] = $this->splittedMessage['host'];
     $info['nick'] = $this->splittedMessage['nick'];
     $info['user'] = $this->splittedMessage['user'];
     $info['nick'] = $this->splittedMessage['nick'];
     return $info;
 }
Esempio n. 21
0
 function sendMail($to, $subject, $template, $vars, $attachment = null)
 {
     require_once $this->CONFIG['phpmailer_path'];
     if (!file_exists('mail_templates/' . $template . '_plain.tpl') || !file_exists('mail_templates/' . $template . '_html.tpl')) {
         return false;
     }
     $smarty = $this->spawnSmarty();
     $smarty->template_dir = 'mail_templates';
     $smarty->compile_dir = 'smarty/templates_c/mail_templates';
     $smarty->cache_dir = 'smarty/cache/mail_templates';
     if (!is_dir('smarty/templates_c/mail_templates')) {
         mkdir('smarty/templates_c/mail_templates');
     }
     if (!is_dir('smarty/cache/mail_templates')) {
         mkdir('smarty/cache/mail_templates');
     }
     $check = false;
     foreach ($vars as $key => $value) {
         $smarty->assign($key, $value);
         if ($key == 'alt_content') {
             $check = true;
         }
     }
     if (!$check) {
         $vars['alt_content'] = strip_tags($vars['content']);
     }
     $smarty->assign('alt_content', $vars['alt_content']);
     $mail = new PHPMailer();
     $mail->CharSet = 'utf-8';
     $mail->From = $this->CONFIG['mail_from'];
     $mail->FromName = $this->CONFIG['mail_from_name'];
     $mail->AddAddress($to);
     if (isset($vars['reply-to'])) {
         list($reply_to) = explode("\n", $vars['reply-to']);
         $mail->AddReplyTo($reply_to);
     }
     if (isset($vars['bcc'])) {
         if (is_array($vars['bcc'])) {
             foreach ($vars['bcc'] as $bcc) {
                 $mail->AddBCC($bcc);
             }
         } else {
             list($bcc) = explode("\n", $vars['bcc']);
             $mail->AddBCC($bcc);
         }
     }
     $mail->isHTML(true);
     $mail->Subject = !libString::isUTF8($subject) ? utf8_encode($subject) : $subject;
     if (isset($attachment)) {
         $mail->addAttachment($attachment);
     }
     $body = $smarty->fetch($template . '_html.tpl');
     $alt_body = $smarty->fetch($template . '_plain.tpl');
     $mail->Body = !libString::isUTF8($body) ? utf8_encode($body) : $body;
     $mail->AltBody = !libString::isUTF8($alt_body) ? utf8_encode($alt_body) : $alt_body;
     if (!$mail->Send()) {
         return false;
     }
     return true;
 }
Esempio n. 22
0
 function trySolution($nick, $solution)
 {
     $solution = libString::convertUmlaute($solution);
     if (strtolower($solution) != strtolower($this->solution)) {
         if ($this->subLife() === "lose") {
             return;
         }
         $this->IRC->sendOutput("Sorry " . $nick . ", that was not the correct solution.");
         $this->sendGrid();
         $this->sendLivesLeft();
         return false;
     }
     $this->winGame($nick);
     return true;
 }