PageRenderTime 55ms CodeModel.GetById 4ms app.highlight 11ms RepoModel.GetById 21ms app.codeStats 1ms

/lizardbot.php

https://github.com/revi/LizardBot-PHP
PHP | 2209 lines | 2004 code | 9 blank | 196 comment | 293 complexity | 16f1141174a1d719c4548b25205b53c5 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1#!/usr/bin/php
   2<?php
   3error_reporting(E_ALL & ~E_NOTICE);
   4$cmdcount = 0;
   5$pingcount = 0;
   6$ctcpcount = 0;
   7$aicount = 0;
   8$insultcount = 0;
   9$fishcount = 0;
  10echo "Determining what configuration file we should use...\r\n";
  11$dir = $_SERVER['argv'][1];
  12$cfg = FALSE;
  13if(!$dir) {
  14	$dir = 'lizardbot.conf.php';
  15	$cfg = TRUE; 
  16}
  17if($cfg) {
  18	echo "{$c_green}Will use the default configuration file, {$dir}{$c_n}\r\n";
  19} else {
  20	echo "{$c_green}Will use the user-specified config file {$dir}{$c_n}\r\n";
  21}
  22echo "Loading essential config files...\r\n";
  23$rehash = TRUE;
  24require("default.conf.php");
  25require($dir);
  26$rehash = FALSE;
  27
  28//Load hasPriv function
  29function hasPriv($priv) {
  30	global $privgroups, $users, $d, $setIsOnWindows, $setUsePCREs;
  31	$parsed = $d[0];
  32	foreach( $users as $user => $group ) {
  33		if($setUsePCREs || $setIsOnWindows) {
  34			if($user == "*!*@*") continue;
  35			if( preg_match( $user, $parsed/*['n!u@h']*/ ) ) {
  36				if( isset( $privgroups[$group][$priv] ) ) {
  37					return $privgroups[$group][$priv];
  38				} else {
  39					return 0;
  40				}
  41			}
  42		} elseif (!$setUsePCREs && !$setIsOnWindows) {
  43			if( fnmatch( $user, $parsed/*['n!u@h']*/ ) ) {
  44				if( isset( $privgroups[$group][$priv] ) ) {
  45					return $privgroups[$group][$priv];
  46				} else {
  47					return 0;
  48				}
  49			}
  50		}
  51	}
  52	$d[0] = $parsed;
  53}
  54
  55echo "OK!\r\n";
  56if(!$setIsOnWindows) {
  57	$c_n = chr(27) . "[0m";
  58	$c_dark = chr(27) . "[01;90m";
  59	$c_red = chr(27) . "[01;91m";
  60	$c_green = chr(27) . "[01;92m";
  61	$c_yellow = chr(27) . "[01;93m";
  62	$c_blue = chr(27) . "[01;94m";
  63	$c_pink = chr(27) . "[01;95m";
  64	$c_cyan = chr(27) . "[01;96m";
  65	$c_bold = chr(27) . "[01;1m";
  66	$c_ul = chr(27) . "[01;4m";
  67	$c_b_dark = chr(27) . "[01;5m";
  68	$c_b_light = chr(27) . "[01;7m";
  69	$c_b_red = chr(27) . "[01;41m";
  70	$c_b_green = chr(27) . "[01;42m";
  71	$c_b_yellow = chr(27) . "[01;43m";
  72	$c_b_blue = chr(27) . "[01;44m";
  73	$c_b_pink = chr(27) . "[01;45m";
  74	$c_b_cyan = chr(27) . "[01;46m";
  75	$c_b_light_bold = chr(27) . "[01;47m";
  76}
  77echo $c_green;
  78?>
  79*******************************************************************************
  80 _      _______  _________  __________   _______    ____
  81| |    |__   __||_______/ /| _______  | | |___| |  | || \
  82| |       | |          / / | |      | | | |___| |  | | | |
  83| |       | |         / /  | |______| | | |___|_|  | | | | BOT
  84| |___  __| |__   ___/ /__ | |______| | | |  \  \  | |_| |
  85|_____||_______| |________||_|      |_| |_|   \__\ |____/
  86
  87           -=- http://fastlizard4.org/wiki/LizardBot -=-
  88
  89LizardBot for PHP: IRC bot developed by FastLizard4 (who else?) and the LizardBot Development Team
  90Version 7.3.0.0b (major.minor.build.revision) BETA
  91Licensed under the General Public License 2.0 (GPL) or later at your option
  92For licensing details, contact me or read this page:
  93http://creativecommons.org/licenses/GPL/2.0/
  94*Report bugs to BugZilla at http://fastlizard4.org/bugzilla/
  95*You may also report issues or submit your own patches at GitHub:
  96https://github.com/FastLizard4/LizardBot-PHP
  97
  98LICENSING DETAILS:
  99LizardBot for PHP (IRC bot) written by FastLizard4 and the LizardBot Development Team
 100Copyright (C) 2008-2013 FastLizard4 and the LizardBot Development Team
 101
 102This program is free software; you can redistribute it and/or
 103modify it under the terms of the GNU General Public License
 104as published by the Free Software Foundation; either version 2
 105of the License, or (at your option) any later version.
 106
 107This program is distributed in the hope that it will be useful,
 108but WITHOUT ANY WARRANTY; without even the implied warranty of
 109MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 110GNU General Public License for more details.
 111
 112A human-readable version of the complete license is available at
 113http://creativecommons.org/licenses/GPL/2.0/
 114The full text of the license can be found here:
 115http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 116
 117PandoraBot extension courtesy of Ttech (PHP-5 OOP)
 118*************************************************************************************
 119<?php
 120//Check for updates
 121echo "{$c_yellow}Checking for updates...\r\n";
 122$version = "7.3.0.0b";
 123$upfp = @fopen('http://fastlizard4.org/w/index.php?title=LizardBot/Latest&action=raw', 'r');
 124$data = @fgets($upfp);
 125@fclose($upfp);
 126if(!$data) {
 127echo "{$_bold}Check for updates failed!{$c_n}\r\n";
 128}
 129if($data == $version) {
 130	echo "{$c_green}>>>>You have the stable latest version, {$version}<<<<{$c_n}\r\n";
 131} else {
 132	echo "{$c_red}>>>>You do not have the latest version, {$data}<<<<{$c_n}\r\n";
 133	echo "{$c_red}This could mean that you're running an older version, or a newer\r\n";
 134	echo "not yet stable version....{$c_n}\r\n";
 135}
 136/**********************************************
 137BEGIN PANDORABOT
 138**********************************************/
 139echo "Loading pandorabot extension...\r\n";
 140// *PHP 5* ONLY
 141
 142class pandorabot {
 143
 144    public $botid;
 145    public $_Pipe; // This will be our cURL handle in a bit
 146    public $timout = 50;
 147    public $default_response = "Probably"; // Use the function to set this.
 148    private $path_url = "http://www.pandorabots.com/pandora/talk?botid="; // So we can easily change url if needed
 149//    private $path_url = "http://localhost/~fastlizard4/blank.html";
 150
 151
 152
 153/* Sanity Checking Function */
 154    public function pandorabot($botid=""){
 155        /* Run all init and such now. */
 156        $botid = trim($botid);
 157        if(isset($botid)){
 158            // Init Curl
 159            $this->_Pipe = curl_init();
 160            curl_setopt($this->_Pipe, CURLOPT_URL, $this->path_url.$botid);
 161            curl_setopt($this->_Pipe, CURLOPT_POST, 1);
 162            curl_setopt($this->_Pipe, CURLOPT_RETURNTRANSFER, 1);
 163        }
 164    }
 165
 166
 167    public function default_response($response=""){
 168        /* Check to see if $response is set otherwise we return the default */
 169        if(isset($response)){
 170            // Check to make sure new response is actually there
 171            if(!$this->sanitize($response) == FALSE){
 172                $this->default_response = $this->sanitize($response); // Set response
 173            }
 174        } else {
 175            // No new response set, return the already set one.
 176            return $this->default_response;
 177        }
 178    }
 179
 180    public function say($user_input){
 181        $name = "input"; // Used to submit the form post
 182        $input = $this->sanitize($user_input);
 183        // Stupid debug stuff
 184    //    echo $this->timeout."<br />";
 185        curl_setopt($this->_Pipe, CURLOPT_TIMEOUT, $this->timout);
 186        curl_setopt ($this->_Pipe, CURLOPT_POSTFIELDS, "Name=$name&input=$input");
 187        curl_setopt ($this->_Pipe, CURLOPT_FOLLOWLOCATION, 1);
 188        $reply = curl_exec($this->_Pipe);
 189        if(isset($reply) && !preg_match('/^\s*$/', $reply)){
 190            return $this->get_say($reply);
 191        } elseif(!isset($reply) || preg_match('/^\s*$/', $reply)) {
 192            return $this->default_response;
 193	}
 194        curl_close($this->_Pipe);
 195    }
 196
 197    public function set_timeout($int){
 198        if(!is_int($int)){
 199            $this->timeout = 60;
 200            return FALSE;
 201        } else {
 202            $this->timeout = $int;
 203            return TRUE;
 204        }
 205    }
 206
 207    private function sanitize($string){
 208        $string = trim(str_replace("\n", "", stripslashes(html_entity_decode($string))));
 209            if(!empty($string)){
 210                return $string;
 211            } else { // Nothing is returned, return false
 212                return FALSE;
 213            }
 214    }
 215
 216    private function get_say($input, $tag='font'){
 217        // Do a little regex to get the bot reply
 218        $pattern = "#<$tag color=\"\\w+\">(.*?)</$tag>#";
 219        $var = preg_match($pattern, $input, $matches);
 220        $result = $this->sanitize($matches[1]); // Get outout and send for validation
 221        /* Simple Sanity Check  - Null */
 222            if($result == FALSE OR empty($result)){
 223                return $this->default_response();
 224            } else {
 225                return $result; // Return valid string.
 226            }
 227    }
 228
 229}
 230echo "Pandorabot class loaded!\r\n";
 231echo "Preparing fishb0t module...\r\n";
 232$fishCresponses = array
 233	(
 234                    '/hampster/i'            => '%n: There is no \'p\' in hamster you retard.',
 235                    '/vinegar.*aftershock/i'    => 'Ah, a true connoisseur!',
 236                    '/aftershock.*vinegar/i'    => 'Ah, a true connoisseur!',
 237                    '/^some people are being fangoriously devoured by a gelatinous monster$/i'
 238                                    => 'Hillary\'s legs are being digested.',
 239                    '/^ag$/i'            => 'Ag, ag ag ag ag ag AG AG AG!',
 240                    '/^(fishbot|%f) owns$/i'        => 'Aye, I do.',
 241                    '/vinegar/i'            => 'Nope, too sober for vinegar.  Try later.',
 242                    '/martian/i'            => 'Don\'t run! We are your friends!',
 243                    '/^just then, he fell into the sea$/i'
 244                                    => 'Ooops!',
 245                    '/aftershock/i'            => 'mmmm, Aftershock.',
 246                    '/^why are you here\?$/i'    => 'Same reason.  I love candy.',
 247                    '/^spoon$/i'            => 'There is no spoon.',
 248                    '/^(bounce|wertle)$/i'        => 'moo',
 249                    '/^crack$/i'            => 'Doh, there goes another bench!',
 250                    '/^you can\'t just pick people at random!$/i'
 251                                    => 'I can do anything I like, %n, I\'m eccentric!  Rrarrrrrgh!  Go!',
 252                    '/^flibble$/i'            => 'plob',
 253                    '/(the fishbot has created splidge|fishbot created splidge)/i'
 254                                    => 'omg no! Think I could show my face around here if I was responsible for THAT?',
 255                    '/^now there\'s more than one of them\?$/i'
 256                                    => 'A lot more.',
 257                    '/^i want everything$/i'    => 'Would that include a bullet from this gun?',
 258                    '/we are getting aggravated/i'    => 'Yes, we are.',
 259                    '/^how old are you, (fishbot|%f)\?$/i'
 260                                    => chr(1).'ACTION is older than time itself!'.chr(1),
 261                    '/^atlantis$/i'            => 'Beware the underwater headquarters of the trout and their bass henchmen. From there they plan their attacks on other continents.',
 262                    '/^oh god$/i'            => 'fishbot will suffice.',
 263                    '/^(fishbot|%f)$/i'            => 'Yes?',
 264                    '/^what is the matrix\?$/i'    => 'No-one can be told what the matrix is.  You have to see it for yourself.',
 265                    '/^what do you need\?$/i'    => 'Guns. Lots of guns.',
 266                    '/^i know kungfu$/i'        => 'Show me.',
 267                    '/^cake$/i'            => 'fish',
 268                    '/^trout go m[o0][o0]$/i'    => 'Aye, that\'s cos they\'re fish.',
 269                    '/^kangaroo$/i'            => 'The kangaroo is a four winged stinging insect.',
 270                    '/^sea bass$/i'            => 'Beware of the mutant sea bass and their laser cannons!',
 271                    '/^trout$/i'            => 'Trout are freshwater fish and have underwater weapons.',
 272                    '/has returned from playing counterstrike/i'
 273                                    => 'like we care fs :(',
 274                    '/^where are we\?$/i'        => 'Last time I looked, we were in %c.',
 275                    '/^where do you want to go today\?$/i'
 276                                    => 'anywhere but redmond :(.',
 277                    '/^fish go m[o0][o0]$/i'    => chr(1).'ACTION notes that %n is truly enlightened.'.chr(1),
 278                    '/^(.*) go m[o0][o0]$/i'    => '%n: only when they are impersonating fish.',
 279                    '/^fish go (.+)$/i'    => '%n LIES! Fish don\'t go %1! fish go m00!',
 280                    '/^you know who else (.*)$/i'    => '%n: YA MUM!',
 281                    '/^if there\'s one thing i know for sure, it\'s that fish don\'t m00\.?$/i'
 282                                    => '%n: HERETIC! UNBELIEVER!',
 283                    '/^(fishbot|%f): muahahaha\. ph33r the dark side\. :\)$/i'
 284                                    => '%n: You smell :P',
 285                    '/^ammuu\?$/i'            => '%n: fish go m00 oh yes they do!',
 286                    '/^fish$/i'            => '%n: fish go m00!',
 287                    '/^snake$/i'            => 'Ah snake a snake! Snake, a snake! Ooooh, it\'s a snake!',
 288                    '/^carrots handbags cheese$/i'    => 'toilets russians planets hamsters weddings poets stalin KUALA LUMPUR! pygmies budgies KUALA LUMPUR!',
 289                    '/sledgehammer/i'        => 'sledgehammers go quack!',
 290                    '/^badger badger badger badger badger badger badger badger badger badger badger badger$/i'
 291                                    => 'mushroom mushroom!',
 292                    '/^moo\?$/i'            => 'To moo, or not to moo, that is the question. Whether \'tis nobler in the mind to suffer the slings and arrows of outrageous fish...',
 293                    '/^herring$/i'            => 'herring(n): Useful device for chopping down tall trees. Also moos (see fish).',
 294                    '/www\.outwar\.com/i'        => 'would you please GO AWAY with that outwar rubbish!',
 295                    '/^god$/i'            => 'Sometimes the garbage disposal gods demand a spoon.',
 296                    '/stupid bot[!?.]*$/i' => '%n: Stupid human.',
 297                    '/fail bot[!?.]*$/i' => '%n: Fail human.',
 298		    '/good bot[!?.]*$/i' => chr(1).'ACTION purrs at %n'.chr(1),
 299		    '/^I am the Doctor,? and you are the Daleks!?$/i' => 'WE ARE THE DALEKS!! Exterminate! EXTEEERRRRMIIINAAAATE!',
 300		    '/^ping$/i' => 'pong',
 301		    '/^pong$/i' => 'pang',
 302		    '/^pang$/i' => 'pung',
 303		    '/^pung$/i' => 'derp'
 304                );
 305            
 306            $fishAresponses = array
 307                (
 308                    '/hampster/i'            => '%n: There is no \'p\' in hamster you retard.',
 309                    '/^feeds (fishbot|%f) hundreds and thousands$/i'
 310                                    => 'MEDI.. er.. FISHBOT',
 311                    '/(vinegar.*aftershock|aftershock.*vinegar)/i'
 312                                    => 'Ah, a true connoisseur!',
 313                    '/vinegar/i'            => 'Nope, too sober for vinegar.  Try later.',
 314                    '/martians/i'            => 'Don\'t run! We are your friends!',
 315                    '/aftershock/i'            => 'mmmm, Aftershock.',
 316                    '/(the fishbot has created splidge|fishbot created splidge)/i'
 317                                    => 'omg no! Think I could show my face around here if I was responsible for THAT?',
 318                    '/we are getting aggravated/i'    => 'Yes, we are.',
 319                    '/^strokes (fishbot|%f)$/i'        => chr(1).'ACTION m00s loudly at %n.'.chr(1),
 320                    '/^slaps (.*) around a bit with a large trout$/i'
 321                                    => 'trouted!',
 322                    '/has returned from playing counterstrike/i'
 323                                    => 'like we care fs :(',
 324                    '/^fish go m[o0][o0]$/i'    => chr(1).'ACTION notes that %n is truly enlightened.'.chr(1),
 325                    '/^(.*) go m[o0][o0]$/i'    => '%n: only when they are impersonating fish.',
 326                    '/^fish go (.+)$/i'    => '%n LIES! Fish don\'t go %1! fish go m00!',
 327                    '/^you know who else (.*)$/i'    => '%n: YA MUM!',
 328                    '/^thinks happy thoughts about pretty (.*)$/i'
 329                                    => chr(1).'ACTION has plenty of pretty %1. Would you like one %n?'.chr(1),
 330                    '/^snaffles a (.*) off (fishbot|%f).?$/i'
 331                                    => ':(',
 332                    '/stupid bot[!?.]*$/i' => '%n: Stupid human.',
 333                    '/fail bot[!?.]*$/i' => '%n: Fail human.',
 334                    '/good bot[!?.]*$/i' => chr(1).'ACTION purrs at %n'.chr(1),
 335                    '/^ping$/i' => 'pong',
 336                    '/^pong$/i' => 'pang',
 337                    '/^pang$/i' => 'pung',
 338                    '/^pung$/i' => 'derp'
 339                );
 340echo "Fishb0t module readied!  FISH GO M00 OH YES THEY DO! [citation needed]\r\n";
 341/**********************************************
 342END PANDORABOT
 343**********************************************/
 344$rehash = FALSE;
 345function tr(&$var) {
 346	$var = trim($var);
 347}
 348if($setIsOnWindows) {
 349	echo "Will skip signal handlers, we're running on Windows...\r\n";
 350} else {
 351	echo "Preparing signal handlers...\r\n";
 352	declare(ticks = 1);
 353	function SIGHUP() {
 354		global $users, $privgroups, $dir;
 355		echo "-!- Caught SIGHUP (1), now rehasing\r\n";
 356		$rehash = TRUE;
 357		require("default.conf.php");
 358		include($dir);
 359		if($setMySQLTablePre) {
 360			$setMySQLTablePre .= "_";
 361		}
 362		$rehash = FALSE;
 363		echo "-!- Rehash complete.\r\n";
 364	}
 365	function SIGTERM() {
 366	global $c_n, $c_red;
 367	//        die();
 368	        global $ircc, $irc;
 369	        fwrite($ircc, "QUIT :Oh noes! :O Caught deadly signal 15 SIGTERM!!\r\n");
 370	        echo <<<IRCO
 371{$c_red}-!- QUIT :Oh noes! :O Caught deadly signal 15 SIGTERM!!\n
 372*** DISCONNECTING FROM {$irc['address']}!\n
 373IRCO;
 374	        fclose($ircc);
 375	        die("Caught SIGTERM!\n{$c_n}");
 376	}
 377	function SIGINT() {
 378		global $c_n, $c_red;
 379	        global $ircc, $irc;
 380	        fwrite($ircc, "QUIT :Oh noes! :O Caught deadly SIGINT (^C) from terminal!!!\r\n");
 381	        echo <<<IRCO
 382{$c_red}-!- QUIT :Oh noes! :O Caught deadly SIGINT!!\n
 383*** DISCONNECTING FROM {$irc['address']}!\n
 384IRCO;
 385	        fclose($ircc);
 386	        die("Caught SIGINT!\n{$c_n}");
 387	}
 388	echo "Initializing Signal Handlers...\r\n";
 389// setup signal handlers
 390	pcntl_signal(SIGHUP, "SIGHUP");
 391	pcntl_signal(SIGTERM, "SIGTERM");
 392	pcntl_signal(SIGINT, "SIGINT");
 393	echo "Success!\r\n";
 394}
 395//PHP Bot for FastLizard4
 396echo "Welcome to the interface for LizardBot-1!\r\n";
 397echo "Determining what configuration file we should use...\r\n";
 398$dir = $_SERVER['argv'][1];
 399$cfg = FALSE;
 400if(!$dir) {
 401	$dir = 'lizardbot.conf.php';
 402	$cfg = TRUE; 
 403}
 404if($cfg) {
 405	echo "{$c_green}Will use the default configuration file, {$dir}{$c_n}\r\n";
 406} else {
 407	echo "{$c_green}Will use the user-specified config file {$dir}{$c_n}\r\n";
 408}
 409echo "Loading essential config files...\r\n";
 410require("default.conf.php");
 411require($dir);
 412echo "OK!\r\n";
 413echo "Verifying required settings are present...\r\n";
 414if(!$users) {
 415	die("{$c_red}Users array missing.{$c_n}\r\n");
 416}
 417if(!$privgroups) {
 418	die("{$c_red}Privgroups array missing.{$c_n}\r\n");
 419}
 420if(!$nickname) {
 421	die("{$c_red}Default nickname missing from config file.{$c_n}\r\n");
 422}
 423if(!$setTrigger) {
 424	$setTrigger = "@";
 425}
 426if(!$setEnableMySQL) {
 427	echo "{$c_yellow}MySQL and all commands requiring MySQL are disabled.{$c_n}\r\n";
 428}
 429if($setEnableMySQL) {
 430	echo "{$c_green}MySQL support enabled!{$c_n}\r\n";
 431	if(!$setMySQLHost) {
 432		die("{$c_red}MySQL database server address not specified (\$setMySQLHost)!{$c_n}\r\n");
 433	} elseif(!$setMySQLPort) {
 434		echo "{$c_yellow}No port for connecting to the MySQL server specified, will use\r\n";
 435		echo "default of 3306...{$c_n}\r\n";
 436		$setMySQLPort = 3306;
 437	} elseif(!$setMySQLUserName) {
 438		die("{$c_red}No MySQL database connection username specified!{$c_n}\r\n");
 439	} elseif(!$setMySQLPassword) {
 440		echo "{$c_yellow}Really?  No password for connecting to MySQL specified.\r\n";
 441		echo "If none is needed, you're doing it wrong....{$c_n}\r\n";
 442	} elseif(!$setMySQLDB) {
 443		die("{$c_red}No MySQL database to use specified in the config file!{$c_n}\r\n");
 444	}
 445	if($setMySQLTablePre) {
 446		$setMySQLTablePre .= "_";
 447	}
 448}
 449echo "Creating the MySQL-related functions....\r\n";
 450if(!$setEnableMySQL) {
 451	echo "You might be wondering why this is happening even though MySQL\r\n";
 452	echo "is disabled.  The functions are being created so that you can\r\n";
 453	echo "enable MySQL support while the bot is running without crashing\r\n";
 454	echo "the bot.  However, before you try to do this (enable MySQL\r\n";
 455	echo "support while the bot is running), make sure that you have read\r\n";
 456	echo "the MySQL documentation on the wiki *COMPLETELY*, or bad stuff\r\n";
 457	echo "*WILL* happen.\r\n";
 458}
 459function dbConnect() {
 460	global $setMySQLHost, $setMySQLPort, $setMySQLUserName, $setMySQLPassword, $setMySQLDB;
 461	$mysql =  mysqli_connect($setMySQLHost, $setMySQLUserName, $setMySQLPassword, $setMySQLDB, $setMySQLPort) OR
 462	print("{$c_red}Failed to connect to the MySQL server!  Details:\r\n" .
 463	mysqli_connect_error() . "{$c_n}\r\n");
 464	return $mysql;
 465}
 466function mkSane($mysql, $data) {
 467	return trim(mysqli_real_escape_string($mysql, $data));
 468}
 469function dbQuery($mysql, $query, &$result) {
 470        $result = mysqli_query($mysql, $query);
 471        if(!$result) {
 472                echo "\r\nERROR: An error occured in the database query:\r\n";
 473                echo "\t" . $query . "\r\n";
 474                echo "MySQL returned the following error:\r\n";
 475                echo "\t" . mysqli_error($mysql) . "\r\n";
 476                return "An error occured in the MySQL database query.  Please check the console for details.";
 477        } else {
 478                return false;
 479        }
 480}
 481if($setEnableMySQL) {
 482	echo "Verifying connection to MySQL database....";
 483	$mysql = dbConnect();
 484	if(!mysql) {die();}
 485	mysqli_close($mysql);
 486	echo "{$_green}    done!{$c_n}\r\n";
 487}
 488if(!$setBitlyAPISleep || !is_int($setBitlyAPISleep)) {
 489	$setBitlyAPISleep = 30;
 490}
 491if(!$timezone) {
 492	echo <<<EOD
 493{$c_red}WARNING!  You did not specify a time zone!  This means you are using
 494the timezone being used by your computer or in your PHP configuration file.  It
 495is strongly recommended that you set the timezone using the \$timezone variable in
 496your LizardBot configuration file!  You have been warned!{$c_n}\r\n
 497EOD;
 498} else {
 499	date_default_timezone_set($timezone);
 500}
 501echo "OK!";
 502if($autoconnect['enabled']) {
 503	echo <<<EOD
 504\r\n{$c_yellow}ATTENTION!  Autoconnect directives are enabled in your configuration file!\r\n
 505The bot will begin autoconnecting in 7 seconds... press ^C NOW if you do not want this to happen!{$c_n}\r\n
 506EOD;
 507	sleep(7);
 508}
 509echo <<<CONSOLEOUTPUT
 510\n{$c_bold}Please enter the FULL address of the network you wish to join.\r\n
 511Specify it as address:port.  If no port is specified, 6667 is used.\r\n
 512{$c_ul}For example: irc.myircnetwork.com:8001 (REQUIRED): 
 513CONSOLEOUTPUT;
 514if($autoconnect['enabled'] && $autoconnect['network']) {
 515	$irc['address'] = $autoconnect['network'];
 516	if(stristr($irc['address'], ":")) {
 517		$temp = explode(":", $irc['address']);
 518		$irc['address'] = $temp[0];
 519		$irc['port'] = $temp[1];
 520	}
 521} elseif($autoconnect['enabled'] && !$autoconnect['network']) {
 522	die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no network was given in config file.{$c_n}\r\n");
 523} elseif(!$autoconnect['enabled']) {
 524	while(!$irc['address']) {
 525		$irc['address'] = fgets(STDIN);
 526		tr($irc['address']);
 527		if(stristr($irc['address'], ":")) {
 528			$temp = explode(":", $irc['address']);
 529			$irc['address'] = $temp[0];
 530			$irc['port'] = $temp[1];
 531		}
 532	}
 533}
 534if(!$irc['address']) {
 535	die("${c_red}No address given.{$c_n}\r\n");
 536}
 537//$nick = $setNick;
 538echo <<<EOD
 539{$c_n}{$c_green}Input of "{$irc['address']}" received!{$c_n}\r\n
 540{$c_bold}Please enter the desired nickname for your bot.  If you enter "." and strike
 541enter, the default (in brackets) will be used\r\n
 542{$c_ul}Nickname [$nickname]: 
 543EOD;
 544if($autoconnect['enabled'] && $autoconnect['nick']) {
 545	$nick = $autoconnect['nick'];
 546} elseif($autoconnect['enabled'] && !$autoconnect['nick']) {
 547	die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no nickname was given in config file.{$c_n}\r\n");
 548} elseif(!$autoconnect['enabled']) {
 549	while(!$nick) {
 550		fscanf(STDIN, "%s", $nick);
 551	}
 552}
 553if($nick == ".") {
 554	$nick = $nickname;
 555	echo <<<EOD
 556{$c_n}{$c_green}No nickname received, using default of $nickname.{$c_n}\r\n
 557EOD;
 558} else {
 559	echo <<<EOD
 560{$c_n}{$c_green}Input of {$nick} received, using that as our nick.{$c_n}\r\n
 561EOD;
 562}
 563echo <<<EOD
 564{$c_bold}Now checking validity of the nickname using standard regex tests...\r\n
 565EOD;
 566if(!preg_match('/^([A-Za-z_\[\]\|])([\w-\[\]\^\|`])*$/', $nick)) {
 567	echo <<<EOD
 568{$c_n}{$c_red}The regex does not match the nick, meaning that the IRC daemon of the server
 569you are attempting to connect to would likely reject your registration signal.
 570Please restart the program and select a valid nick.\r\n
 571A valid nick is: First character is any letter A-Z or a-z, all other characters
 572up to 12 can be A-Z, a-z, 0-9, _, -, or ^.\r\n
 573EOD;
 574	die($c_n);
 575}
 576echo <<<EOD
 577{$c_ul}Should I send identification information to NickServ? (yes/no, default no): 
 578EOD;
 579if($autoconnect['enabled'] && $autoconnect['identify']) {
 580	$irc['identify'] = $autoconnect['identify'];
 581} elseif($autoconnect['enabled'] && !$autoconnect['identify']) {
 582	die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no id mode was given in the config file.{$c_n}\r\n");
 583} elseif(!$autoconnect['enabled']) {
 584	while(!$irc['identify']) {
 585		fscanf(STDIN, "%s", $irc['identify']);
 586	}
 587}
 588switch ($irc['identify']) {
 589	case "yes":
 590	case "y":
 591		echo "{$c_n}{$c_green}OK, will send identification info to NickServ.{$c_n}\r\n";
 592		$irc['get-ident'] = true;
 593		$irc['identify'] = true;
 594	break;
 595	case "no":
 596	case "n":
 597	default:
 598		echo "{$c_n}{$c_green}OK, will not send identification info to NickServ.${c_n}\r\n";
 599		$irc['get-ident'] = false;
 600		$irc['identify'] = false;
 601	break;
 602}
 603if(!$setNSUsername) {
 604	$irc['default-ns'] = "  ";
 605} else {
 606	$irc['default-ns'] = "  [$setNSUsername]: ";
 607}
 608if($irc['get-ident']) {
 609	echo <<<EOD
 610{$c_bold}You will shortly be requested to enter the primary nickname of your account.
 611Note that this is only usable on Atheme, and cannot be used with other daemons,
 612such as Anope to the point that identification will fail.  It is recommended
 613you use this function with Atheme to guarantee your bot correctly identifies.\r\n
 614To send the default (if present), enter "." and strike enter.  To send NO
 615primary username, enter "#" and strike enter.  Otherwise, enter the username
 616you would like to use and strike enter.\r\n
 617Please note that this is not the same as the bot nickname.\r\n
 618{$c_ul}OK, what is the primary username on the account?{$irc['default-ns']}
 619EOD;
 620	if($autoconnect['enabled'] && $autoconnect['id-nick']) {
 621		$NSUsername = $autoconnect['id-nick'];
 622	} elseif($autoconnect['enabled'] && !$autoconnect['id-nick']) {
 623		die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no nickserv username is in the config file.{$c_white}\r\n");
 624	} elseif(!$autoconnect['enabled']) {
 625		while(!$NSUsername) {
 626			fscanf(STDIN, "%s", $NSUsername);
 627		}
 628	}
 629	if($NSUsername == ".") {
 630		$irc['ns-username'] = $setNSUsername . " ";
 631		echo <<<EOD
 632{$c_n}{$c_green}No input received, using default {$setNSUsername}.{$c_n}\r\n
 633EOD;
 634	} elseif($NSUsername == "#") {
 635		echo <<<EOD
 636{$c_n}{$c_green}"#" received, will not send a username to NickServ.{$c_n}\r\n
 637EOD;
 638		$irc['ns-username'] = NULL;
 639	} else {
 640		$irc['ns-username'] = $NSUsername . " ";
 641		echo <<<EOD
 642{$c_n}{$c_green}Input of {$NSUsername} received, using that to identify.{$c_n}\r\n
 643EOD;
 644	}
 645	echo <<<EOD
 646{$c_bold}You will now be prompted to enter the NickServ password.  Please note that THE
 647PASSWORD IS NOT SAVED and it will be VISIBLE IN THE CONSOLE IN CLEAR TEXT, but
 648should disappear when it leaves the screen buffer.  For this reason, you should
 649make sure any files containg a shell log should only be readable by you and
 650only priveleged others.\r\n
 651IF YOU DO NOT WANT TO ENTER A PASSWORD AND ABORT IDENTIFICATION, ENTER "." AND
 652STRIKE ENTER AT THIS PROMPT.\r\n
 653{$c_ul}OK, what is the password?  
 654EOD;
 655	if($autoconnect['enabled'] && $autoconnect['id-pass']) {
 656		$NSPassword = $autoconnect['id-pass'];
 657	} elseif($autoconnect['enabled'] && !$autoconnect['id-pass']) {
 658		die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no nickserv password was given in config.{$c_n}\r\n");
 659	} elseif(!$autoconnect['enabled']) {
 660		while(!$NSPassword) {
 661			fscanf(STDIN, "%s", $NSPassword);
 662		}
 663	}
 664	if($NSPassword == ".") {
 665		echo "{$c_n}{$c_yellow}No input received, WILL NOT IDENTIFY!\r\n";
 666		$irc['identify'] = false;
 667		
 668	} else {
 669		$irc['ns-password'] = $NSPassword;
 670		unset($NSPassword);
 671		echo "{$c_n}{$c_green}Input received, using that to identify.\r\n";
 672		$irc['identify'] = true;
 673	}
 674	unset($autoconnect['id-pass']); //For security purposes
 675}
 676/*foreach($irc as $key => $val) {
 677	echo "$key => $val\r\n";
 678}*/
 679echo <<<CONSOLEOUTPUT
 680{$c_n}Attempting to connect to "{$irc['address']}"...\n
 681Now commencing connection process...\n
 682Opening socket...\n
 683CONSOLEOUTPUT;
 684$n = 0;
 685$open = false;
 686//$fp = array();
 687while(!$open) {
 688	if(isset($fp[$n])) {
 689	$n++;
 690} else {
 691	$open = true;
 692	if(!$irc['port']) { $irc['port'] = 6667; }
 693//	echo $irc . "\r\n";
 694	try { 
 695		if(!$fp[$n] = fsockopen($irc['address'], $irc['port'], $error, $error2, 15)) {
 696			if(stristr($error2, "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.")) {
 697				$error2 .= "(Connection Timed Out)";
 698			}
 699			throw new Exception("Could not open socket! (ERRNO: 1)\r\nTechnical details:\r\nE1: $error\r\nE2: $error2");
 700		}
 701	} catch (Exception $e) {
 702		echo "{$c_red}Could not connect because: " . $e->getMessage() . "\n";
 703		die($c_n);
 704	}
 705	echo <<<CONSOLEOUTPUT
 706Socket to {$irc['address']} opened on port {$irc['port']}...\n
 707Socket ID is: $n\n
 708-!- CONNECTING TO {$irc['address']}:{$irc['port']} ...\n
 709CONSOLEOUTPUT;
 710echo <<<STDOUT
 711Sleeping for 5 seconds to make sure we are connected before registering...\r\n
 712STDOUT;
 713sleep(5);
 714}
 715}
 716if(!$setIdent) $setIdent = "bot";
 717if(!$setGecos) $setGecos = "bot";
 718if($fp[$n]) {
 719	$connected = false;
 720	for($i = 1; $i <=2; $i++) {
 721		global $fp;
 722		fwrite($fp[$n], "USER $setIdent bot bot :$setGecos\r\n");
 723		echo <<<IRCO
 724-!- USER $setIdent bot bot :$setGecos\r\n
 725IRCO;
 726		fwrite($fp[$n], "NICK $nick\r\n");
 727		echo <<<IRCO
 728-!- NICK $nick\r\n
 729IRCO;
 730if($i == 1) {
 731	echo "Waiting 2 seconds before resending registration for good measure...\r\n";
 732	sleep(2);
 733}
 734	}
 735}
 736if($irc['identify']) {
 737	echo "Waiting 2 seconds before sending identification information to make sure we're registered...\r\n";
 738	sleep(2);
 739	fwrite($fp[$n], "PRIVMSG NickServ :IDENTIFY " . $irc['ns-username'] . $irc['ns-password'] . "\r\n");
 740	echo <<<IRCO
 741*** ID INFO SENT\r\n
 742IRCO;
 743	$irc['ns-username'] = NULL;
 744}
 745echo "Waiting 5 seconds to make sure we're all good to begin the sync process...\r\n";
 746sleep(5);
 747if($setAutoModes) {
 748	echo "Now setting usermode(s) +{$setAutoModes} on myself...\r\n";
 749	fwrite($fp[$n], "MODE {$nick} +{$setAutoModes}\r\n");
 750}
 751echo <<<CONSOLEOUTPUT
 752\n{$c_ul}Please enter a comma-delimited list of channels to join: 
 753CONSOLEOUTPUT;
 754if($autoconnect['enabled'] && $autoconnect['channels']) {
 755	$irc['channels'] = $autoconnect['channels'];
 756} elseif($autoconnect['enabled'] && !$autoconnect['channels']) {
 757	die("\r\n{$c_red}ERROR: Autoconnect is enabled, but no channels were specified in config file.{$c_n}\r\n");
 758} elseif(!$autoconnect['enabled']) {
 759	while(!$irc['channels']) {
 760		fscanf(STDIN, "%s", $irc['channels']);
 761	}
 762}
 763echo <<<CONSOLEOUTPUT
 764{$c_n}{$c_green}Input of "{$irc['channels']}" received!{$c_n}\n
 765Joining...\n
 766CONSOLEOUTPUT;
 767$uptime['start'] = time();
 768$irc['channels'] = explode(",", $irc['channels']);
 769foreach($irc['channels'] AS $channel) {
 770	fwrite($fp[$n], "JOIN $channel\r\n");
 771	echo <<<IRCO
 772-!- JOIN $channel\n
 773IRCO;
 774}
 775$ircc = $fp[$n];
 776$delimiter = "@";
 777/*foreach($irc['channels'] AS $channel) {
 778  fwrite($ircc, "PRIVMSG $channel :LizardBot is now online!! :DD\r\n");
 779}*/
 780echo <<<IRCO
 781*** Sent join messages\n
 782IRCO;
 783while(!feof($fp[$n])) {//While connected to IRC...
 784/* if(fscanf(STDIN, "%s", $irc['command']) == 1) {
 785//if($irc['command']) {
 786fwrite($ircc, "{$irc['command']}\r\n");
 787echo "{$irc['command']}\n";
 788echo <<<CONSOLEOUTPUT
 789Input of "{$irc['command']}" received!\n
 790CONSOLEOUTPUT;
 791} */
 792	$toRead = array($ircc, $ircc);
 793	$toWrite = NULL;
 794	$toExcept = NULL;
 795	$toTimeout = 15;
 796	if(stream_select($toRead, $toWrite, $toExcept, $toTimeout) || $setEnableDelays) {
 797		$data = str_replace(array("\n", "\r"), '', fgets($ircc, 1024));
 798		echo $data . "\n";
 799	} else {
 800		$data = NULL;
 801	}
 802	$data2 = str_replace(":", "", $data);
 803	$data3 = str_replace("$$", ":", $data2);
 804	$d = explode(' ', $data3);
 805	$c = $d[2];
 806	if(!$muted) {
 807		if($d[3] == "{$setTrigger}test"&& hasPriv('*')) {
 808			$cmdcount++;
 809			fwrite($ircc, "PRIVMSG $c :OLOL!\r\n");
 810			echo <<<IRCO
 811-!- PRIVMSG #lobby :OLOL!\n
 812IRCO;
 813		}
 814		if($d[3] == "{$setTrigger}die" && hasPriv('die')) {
 815			$cmdcount++; // 9_9
 816			if(true) {
 817				fwrite($ircc, "QUIT :Ordered to death by {$d[0]}!\r\n");
 818				echo <<<IRCO
 819{$c_red}-!- QUIT :Ordered to death!\n
 820*** DISCONNECTING FROM {$irc['address']}!\n
 821IRCO;
 822				fclose($ircc);
 823				die("Terminated!\n{$c_n}");
 824			} else {
 825//        fwrite($ircc, "NOTICE $c :*** WARNING: (PING FastLizard4) {$d[0]} ({$d[2]}) attempted to kill me!\r\n");
 826				echo <<<IRCO
 827*** @die access violation logged!\n
 828IRCO;
 829			}
 830		}
 831	if(hasPriv('say')) {
 832		if($d[3] == "{$setTrigger}say") {
 833			$cmdcount++;
 834			if($d[2] != $nick) {
 835				$ndata = explode(":{$setTrigger}say ", $data);
 836				$rdata = $ndata[1];
 837				fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
 838				echo <<<IRCO
 839-!- PRIVMSG $c :$rdata\n
 840IRCO;
 841			} else {
 842				$kdata = explode(":{$setTrigger}say ", $data);
 843				$cdata = $kdata[1];
 844				$ndata = explode(" ", $cdata);
 845				$c = $ndata[0];
 846				$ndata[0] = NULL;
 847				$rdata = trim(implode(" ", $ndata));
 848				fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
 849				echo <<<IRCO
 850-!- PRIVMSG $c :$rdata\n
 851IRCO;
 852			}
 853		}
 854	}
 855	if(hasPriv('do')) {
 856		if($d[3] == "{$setTrigger}do") {
 857			$cmdcount++;
 858			if($d[2] != $nick) {
 859				$ndata = explode(":{$setTrigger}do ", $data);
 860				$ddata = $ndata[1];
 861				$rdata = chr(001) . "ACTION $ddata" . chr(001);
 862				fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
 863				echo <<<IRCO
 864-!- CTCP $c ACTION $rdata\n
 865IRCO;
 866			} else {
 867				$kdata = explode(":{$setTrigger}do ", $data);
 868				$cdata = $kdata[1];
 869				$ndata = explode(" ", $cdata);
 870				$c = $ndata[0];
 871				$ndata[0] = NULL;
 872				$ddata = implode(" ", $ndata);
 873				$me = trim($ddata);
 874				$rdata = trim(chr(001) . "ACTION $me" . chr(001));
 875				fwrite($ircc, "PRIVMSG $c :$rdata\r\n");
 876				echo <<<IRCO
 877-!- CTCP $c ACTION $rdata\n
 878IRCO;
 879			}
 880		}
 881	}
 882	if($d[3] == "{$setTrigger}join" && hasPriv('join')) {
 883		$cmdcount++;
 884		fwrite($ircc, "JOIN {$d[4]}\r\n");
 885		fwrite($ircc, "PRIVMSG {$d[4]} :{$d[0]} has ordered me to join the channel.\r\n");
 886		echo <<<IRCO
 887-!- JOIN {$d[4]}\n
 888IRCO;
 889	}
 890	if($d[3] == "{$setTrigger}part" && hasPriv('part')) {
 891		$cmdcount++;
 892		fwrite($ircc, "PART {$d[4]} :Ordered to death by {$d[0]}!\r\n");
 893		echo <<<IRCO
 894-!- PART {$d[4]}\n
 895IRCO;
 896	}
 897	if(hasPriv('notice')) {
 898		if($d[3] == "{$setTrigger}notice") {
 899			$cmdcount++;
 900			if($d[2] != $nick) {
 901				$ndata = explode(":{$setTrigger}notice ", $data);
 902				$rdata = $ndata[1];
 903				fwrite($ircc, "NOTICE $c :$rdata\r\n");
 904				echo <<<IRCO
 905-!- NOTICE $c :$rdata\n
 906IRCO;
 907			} else {
 908				$kdata = explode(":{$setTrigger}notice ", $data);
 909				$cdata = $kdata[1];
 910				$ndata = explode(" ", $cdata);
 911				$c = $ndata[0];
 912				$ndata[0] = NULL;
 913				$rdata = implode(" ", $ndata);
 914				fwrite($ircc, "NOTICE $c :$rdata\r\n");
 915				echo <<<IRCO
 916-!- NOTICE $c :$rdata\n
 917IRCO;
 918			}  
 919		}
 920	}
 921	if($d[3] == "{$setTrigger}raw" && hasPriv('raw')) {
 922		$cmdcount++;
 923		if(true) {
 924			$kdata = explode("{$setTrigger}raw ", $data);
 925			$rdata = $kdata[1];
 926			fwrite($ircc, "$rdata\r\n");
 927			echo <<<IRCO
 928-!- MANUAL RAW COMMAND ISSUED BY {$d[0]}: $rdata\n
 929IRCO;
 930		} else {
 931			fwrite($ircc, "PRIVMSG $c :Access denied.\r\n");
 932			echo <<<IRCO
 933PRIVMSG $c :Access denied.\r\n
 934IRCO;
 935		}
 936	}
 937	if($d[0] == 'PING') {
 938		$pingcount++;
 939		fwrite($ircc, "PONG {$d[1]}\r\n");
 940		echo <<<IRCO
 941PONG {$d[1]}\n
 942IRCO;
 943	}
 944	if($d[3] == "{$setTrigger}fap" && hasPriv('fap')) {
 945		$cmdcount++;
 946		if(!$d[4]) {
 947			$who = explode("!", $d[0]);
 948			$who2 = $who[0];
 949		} else {
 950			$who2 = $d[4];
 951		}
 952		fwrite($ircc, "PRIVMSG $c :Ceiling_Cat is watching $who2 masturbate\r\n");
 953		echo <<<IRCO
 954PRIVMSG $c :Ceiling_Cat is watching $who2 masturbate\n
 955IRCO;
 956	}
 957	if(hasPriv('op')) {
 958		if($d[3] == "{$setTrigger}kick") {
 959			$cmdcount++;
 960//$data1 = explode("{$setTrigger}kick ", $data);
 961			if($d[2] != $nick) {
 962				$kdata = explode(":{$setTrigger}kick ", $data);
 963				$cdata = $kdata[1];
 964				$ndata = explode(" ", $cdata);
 965				$target = $ndata[0];
 966				$ndata[0] = NULL;
 967				$comment = implode(" ", $ndata);
 968			} else {
 969				$kdata = explode(":{$setTrigger}kick ", $data);
 970				$cdata = $kdata[1];
 971				$ndata = explode(" ", $cdata);
 972				$c = $ndata[0];
 973				$target = $ndata[1];
 974				$ndata[0] = NULL;
 975				$ndata[1] = NULL;
 976				$comment = implode(" ", $ndata);
 977			}
 978			fwrite($ircc, "KICK $c $target :$comment\r\n");
 979			echo <<<IRCO
 980-!- KICK $c $target :$comment\n
 981IRCO;
 982		}
 983	}
 984	if($d[3] == "{$setTrigger}op" && hasPriv('op')) {
 985		$cmdcount++;
 986		fwrite($ircc, "PRIVMSG ChanServ :OP $c\r\n");
 987		echo <<<IRCO
 988PRIVMSG ChanServ :OP $c\n
 989IRCO;
 990	}
 991	if($d[3] == "{$setTrigger}deop" && hasPriv('op')) {
 992		$cmdcount++;
 993		fwrite($ircc, "MODE $c -o {$nick}\r\n");
 994		echo <<<IRCO
 995MODE $c -o LizardBot-1\n
 996IRCO;
 997	}
 998	if($d[3] == chr(001) . "VERSION" . chr(001)) {
 999		$ctcpcount++;
1000		$target = explode("!", $d[0]);
1001		$target = $target[0];
1002		$data = "NOTICE $target :";
1003		$data .= chr(001);
1004		$data .= "VERSION " . $setCTCPVersion;
1005		$data .= chr(001);
1006		$data .= "\r\n";
1007		fwrite($ircc, $data);
1008		echo <<<IRCO
1009-!- SENT CTCP VERSION REPLY TO $target\n
1010IRCO;
1011	}
1012
1013
1014	
1015	if($d[3] == chr(001) . "TIME" . chr(001)) {
1016		$ctcpcount++;
1017		$target = explode("!", $d[0]);
1018		$target = $target[0];
1019		$data = "NOTICE $target :";
1020		$data .= chr(001);
1021		$data .= "TIME " . date('r');
1022		$data .= chr(001);
1023		$data .= "\r\n";
1024		fwrite($ircc, $data);
1025		echo <<<IRCO
1026-!- SENT CTCP TIME REPLY TO $target\n
1027IRCO;
1028	}
1029	if($d[3] == chr(001) . "USERINFO" . chr(001)) {
1030		$ctcpcount++;
1031		$target = explode("!", $d[0]);
1032		$target = $target[0];
1033		$data = "NOTICE $target :";
1034		$data .= chr(001);
1035		$data .= "USERINFO " . $setCTCPUserinfo;
1036		$data .= chr(001);
1037		$data .= "\r\n";
1038		fwrite($ircc, $data);
1039		echo <<<IRCO
1040-!- SENT CTCP USERINFO REPLY TO $target\n
1041IRCO;
1042	}
1043	if($d[3] == chr(001) . "CLIENTINFO" . chr(001)) {
1044		$ctcpcount++;
1045		$target = explode("!", $d[0]);
1046		$target = $target[0];
1047		$data = "NOTICE $target :";
1048		$data .= chr(001);
1049		$data .= "CLIENTINFO CLIENTINFO FINGER TIME USERINFO VERSION";
1050		$data .= chr(001);
1051		$data .= "\r\n";
1052		fwrite($ircc, $data);
1053		echo <<<IRCO
1054-!- SENT CTCP CLIENTINFO REPLY TO $target\n
1055IRCO;
1056	}
1057
1058
1059	if($d[3] == chr(001) . "FINGER" . chr(001)) {
1060		$ctcpcount++;
1061		$target = explode("!",$d[0]);
1062		$target = $target[0];
1063		$data = "NOTICE $target :";
1064		$data .= chr(001);
1065		$data .= "FINGER ". $setCTCPVersion;
1066		$data .= chr(001);
1067		$data .= "\r\n";
1068		fwrite($ircc, $data);
1069		echo <<<IRCO
1070-!- SENT CTCP FINGER REPLY TO $target\n
1071IRCO;
1072	}
1073	if($d[3] == "{$setTrigger}rehash" && hasPriv('rehash')) {
1074		$cmdcount++;
1075		if($d[2] == $nick) {
1076			$kdata = explode($d[0], "!");
1077			$target = $kdata[0];
1078		} else {
1079			$target = $d[2];
1080		}
1081		fwrite($ircc, "PRIVMSG $target :Rehashing...\r\n");
1082		echo "PRIVMSG $target :Rehashing...\r\n";
1083		$rehash = true;
1084		require("default.conf.php");
1085		include($dir);
1086		if($setMySQLTablePre) {
1087			$setMySQLTablePre .= "_";
1088		}
1089		echo "Rehashed!\r\n";
1090		fwrite($ircc, "PRIVMSG $target :Rehashed config file.\r\n");
1091		echo "PRIVMSG $target :Rehashed config file.\r\n";
1092	}
1093	if($d[3] == "{$setTrigger}nick" && hasPriv('nick')) {
1094		$cmdcount++;
1095		$nick = $d[4];
1096		fwrite($ircc, "NICK $nick\r\n");
1097		echo "-!- NICK $nick\r\n";
1098	}
1099
1100	if(($d[3] == "{$setTrigger}info" || $d[3] == "{$setTrigger}help") && hasPriv('*')) {
1101		$cmdcount++;
1102		$target = explode("!", $d[0]);
1103		$target2 = $target[0];
1104		if(!stristr($d[2], "#")) {
1105			$c = $target2[0];
1106		}
1107/*		fwrite($ircc, "PRIVMSG $c :$target2: Hello!  I am LizardBot-1, FastLizard4's PHP bot.  I am written 
1108in PHP 5 Procedural.  I work on both Windows and *Nix systems with PHP installed.  I am run from the command line.  These are the commands you can run (the trigger is {$setTrigger}):\r\n");
1109		sleep(2);
1110		fwrite($ircc, "PRIVMSG $c :$target2: test, join, part, do, op, deop, kick, fap, notice.  Restricted commands: <hidden>.\r\n");
1111		sleep(1);
1112		fwrite($ircc, "PRIVMSG $c :$target2: You have the access level of: " . showPriv() . "\r\n");
1113		sleep(1);
1114		fwrite($ircc, "PRIVMSG $c :$target2: Extensions: Pandorabot by Ttech (PHP-5-OOP)\r\n");
1115		sleep(2);*/
1116		fwrite($ircc, "PRIVMSG $c :$target2: For help and copyrights, see http://fastlizard4.org/wiki/LizardBot\r\n");
1117		echo "
1118-!- $target2 requested {$setTrigger}info\n
1119";
1120	}
1121	if(preg_match('/^[,.?!@#$%^&*-+_=|]+help$/', $d[3]) && $setEnableAllTriggerHelp && hasPriv('*') && $d[3] != "{$setTrigger}help") {
1122                $cmdcount++;
1123                $target = explode("!", $d[0]);
1124                $target2 = $target[0];
1125                if(!stristr($d[2], "#")) {
1126                        $c = $target2[0];
1127                }
1128		fwrite($ircc, "PRIVMSG $c :$target2: You have triggered my general help command by using a \"standard\" bot trigger that is not my normal trigger.  For your reference, my normal trigger (which you must use for triggering all my commands) is {$setTrigger}\r\n");
1129                fwrite($ircc, "PRIVMSG $c :$target2: For help and copyrights, see http://fastlizard4.org/wiki/LizardBot\r\n");
1130	}
1131	if($d[3] == "{$setTrigger}nyse" && hasPriv('nyse')) {
1132		$cmdcount++;
1133		$symbol = $d[4];
1134		$url = sprintf('http://quote.yahoo.com/d/quotes.csv?s=%s&f=nl1c6k2t1vp', urlencode($symbol));
1135		echo "-!- Getting quote for $symbol\r\n";
1136		$quoteurl = @fopen($url, 'r') OR $data = "Error connecting to Yahoo!";
1137		$read = fgetcsv($quoteurl);
1138		fclose($quoteurl);
1139		$colorend = "\003";
1140		if($read[2] >= 0) {
1141			$color = "\0033";
1142//			$read[2] = "+" . $read[2];
1143		} elseif($read[2] <= 0) {
1144			$color = "\0034";
1145		} elseif($read[2] == 0) {
1146			$color = NULL;
1147			$colorend = NULL;
1148		}
1149		$pcnt = explode(" ", $read[3]);
1150		if(strcasecmp($read[0], $symbol) != 0) {
1151			if(!$setNoBolds) {$bold = "\002";}
1152			$data = "The latest value for {$bold}'{$read[0]}'{$bold} (\0036$symbol\003) is " . chr(003) . "12" . "\$" . $read[1] . "\003 (delta:" . $color . " " . $read[2] . $colorend . " or" . $color . " " . $pcnt[2] . $colorend . " from last close of " . $read[6] . "; last trade at " . $read[4] . " eastern time; mkt volume: " . $read[5] . ") (Source: Yahoo!)";
1153		} else {
1154			$data = "Invalid symbol.";
1155		}
1156		$target = explode("!", $d[0]);
1157		$e = $target[0] . ": ";
1158		if($d[2] == $nick) {
1159			$target = explode("!", $d[0]);
1160			$c = $target[0];
1161			$e = NULL;
1162		} else {
1163			$c = $d[2];
1164		}
1165		fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
1166		echo "PRIVMSG $c :" . $e . $data . "\r\n";
1167	}
1168	if($d[3] == "{$setTrigger}fantasy" && hasPriv('*')) {
1169		$cmdcount++;
1170		if(!$setFantasy) {
1171			$data = "Fantasy is off.";
1172		} else {
1173			$data = "Fantasy is on.";
1174		}
1175                $target = explode("!", $d[0]);
1176                $e = $target[0] . ": ";
1177                if($d[2] == $nick) {
1178                        $target = explode("!", $d[0]);
1179                        $c = $target[0];
1180                        $e = NULL;
1181                } else {
1182                        $c = $d[2];
1183                }
1184		fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
1185		echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
1186	}
1187	if($d[3] == "{$setTrigger}fantasy-on" && hasPriv('mute')) {
1188		$cmdcount++;
1189		$setFantasy = TRUE;
1190		$ai = new pandorabot("838c59c76e36816b");
1191		if(!$setAIDefaultRE) { $setAIDefaultRE = "Probably"; }
1192		$ai->default_response = $setAIDefaultRE;
1193		$data = "Fantasy turned on!";
1194                $target = explode("!", $d[0]);
1195                $e = $target[0] . ": ";
1196                if($d[2] == $nick) {
1197                        $target = explode("!", $d[0]);
1198                        $c = $target[0];
1199                        $e = NULL;
1200                } else {
1201                        $c = $d[2];
1202                }
1203                fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
1204                echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
1205	}
1206        if($d[3] == "{$setTrigger}fantasy-off" && hasPriv('mute')) {
1207        	$cmdcount++;
1208                $setFantasy = FALSE;
1209		unset($ai);
1210                $data = "Fantasy turned off!";
1211                $target = explode("!", $d[0]);
1212                $e = $target[0] . ": ";
1213                if($d[2] == $nick) {
1214                        $target = explode("!", $d[0]);
1215                        $c = $target[0];
1216                        $e = NULL;
1217                } else {
1218                        $c = $d[2];
1219                }
1220                fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
1221                echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
1222        }
1223	if($setFantasy && hasPriv('fantasy')) {
1224		if(!$ai) {
1225			$ai = new pandorabot("838c59c76e36816b");
1226	                if(!$setAIDefaultRE) { $setAIDefaultRE = "Probably"; }
1227	                $ai->default_response = $setAIDefaultRE;
1228		}
1229//		$data-ai = explode(":", $data);
1230		$dataai = explode(" :", $data);
1231//		echo "dataai: " . $dataai[2] . "\r\n";
1232//		echo "dataai1: " . $dataai[1] . "\r\n";
1233		$nicksan = preg_quote($nick, '/');
1234		$regex = "/^";
1235		$regex .= $nicksan;
1236		$regex .= "(: |, | - ).*$/i";
1237		if(preg_match($regex, $dataai[1])) {
1238			$parseai = explode(" ", $dataai[1]);
1239//			echo "parseai: " . $parseai . "\r\n";
1240			$parseai[0] = null;
1241			$parsedata = implode(" ", $parseai);
1242//			echo "parsedata: " . $parsedata . "\r\n";
1243			$msg = $parsedata; // This is the message you get from IRC 
1244			$ai->set_timeout(180); // 60 should be fine
1245			$rofl = $ai->say($msg); // This is what you want to get back to the user. 
1246			$aicount++;
1247			if(!$rofl || preg_match('/^\s*$/', $rofl)) { $rofl = $ai->default_response; }
1248	                $target = explode("!", $d[0]);
1249        	        $e = $target[0] . ": ";
1250			sleep(2);
1251                	if($d[2] == $nick) {
1252                        	$target = explode("!", $d[0]);
1253	                        $c = $target[0];
1254        	                $e = NULL;
1255                	} else {
1256	                        $c = $d[2];
1257        	        }
1258	                fwrite($ircc, "PRIVMSG $c :" . $e . $rofl . "\r\n");
1259        	        echo "-!- PRIVMSG $c :" . $e . $rofl . "\r\n";
1260		}
1261	}
1262	if($d[3] == "{$setTrigger}exec" && hasPriv('exec') && $setEnableExec) {
1263		$cmdcount++;
1264		$tgc = $d[2];
1265		$tgf = $d[0];
1266		$d[0] = NULL;
1267		$d[1] = NULL;
1268		$d[2] = NULL;
1269		$d[3] = NULL;
1270                $target = explode("!", $tgf);
1271                $e = $target[0] . ": ";
1272		$data = implode(" ", $d);
1273//                $patterns = array("/\e*/");
1274//                $replacements = array(" ");
1275//                $sandata = preg_replace($patterns, $replacements, $data);
1276		unset($execresult);
1277		$result = exec($data, $execresult, $return);
1278		if($tgc == $nick) {
1279			$target = explode("!", $tgf);
1280                                $c = $target[0];
1281                                $e = NULL;
1282                        } else {
1283                                $c = $tgc;
1284                        }
1285		$returndata = implode(" ", $execresult);
1286		if($return == 127) { $return .= " (Command Unrecognized)"; }
1287		$output = "Output: " . $returndata . "; Return: " . $return;
1288		fwrite($ircc, "PRIVMSG $c :" . $e . $output . "\r\n");
1289                echo "-!- PRIVMSG $c :" . $e . $output . "\r\n";
1290	}
1291	if($d[3] == "{$setTrigger}tinyurl" && hasPriv('tinyurl')) {
1292		$cmdcount++;
1293		$ndata = explode(":{$setTrigger}tinyurl ", $data);
1294		$rdata = $ndata[1];
1295		$data = NULL;
1296		$tinyurl = trim($rdata);
1297//		$tinyurl = urlencode($tinyurl);
1298		if(!preg_match('#^(http|https)://.*$#i', $tinyurl)) {
1299			$data = "Invalid URL.";
1300		} else {
1301			$tinyfp = fopen("http://tinyurl.com/api-create.php?url={$tinyurl}","r") OR $data = "Error in connection to TinyURL API.";
1302			if(!$data) {
1303				$data   = fgets($tinyfp);
1304				fclose($tinyfp); //Remember to close all sockets!
1305			}
1306		}
1307		/* BEGIN DETERMINATION BLOCK */
1308		$target = explode("!", $d[0]);
1309		$e = $target[0] . ": ";
1310		if($d[2] == $nick) {
1311			$target = explode("!", $d[0]);
1312			$c = $target[0];
1313			$e = NULL;
1314		} else {
1315			$c = $d[2];
1316		} /* END DETERMINATION BLOCK */
1317		fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
1318		echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
1319	}
1320	if($d[3] == "{$setTrigger}eval" && hasPriv('eval') && $setEnableEval) {
1321		$cmdcount++;
1322                $tgc = $d[2];
1323                $tgf = $d[0];
1324                $d[0] = NULL;
1325                $d[1] = NULL;
1326                $d[2] = NULL;
1327                $d[3] = NULL;
1328                $target = explode("!", $tgf);
1329                $e = $target[0] . ": ";
1330                $data = implode(" ", $d);
1331//                $patterns = array("/\e*/");
1332//                $replacements = array(" ");
1333//                $sandata = preg_replace($patterns, $replacements, $data);
1334//                unset($execresult);
1335		if(!$setNoBolds) { $bold = "\002"; }
1336		try {
1337	                $result = eval($data);
1338		} catch(Exception $e) {
1339			$result = $bold . "ERROR: " . $bold . $e->__toString();
1340		}
1341                if($tgc == $nick) {
1342                        $target = explode("!", $tgf);
1343                                $c = $target[0];
1344                                $e = NULL;
1345                        } else {
1346                                $c = $tgc;
1347                        }
1348		$status = ($result) ? "true" : "false";
1349		$output = "Code returned: $result ($status)";
1350                fwrite($ircc, "PRIVMSG $c :" . $e . $output . "\r\n");
1351                echo "-!- PRIVMSG $c :" . $e . $output . "\r\n";
1352        }
1353	if($d[3] == "{$setTrigger}update" && hasPriv('*')) {
1354		$cmdcount++;
1355		echo "Checking for updates...\r\n";
1356		$version = "7.3.0.0b";
1357		$upfp = @fopen('http://fastlizard4.org/w/index.php?title=LizardBot/Latest&action=raw', 'r');
1358		$data = @fgets($upfp);
1359		@fclose($upfp);
1360                $target = explode("!", $d[0]);
1361                $e = $target[0] . ": ";
1362                if($d[2] == $nick) {
1363                        $target = explode("!", $d[0]);
1364                        $c = $target[0];
1365                        $e = NULL;
1366                } else {
1367                        $c = $d[2];
1368

Large files files are truncated, but you can click here to view the full file