PageRenderTime 47ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

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