PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
  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];
  1339. }
  1340. if(!$data) {
  1341. $output = "Check for updates failed!";
  1342. }
  1343. if($data == $version) {
  1344. $output = "LizardBot is up-to-date";
  1345. } else {
  1346. $output = "LizardBot version {$data} is available. Please update, or get details at http://fastlizard4.org/wiki/LizardBot/CL#latest";
  1347. }
  1348. fwrite($ircc, "PRIVMSG $c :" . $e . $output . "\r\n");
  1349. echo "-!- PRIVMSG $c :" . $e . $output . "\r\n";
  1350. }
  1351. if($d[3] == "{$setTrigger}wot" && hasPriv('*')) {
  1352. $cmdcount++;
  1353. $site = $d[4];
  1354. $url = sprintf('http://api.mywot.com/0.4/public_link_json?hosts=%s/&callback=jsonp1225957266492&_=1225957271558', $site);
  1355. echo "-!- Getting WoT ratings for {$site}\r\n";
  1356. $woturl = @fopen($url, 'r') OR $data = "Error connecting to WoT API!";
  1357. $jsonout = fgets($woturl);
  1358. fclose($woturl);
  1359. $first = $jsonout;
  1360. $second = explode("(", $first);
  1361. $third = explode(")", $second[1]);
  1362. $json = $third[0];
  1363. // echo $json . "\r\n";
  1364. /* $patterns = array("[", "]");
  1365. $replacements = array("{", "}");
  1366. $jsono = str_replace($patterns, $replacements, $json);
  1367. $patterns = " ";
  1368. $replacements = "";
  1369. $jsonin = str_replace($patterns, $replacements, $jsono);
  1370. echo $jsonin . "\r\n";*/
  1371. $array2 = json_decode($json, TRUE);
  1372. /* foreach($array2 AS $key => $value) {
  1373. if(!is_scalar($value)) {
  1374. foreach($value AS $vkey => $vval) {
  1375. if(!is_scalar($vval)) {
  1376. foreach($vval AS $vvkey => $vvval) {
  1377. $vval = "<<<ARRAY>>>";
  1378. }
  1379. }
  1380. echo <<<STDOUT
  1381. \t([{$vkey}] => {$vval})\r\n
  1382. STDOUT;
  1383. $value = "<<<ARRAY>>>";
  1384. }
  1385. }
  1386. echo <<<STDOUT
  1387. [{$key}] => {$value}\r\n
  1388. STDOUT;
  1389. }*/
  1390. if($d[2] == $nick) {
  1391. $target = explode("!", $d[0]);
  1392. $c = $target[0];
  1393. $e = NULL;
  1394. } else {
  1395. $c = $d[2];
  1396. $target = explode("!", $d[0]);
  1397. $e = $target[0] . ":";
  1398. }
  1399. if(!$setNoBolds) {
  1400. $bold = "\002";
  1401. } else {
  1402. $bold = NULL;
  1403. }
  1404. // $wotarray = $array2[$site];
  1405. $wot = array();
  1406. /* foreach($wotarray[0] AS $key => $value) {
  1407. $patterns = array("\r\n", "\r", "\n");
  1408. $replacements = "";
  1409. $wotarray[0][$key] = str_replace($patterns, $replacements, $value);
  1410. }
  1411. foreach($wotarray[1] AS $key => $value) {
  1412. $patterns = array("\r\n", "\r", "\n");
  1413. $replacements = "";
  1414. $wotarray[1][$key] = str_replace($patterns, $replacements, $value);
  1415. }
  1416. foreach($wotarray[2] AS $key => $value) {
  1417. $patterns = array("\r\n", "\r", "\n");
  1418. $replacements = "";
  1419. $wotarray[2][$key] = str_replace($patterns, $replacements, $value);
  1420. }
  1421. foreach($wotarray[4] AS $key => $value) {
  1422. $patterns = array("\r\n", "\r", "\n");
  1423. $replacements = "";
  1424. $wotarray[4][$key] = str_replace($patterns, $replacements, $value);
  1425. }*/
  1426. $wot['trustworthiness']['rating'] = trim($array2[$site][0][0]);
  1427. $wot['trustworthiness']['reliable'] = trim($array2[$site][0][1]);
  1428. $wot['vendor reliability']['rating'] = trim($array2[$site][1][0]);
  1429. $wot['vendor reliability']['reliable'] = trim($array2[$site][1][1]);
  1430. // echo $array2[$site][1][1] . "\r\n";
  1431. // echo $wot['vendor reliability']['reliable'] . "\r\n";
  1432. // echo $wot['vendor reliability']['reliable'] . "\r\n";
  1433. $wot['privacy']['rating'] = trim($array2[$site][2][0]);
  1434. $wot['privacy']['reliable'] = trim($array2[$site][2][1]);
  1435. $wot['child safety']['rating'] = trim($array2[$site][4][0]);
  1436. $wot['child safety']['reliable'] = trim($array2[$site][4][1]);
  1437. if($wot['trustworthiness']['rating'] >= 80) {
  1438. $color[0] = "\0033";
  1439. } elseif($wot['trustworthiness']['rating'] >= 60 && $wot['trustworthiness']['rating'] < 79) {
  1440. $color[0] = "\0039";
  1441. } elseif($wot['trustworthiness']['rating'] >= 40 && $wot['trustworthiness']['rating'] < 59) {
  1442. $color[0] = "\0038";
  1443. } elseif($wot['trustworthiness']['rating'] >= 20 && $wot['trustworthiness']['rating'] < 39) {
  1444. $color[0] = "\0037";
  1445. } elseif($wot['trustworthiness']['rating'] >= 0 && $wot['trustworthiness']['rating'] < 19) {
  1446. $color[0] = "\0034";
  1447. } else { $color[0] = "\0034"; $wot['trustworthiness']['rating'] = "NO DATA"; }
  1448. if($wot['vendor reliability']['rating'] >= 80) {
  1449. $color[1] = "\0033";
  1450. } elseif($wot['vendor reliability']['rating'] >= 60 && $wot['vendor reliability']['rating'] < 79) {
  1451. $color[1] = "\0039";
  1452. } elseif($wot['vendor reliability']['rating'] >= 40 && $wot['vendor reliability']['rating'] < 59) {
  1453. $color[1] = "\0038";
  1454. } elseif($wot['vendor reliability']['rating'] >= 20 && $wot['vendor reliability']['rating'] < 39) {
  1455. $color[1] = "\0037";
  1456. } elseif($wot['vendor reliability']['rating'] >= 0 && $wot['vendor reliability']['rating'] < 19) {
  1457. $color[1] = "\0034";
  1458. } else { $color[1] = "\0034"; $wot['vendor reliability']['rating'] = "NO DATA"; }
  1459. if($wot['privacy']['rating'] >= 80) {
  1460. $color[2] = "\0033";
  1461. } elseif($wot['privacy']['rating'] >= 60 && $wot['privacy']['rating'] < 79) {
  1462. $color[2] = "\0039";
  1463. } elseif($wot['privacy']['rating'] >= 40 && $wot['privacy']['rating'] < 59) {
  1464. $color[2] = "\0038";
  1465. } elseif($wot['privacy']['rating'] >= 20 && $wot['privacy']['rating'] < 39) {
  1466. $color[2] = "\0037";
  1467. } elseif($wot['privacy']['rating'] >= 0 && $wot['privacy']['rating'] < 19) {
  1468. $color[2] = "\0034";
  1469. } else { $color[2] = "\0034"; $wot['privacy']['rating'] = "NO DATA"; }
  1470. if($wot['child safety']['rating'] >= 80) {
  1471. $color[4] = "\0033";
  1472. } elseif($wot['child safety']['rating'] >= 60 && $wot['child safety']['rating'] < 79) {
  1473. $color[4] = "\0039";
  1474. } elseif($wot['child safety']['rating'] >= 40 && $wot['child safety']['rating'] < 59) {
  1475. $color[4] = "\0038";
  1476. } elseif($wot['child safety']['rating'] >= 20 && $wot['child safety']['rating'] < 39) {
  1477. $color[4] = "\0037";
  1478. } elseif($wot['child safety']['rating'] >= 0 && $wot['child safety']['rating'] < 19) {
  1479. $color[4] = "\0034";
  1480. } else { $color[4] = "\0034"; $wot['child safety']['rating'] = "NO DATA"; }
  1481. $toirc = "The WoT rating for {$site} is: Trust: {$bold}{$color[0]}<\003{$bold} {$wot['trustworthiness']['rating']}, {$wot['trustworthiness']['reliable']} {$bold}{$color[0]}>\003{$bold}; Reliability: {$bold}{$color[1]}<\003{$bold} {$wot['vendor reliability']['rating']}, {$wot['vendor reliability']['reliable']} {$bold}{$color[1]}>\003{$bold}; Privacy: {$bold}{$color[2]}<\003{$bold} {$wot['privacy']['rating']}, {$wot['privacy']['reliable']} {$bold}{$color[2]}>\003{$bold}; Child Safety: {$bold}{$color[4]}<\003{$bold} {$wot['child safety']['rating']}, {$wot['child safety']['reliable']} {$bold}{$color[4]}>\003{$bold} (http://www.mywot.com/en/scorecard/{$site})";
  1482. $patterns = array("\r\n", "\r", "\n");
  1483. $replacements = "";
  1484. $outtoirc = str_replace($patterns, $replacements, $toirc);
  1485. fwrite($ircc, "PRIVMSG $c :" . $e . $outtoirc . "\r\n");
  1486. echo "-!- PRIVMSG $c :" . $e . $outtoirc . "\r\n";
  1487. unset($color);
  1488. }
  1489. if($d[3] == "{$setTrigger}gcalc" && hasPriv('*') && $setTrustGoogle) {
  1490. $cmdcount++;
  1491. /*
  1492. * VARIABLES
  1493. * $toGoogle: Data to be sent to Google
  1494. * $google: Fp for Google
  1495. * $googleURL: The URL we should connect to
  1496. * $data: Data to be returned to IRC
  1497. * $googleOutn: Data from Google
  1498. * $tnick: Target nick
  1499. * $tt: Placeholder
  1500. */
  1501. $stopExecution = FALSE;
  1502. $tt = $d[0];
  1503. $d[0] = NULL;
  1504. $d[1] = NULL;
  1505. $tnick = $d[2];
  1506. $d[2] = NULL;
  1507. $d[3] = NULL;
  1508. $toGoogle = implode(" ", $d);
  1509. $googleURL = 'http://www.google.com/search?q=' . urlencode($toGoogle);
  1510. $googleOut = NULL;
  1511. $google = @fopen($googleURL, 'r') OR $data = "Error connecting to Google! Oh noes!";
  1512. while(!feof($google)) {
  1513. if(!$googleOut) {
  1514. $googleOut = fgets($google);
  1515. } else {
  1516. $googleOut .= fgets($google);
  1517. }
  1518. }
  1519. fclose($google);
  1520. unset($google);
  1521. if(!stristr($googleOut, '<img src="/images/icons/onebox/calculator-40.gif" width=40 height=40 alt="">')) {
  1522. $data = "Error: An invalid calculation was specified.";
  1523. $stopExecution = TRUE;
  1524. }
  1525. if(!$stopExecution) {
  1526. //Note: The following code comes from http://www.hawkee.com/snippet/5812/ and is modified to work here
  1527. $f = array("Â", "<font size=-2> </font>", " &#215; 10", "<sup>", "</sup>");$t = array("", "", "e", "^", "");
  1528. preg_match('/<h2 class=r style="font-size:138%"><b>(.*?)<\/b><\/h2>/', $googleOut, $matches);
  1529. if (!$matches['1']){
  1530. $data = 'Your input could not be processed..';
  1531. } else {
  1532. $data = str_replace($f, $t, $matches['1']);
  1533. }
  1534. }
  1535. unset($googleOut);
  1536. unset($toGoogle);
  1537. unset($googleURL);
  1538. $target = explode("!", $tt);
  1539. $e = $target[0] . ": ";
  1540. if($tnick == $nick) {
  1541. $target = explode("!", $tt);
  1542. $c = $target[0];
  1543. $e = NULL;
  1544. } else {
  1545. $c = $tnick;
  1546. }
  1547. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1548. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1549. unset($c);
  1550. unset($e);
  1551. unset($data);
  1552. unset($tt);
  1553. unset($tnick);
  1554. unset($stopExecution);
  1555. }
  1556. /* if($d[3] == "{$setTrigger}editcount" && hasPriv('*')) {
  1557. $cmdcount++;
  1558. $error = FALSE;
  1559. /************************
  1560. Editcount function
  1561. *Determines a user's editcount on various Wikimedia wikis
  1562. *May be upgraded in the future to use non-wikimedia wikis
  1563. *Variables used:
  1564. **
  1565. **********************/
  1566. /* $editcount['user'] = $d[4];
  1567. $editcount['wiki'] = $d[6];
  1568. $editcount['lang'] = $d[5];
  1569. if(!$editcount['wiki']) { $editcount['wiki'] = "wikipedia"; }
  1570. if(!$editcount['lang']) { $editcount['lang'] = "en"; }
  1571. if(!$editcount['user']) {
  1572. $error = TRUE;
  1573. $data = "Error: No username was specified. Please specify one.";
  1574. } else {
  1575. $editcount['user'] = urlencode($editcount['user']);
  1576. $editcount['lang'] = urlencode($editcount['lang']);
  1577. $editcount['wiki'] = urlencode($editcount['wiki']);
  1578. }
  1579. if(!$error) {
  1580. $soxtoolURL = "http://toolserver.org/~soxred93/count/index.php?name={$editcount['user']}&lang={$editcount['lang']}&wiki={$editcount['wiki']}";
  1581. $data = NULL;
  1582. $soxtoolOut = NULL;
  1583. $soxtool = @fopen($soxtoolURL, 'r') OR $data = "Error connecting to SoxRed's editcounter! Oh noes!";
  1584. $i = 0;
  1585. while(!feof($soxtool) && $i <= 50) {
  1586. if(!$soxtoolOut) {
  1587. $soxtoolOut = fgets($soxtool);
  1588. } else {
  1589. $soxtoolOut .= fgets($soxtool);
  1590. }
  1591. $i++;
  1592. }
  1593. $editcount['live'] = explode("<b>Live edits: ", $soxtoolOut);
  1594. $editcount['live']['parsed'] = explode("</b><br />", $editcount['live'][1]);
  1595. $editcount['userrights'] = explode("User groups: ", $soxtoolOut);
  1596. $editcount['userrights']['parsed'] = explode("<br />", $editcount['userrights'][1]);
  1597. $editcount['first edit'] = explode("First edit: ", $soxtoolOut);
  1598. $editcount['first edit']['parsed'] = explode("<br />", $editcount['first edit'][1]);
  1599. $editcount['deleted'] = explode("Deleted edits: ", $soxtoolOut);
  1600. $editcount['deleted']['parsed'] = explode("<br />", $editcount['deleted'][1]);
  1601. $editcount['total'] = explode("Total edits (including deleted): ", $soxtoolOut);
  1602. $editcount['total']['parsed'] = explode("<br />", $editcount['total'][1]);
  1603. if($setNoBolds) {
  1604. $bold = NULL;
  1605. } else {
  1606. $bold = "\002";
  1607. }
  1608. $data .= "\0032Contribs: http://{$editcount['lang']}.{$editcount['wiki']}.org/wiki/Special:Contributions/{$editcount['user']}\003 - ";
  1609. $data .= "\0037Userrights: {$editcount['userrights']['parsed'][0]}\003 - \0036First edit: {$editcount['first edit']['parsed'][0]}\003 - {$bold}\00312Total edits: {$editcount['total']['parsed'][0]} \003(\0034Deleted: {$editcount['deleted']['parsed'][0]}\003 - \0033Live: {$editcount['live']['parsed'][0]}\003){$bold} - \00310{$soxtoolURL}\003";
  1610. }
  1611. $target = explode("!", $d[0]);
  1612. $e = $target[0] . ": ";
  1613. if($d[2] == $nick) {
  1614. $target = explode("!", $d[0]);
  1615. $c = $target[0];
  1616. $e = NULL;
  1617. } else {
  1618. $c = $d[2];
  1619. }
  1620. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1621. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1622. unset($error, $editcount, $data, $soxtoolURL, $soxtool, $soxtoolOut, $c, $e, $target);
  1623. } */
  1624. if($d[3] == "{$setTrigger}insult" && hasPriv('insult') && $setInsultUsers) {
  1625. $insultcount++;
  1626. $cmdcount++;
  1627. $error = NULL;
  1628. $insult = @fopen("http://www.pangloss.com/seidel/Shaker/index.html", 'r') OR $error = "Unable to connect to internet. Is it broken by Conficker?";
  1629. $insultOut = NULL;
  1630. if($error) {
  1631. $data = $error;
  1632. } else {
  1633. while(!feof($insult)) {
  1634. if(!$insultOut) {
  1635. $insultOut = fgets($insult);
  1636. } else {
  1637. $insultOut .= fgets($insult);
  1638. }
  1639. }
  1640. $parsed = array();
  1641. $parsed[0] = explode("<font size=\"+2\">", $insultOut);
  1642. $parsed[1] = explode("</font>", $parsed[0][1]);
  1643. $result = strip_tags($parsed[1][0]);
  1644. $data = trim($result);
  1645. }
  1646. $target = explode("!", $d[0]);
  1647. if($d[4] && strcasecmp($d[4], $nick)) {
  1648. $e = $d[4] . ": ";
  1649. } else {
  1650. if(!strcasecmp($d[4], $nick)) {
  1651. $e = $target[0] . ": I refuse to insult myself, so I will now insult you. ";
  1652. } else {
  1653. $e = $target[0] . ": ";
  1654. }
  1655. }
  1656. if($d[2] == $nick) {
  1657. $target = explode("!", $d[0]);
  1658. $c = $target[0];
  1659. $e = NULL;
  1660. } else {
  1661. $c = $d[2];
  1662. }
  1663. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1664. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1665. fclose($insult);
  1666. }
  1667. if($d[3] == "{$setTrigger}status" && hasPriv('*')) {
  1668. $cmdcount++;
  1669. $totalcount = $cmdcount + $pingcount + $ctcpcount + $aicount + $fishcount;
  1670. $uptime['days'] = (time() - $uptime['start'])/86400;
  1671. $uptime['days'] = floor($uptime['days']);
  1672. $uptime['current'] = gmdate('H:i:s', time() - $uptime['start']);
  1673. $uptime['current'] = $uptime['days'] . ' days, ' . $uptime['current'];
  1674. $php_os = PHP_OS;
  1675. $data = "I am bot {$nick}. Software: LizardBot for PHP v{$version} (http://fastlizard4.org/wiki/LizardBot) on OS {$php_os}; Uptime: {$uptime['current']}; I have been used a total of {$totalcount} times (Commands: {$cmdcount} [Of which, {$insultcount} were insult commands], Server pings: {$pingcount}, Recognized CTCPs: {$ctcpcount}, AI calls: {$aicount}, Fishbot calls: {$fishcount}).";
  1676. $target = explode("!", $d[0]);
  1677. $e = $target[0] . ": ";
  1678. if($d[2] == $nick) {
  1679. $target = explode("!", $d[0]);
  1680. $c = $target[0];
  1681. $e = NULL;
  1682. } else {
  1683. $c = $d[2];
  1684. }
  1685. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1686. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1687. }
  1688. if($d[3] == "{$setTrigger}untiny" && hasPriv('tinyurl')) {
  1689. $cmdcount++;
  1690. $tinynumber = $d[4];
  1691. $url = "http://tinyurl.com/preview.php?num={$tinynumber}";
  1692. $tinyurl = @fopen($url, 'r') OR $error = "Unable to connect to TinyURL to make the URL longer. Perhaps the Internet needs help in maing the URL longer; give it some Viagra.";
  1693. $tinyOut = NULL;
  1694. if($error) {
  1695. $data = $error;
  1696. } else {
  1697. while(!feof($tinyurl)) {
  1698. if(!$tinyOut) {
  1699. $tinyOut = fgets($tinyurl);
  1700. } else {
  1701. $tinyOut .= fgets($tinyurl);
  1702. }
  1703. }
  1704. $parsed = array();
  1705. $parsed[0] = explode("<blockquote>", $tinyOut);
  1706. $parsed[1] = explode("</blockquote>", $parsed[0][1]);
  1707. $result = strip_tags($parsed[1][0]);
  1708. $data = trim($result);
  1709. if(!$data) {
  1710. $data = "Error in the input you gave me. Remember that the only parameter this command needs is the NUMBER after http://tinyurl.com/, not the entire TinyURL. Verify that the provided TinyURL ID is valid, and that you even provided an input.";
  1711. }
  1712. }
  1713. $target = explode("!", $d[0]);
  1714. $e = $target[0] . ": ";
  1715. if($d[2] == $nick) {
  1716. $target = explode("!", $d[0]);
  1717. $c = $target[0];
  1718. $e = NULL;
  1719. } else {
  1720. $c = $d[2];
  1721. }
  1722. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1723. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1724. fclose($tinyurl);
  1725. }
  1726. if($d[3] == "{$setTrigger}bit.ly" && hasPriv('bit.ly') && $setEnableBitly && $setBitlyLogin && $setBitlyAPIKey) {
  1727. /* Right then. Here lies the code that allows bit.ly (another URL shortener
  1728. ** interaction. I'm going to try to actually document the code, since it will
  1729. ** be unusually complex. It will use cURL and bit.ly's API, version 3. So, if you're
  1730. ** ready for your brain to be exploded, read on!
  1731. */
  1732. // First thing is that the bit.ly API is rate limited. So, we'll prevent the bot from
  1733. // making an API request too often by noting the time of each request. This will be
  1734. // user configurable.
  1735. $bitlyThisRequestTime = time();
  1736. if($bitlyThisRequestTime - $bitlyLastRequestTime < $setBitlyAPISleep) { //We've exceeded the bot-based ratelimit, so abort.
  1737. $data = "Rate limit exceeded. Please wait a few seconds, or contact the bot's operator to get the limit raised.";
  1738. } else { // Ratelimit OK, proceed
  1739. $bitlyLastRequestTime = $bitlyThisRequestTime;
  1740. // Many of the cURL options (i.e., curl_setopt()) are going to be common across all possible API queries, so we're
  1741. // going to go ahead and start "building" the query
  1742. $apiPipe = curl_init();
  1743. $apiPipeSetoptSuccess = curl_setopt_array($apiPipe, array( // Begin setting cURL Options
  1744. CURLOPT_AUTOREFERER => TRUE ,
  1745. CURLOPT_VERBOSE => TRUE , // So, if necessary, bot operators can read debugging stuff from STDERR
  1746. CURLOPT_CONNECTTIMEOUT => 20 , // 20 seconds for a timeout seems reasonable enough. Lower might be better, though
  1747. CURLOPT_PORT => 80 ,
  1748. // CURLOPT_PROTOCOLS => CURLPROTO_HTTP,
  1749. CURLOPT_TIMEOUT => 30 , // 30 seconds is the maximum amount of time we want to wait for this to work
  1750. CURLOPT_RETURNTRANSFER => TRUE , // I would like my data back, kthx
  1751. CURLOPT_USERAGENT => "LizardBot-PHP/7.3.0.0b (compatible; +http://fastlizard4.org/wiki/LizardBot)" //Set our useragent
  1752. ));
  1753. if(!$apiPipeSetoptSuccess) { // Uhoh, it looks like that, for some reason, configuration of the pipe failed.
  1754. $data = "For some reason, curl_setopt_array() configuration failed. Perhaps you're running an obsolete version of PHP-cURL? Or perhaps your version of PHP is outdated?";
  1755. } else { // Configuration worked, so we're free to continue.
  1756. // First, we set the URL base for all API queries.
  1757. $apiPipeURLBase = 'http://api.bit.ly/v3/';
  1758. // Now, we need to figure out what query we need to run.
  1759. if($d[4] == "shorten") { // User wants to shorten a link
  1760. if(!$d[5]) {
  1761. $data = "A required parameter, the URL to shorten, was not provided. Syntax: @bit.ly shorten URLtoShorten";
  1762. } else {
  1763. $apiPipeRequestURL = $apiPipeURLBase . "shorten?format=json&domain=bit.ly&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
  1764. // Now we need to handle the long URL that needs to be shortened. It must be URL encoded.
  1765. $apiPipeRequestLongUrlE = explode('shorten', $data);
  1766. $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
  1767. $apiPipeRequestURL .= "longUrl={$apiPipeRequestLongUrl}";
  1768. curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
  1769. $apiPipeReturn = curl_exec($apiPipe); // GO!
  1770. $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
  1771. if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
  1772. $data = "Hmm, something went wrong when I tried to shorten your URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
  1773. } else { // Looks like everything ran correctly, so proceed
  1774. if($apiPipeOut['data']['new_hash']) {
  1775. $newHash = "Yes.";
  1776. } else {
  1777. $newHash = "No.";
  1778. }
  1779. $data = "Shortened URL: {$apiPipeOut['data']['url']} - Is this the first time the long URL you entered was shortened? {$newHash}";
  1780. }
  1781. }
  1782. } elseif($d[4] == "expand") { // User wants to expand
  1783. if(!$d[5]) {
  1784. $data = "A required parameter, the (full) URL to expand, was not found. Syntax: @bit.ly expand bit.lyURL";
  1785. } else {
  1786. //This is pretty much a reuse of the shorten code
  1787. $apiPipeRequestURL = $apiPipeURLBase . "expand?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
  1788. $apiPipeRequestLongUrlE = explode('expand', $data);
  1789. $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
  1790. $apiPipeRequestURL .= "shortUrl={$apiPipeRequestLongUrl}";
  1791. curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
  1792. $apiPipeReturn = curl_exec($apiPipe); // GO!
  1793. $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
  1794. if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
  1795. $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
  1796. } else { // Looks like everything ran correctly, so proceed
  1797. if($apiPipeOut['data']['expand'][0]['error']) {
  1798. $data = "The API returned an error for your short URL. Here it is: {$apiPipeOut['data']['expand'][0]['error']}.";
  1799. } else {
  1800. $data = "For the short URL {$apiPipeOut['data']['expand'][0]['short_url']}, the corresponding long URL is: {$apiPipeOut['data']['expand'][0]['long_url']}";
  1801. }
  1802. }
  1803. }
  1804. } elseif($d[4] == "clicks") { // User wants to get clicks for an already existing URL
  1805. if(!$d[5]) {
  1806. $data = "A required parameter, the bit.ly URL to get click data for, was not found. Syntax: @bit.ly clicks bit.lyURL";
  1807. } else {
  1808. //This is pretty much a reuse of the expand code
  1809. $apiPipeRequestURL = $apiPipeURLBase . "clicks?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
  1810. $apiPipeRequestLongUrlE = explode('clicks', $data);
  1811. $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
  1812. $apiPipeRequestURL .= "shortUrl={$apiPipeRequestLongUrl}";
  1813. curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
  1814. $apiPipeReturn = curl_exec($apiPipe); // GO!
  1815. $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
  1816. if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
  1817. $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
  1818. } else { // Looks like everything ran correctly, so proceed
  1819. if($apiPipeOut['data']['clicks'][0]['error']) {
  1820. $data = "The API returned an error for your short URL. Here it is: {$apiPipeOut['data']['clicks'][0]['error']}.";
  1821. } else {
  1822. if($apiPipeOut['data']['clicks'][0]['global_clicks'] == $apiPipeOut['data']['clicks'][0]['user_clicks'] && $apiPipeOut['data']['clicks'][0]['user_clicks'] != 0) {
  1823. $data = "For the short URL {$apiPipeOut['data']['clicks'][0]['short_url']}, which is an \"aggregate\" or \"global\" bit.ly URL, there have been {$apiPipeOut['data']['clicks'][0]['global_clicks']} clicks.";
  1824. } else {
  1825. $data = "For the short URL {$apiPipeOut['data']['clicks'][0]['short_url']}, the number of clicks is {$apiPipeOut['data']['clicks'][0]['user_clicks']} and the number of global clicks on the aggregate (global) bit.ly URL is {$apiPipeOut['data']['clicks'][0]['global_clicks']}.";
  1826. }
  1827. }
  1828. }
  1829. }
  1830. } elseif($d[4] == "checkpro") { // User wants to see if a domain is a bit.ly pro domain
  1831. if(!$d[5]) {
  1832. $data = "A required parameter, the domain to check, was not found. Syntax: @bit.ly checkpro domainToCheck";
  1833. } else {
  1834. //This is pretty much a reuse of the expand code
  1835. $apiPipeRequestURL = $apiPipeURLBase . "bitly_pro_domain?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
  1836. $apiPipeRequestLongUrlE = explode('checkpro', $data);
  1837. $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
  1838. $apiPipeRequestURL .= "domain={$apiPipeRequestLongUrl}";
  1839. curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
  1840. $apiPipeReturn = curl_exec($apiPipe); // GO!
  1841. $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
  1842. if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
  1843. $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
  1844. } else { // Looks like everything ran correctly, so proceed
  1845. if($apiPipeOut['data']['bitly_pro_domain']) {
  1846. $data = "The domain you entered, {$apiPipeOut['data']['domain']}, IS a bitly pro domain.";
  1847. } else {
  1848. $data = "The domain you entered, {$apiPipeOut['data']['domain']}, IS NOT a bitly pro domain.";
  1849. }
  1850. }
  1851. }
  1852. } elseif($d[4] == "lookup") { // User wants to lookup an already existing bit.ly link for a long URL
  1853. if(!$d[5]) {
  1854. $data = "A required parameter, the long URL to check, was not found. Syntax: @bit.ly lookup longURL";
  1855. } else {
  1856. //This is pretty much a reuse of the expand code
  1857. $apiPipeRequestURL = $apiPipeURLBase . "lookup?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
  1858. $apiPipeRequestLongUrlE = explode('lookup', $data);
  1859. $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
  1860. $apiPipeRequestURL .= "url={$apiPipeRequestLongUrl}";
  1861. curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
  1862. $apiPipeReturn = curl_exec($apiPipe); // GO!
  1863. $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
  1864. if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
  1865. $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
  1866. } else { // Looks like everything ran correctly, so proceed
  1867. if($apiPipeOut['data']['lookup'][0]['error']) {
  1868. $data = "The API returned an error for your long URL. Here it is: {$apiPipeOut['data']['lookup'][0]['error']}. If this is NOT_FOUND, it means that no bit.ly URL yet exists for the long URL you entered.";
  1869. } else {
  1870. $data = "For the long URL {$apiPipeOut['data']['lookup'][0]['url']}, the following bit.ly short URL already exists: {$apiPipeOut['data']['lookup'][0]['short_url']}";
  1871. }
  1872. }
  1873. }
  1874. } elseif($d[4] == "info") { // User wants to get info
  1875. if(!$d[5]) {
  1876. $data = "A required parameter, the bit.ly URL to get info for, was not found. Syntax: @bit.ly info bit.lyURL";
  1877. } else {
  1878. //This is pretty much a reuse of the shorten code
  1879. $apiPipeRequestURL = $apiPipeURLBase . "info?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
  1880. $apiPipeRequestLongUrlE = explode('info', $data);
  1881. $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
  1882. $apiPipeRequestURL .= "shortUrl={$apiPipeRequestLongUrl}";
  1883. curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
  1884. $apiPipeReturn = curl_exec($apiPipe); // GO!
  1885. $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
  1886. if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
  1887. $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
  1888. } else { // Looks like everything ran correctly, so proceed
  1889. if($apiPipeOut['data']['info'][0]['error']) {
  1890. $data = "The API returned an error for your short URL. Here it is: {$apiPipeOut['data']['info'][0]['error']}.";
  1891. } else {
  1892. if($apiPipeOut['data']['info'][0]['created_by'] == "bitly") {
  1893. $data = "For the short URL {$apiPipeOut['data']['info'][0]['short_url']}, the page title is: \"{$apiPipeOut['data']['info'][0]['title']}\". The bit.ly URL is an aggregate URL.";
  1894. } else {
  1895. $data = "For the short URL {$apiPipeOut['data']['info'][0]['short_url']}, the page title is: \"{$apiPipeOut['data']['info'][0]['title']}\" and the bit.ly URL was created by the bit.ly user \"{$apiPipeOut['data']['info'][0]['created_by']}\".";
  1896. }
  1897. }
  1898. }
  1899. }
  1900. } else {
  1901. $data = "A required parameter, the action, was not provided. Syntax: @bit.ly action [otherArguments]";
  1902. }
  1903. }
  1904. }
  1905. curl_close($apiPipe); //End the cURL session
  1906. $target = explode("!", $d[0]);
  1907. $e = $target[0] . ": ";
  1908. if($d[2] == $nick) {
  1909. $target = explode("!", $d[0]);
  1910. $c = $target[0];
  1911. $e = NULL;
  1912. } else {
  1913. $c = $d[2];
  1914. }
  1915. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1916. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1917. }
  1918. if($d[3] == "{$setTrigger}fish" && hasPriv('*')) {
  1919. $cmdcount++;
  1920. if($setEnableFishbot) {
  1921. $data = "Fishb0t module is enabled.";
  1922. } else {
  1923. $data = "Fishb0t module is disabled.";
  1924. }
  1925. $target = explode("!", $d[0]);
  1926. $e = $target[0] . ": ";
  1927. if($d[2] == $nick) {
  1928. $target = explode("!", $d[0]);
  1929. $c = $target[0];
  1930. $e = NULL;
  1931. } else {
  1932. $c = $d[2];
  1933. }
  1934. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1935. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1936. }
  1937. if($d[3] == "{$setTrigger}fish-on" && hasPriv('mute')) {
  1938. $setEnableFishbot = TRUE;
  1939. $data = "Fishb0t enabled!";
  1940. $target = explode("!", $d[0]);
  1941. $e = $target[0] . ": ";
  1942. if($d[2] == $nick) {
  1943. $target = explode("!", $d[0]);
  1944. $c = $target[0];
  1945. $e = NULL;
  1946. } else {
  1947. $c = $d[2];
  1948. }
  1949. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1950. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1951. }
  1952. if($d[3] == "{$setTrigger}fish-off" && hasPriv('mute')) {
  1953. $setEnableFishbot = FALSE;
  1954. $data = "Fishb0t disabled!";
  1955. $target = explode("!", $d[0]);
  1956. $e = $target[0] . ": ";
  1957. if($d[2] == $nick) {
  1958. $target = explode("!", $d[0]);
  1959. $c = $target[0];
  1960. $e = NULL;
  1961. } else {
  1962. $c = $d[2];
  1963. }
  1964. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  1965. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  1966. }
  1967. if($setEnableReminders && $setEnableMySQL) {
  1968. if(!is_array($reminder)) { //Build the array from database
  1969. $reminder = array();
  1970. $query = "SELECT `reminder_id`, `reminder_target_nick` FROM `{$setMySQLTablePre}reminders` ORDER BY `reminder_id` ASC";
  1971. $mysql = dbConnect();
  1972. $r = dbQuery($mysql, $query, $result);
  1973. if($r) {
  1974. $setEnableReminders = false; //This is a sorta permament error
  1975. } else {
  1976. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  1977. $reminder[$row['reminder_id']] = $row['reminder_target_nick'];
  1978. }
  1979. mysqli_free_result($result);
  1980. }
  1981. mysqli_close($mysql);
  1982. }
  1983. //Code to allow adding reminders:
  1984. if($d[3] == "{$setTrigger}remind" && hasPriv('remind')) {
  1985. $reminderReminder = $d[0];
  1986. $target = explode("!", $d[0]);
  1987. $e = $target[0] . ": ";
  1988. if($d[2] == $nick) {
  1989. $target = explode("!", $d[0]);
  1990. $c = $target[0];
  1991. $e = NULL;
  1992. } else {
  1993. $c = $d[2];
  1994. }
  1995. if(!$d[5]) {
  1996. $data = "ERROR: Too few parameters for the @remind command. Syntax: @remind <target> <message>";
  1997. } else {
  1998. $reminderTarget = $d[4];
  1999. $reminderText = explode("{$setTrigger}remind {$d[4]}", $data);
  2000. $reminderText = trim($reminderText[1]);
  2001. $reminderTime = gmdate("Y-m-d H:i:s");
  2002. $d[0] = NULL; //Clear this so that the bot doesn't instantly remind the requester if the reminder is a self-reminder
  2003. //Ok, we have all the variables we need, so sanitize input and build the query:
  2004. $mysql = dbConnect();
  2005. if(!$mysql) { $data = "Eror connecting to MySQL."; }
  2006. $reminderTarget = mkSane($mysql, $reminderTarget);
  2007. $reminderReminder = mkSane($mysql, $reminderReminder);
  2008. $reminderText = mkSane($mysql, $reminderText);
  2009. $reminderTime = mkSane($mysql, $reminderTime);
  2010. //Get the definitions set up
  2011. $query = "INSERT INTO `{$setMySQLTablePre}reminders` (`reminder_text`, `reminder_target_nick`, `reminder_time`, `reminder_requester`) VALUES ('{$reminderText}', '{$reminderTarget}', '{$reminderTime}', '{$reminderReminder}')";
  2012. if(dbQuery($mysql, $query, $result)) {
  2013. //Fail!
  2014. $data = "An error occured executing the database query. Check the console for details.";
  2015. } else {
  2016. //Success
  2017. //Reload the array!
  2018. $reminders = array();
  2019. $reminder = array();
  2020. $query = "SELECT `reminder_id`, `reminder_target_nick` FROM `{$setMySQLTablePre}reminders` ORDER BY `reminder_id` ASC";
  2021. $r = dbQuery($mysql, $query, $result);
  2022. $data = NULL;
  2023. if($r) {
  2024. $data = "Hmm, there was an error reloading the array.... ";
  2025. } else {
  2026. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  2027. $reminder[$row['reminder_id']] = $row['reminder_target_nick'];
  2028. }
  2029. mysqli_free_result($result);
  2030. }
  2031. if($setRemindOnJoin) {
  2032. $orJoin = "or join ";
  2033. } else {
  2034. unset($orJoin);
  2035. }
  2036. $data .= "OK, I'll tell them the next time I see them talk in {$orJoin}a channel I'm in.";
  2037. }
  2038. unset($result);
  2039. mysqli_close($mysql);
  2040. }
  2041. fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
  2042. echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
  2043. }
  2044. //Code to allow retrieval of reminders, ignoring PMs to the bot
  2045. if(($d[1] == "PRIVMSG" || ($d[1] == "JOIN" && $setRemindOnJoin)) && $d[2] != $nick) {
  2046. $success = false;
  2047. $t = explode('!', $d[0]);
  2048. $userNick = $t[0];
  2049. $t = explode('@', $d[0]);
  2050. $userHost = $t[1];
  2051. $data = NULL;
  2052. foreach($reminder as $id => $target) {
  2053. if(stristr($userNick, $target) || stristr($userHost, $target) == $target) {
  2054. //We have a winner!
  2055. $mysql = dbConnect();
  2056. $query = "SELECT `reminder_text`, `reminder_time`, `reminder_requester` FROM `{$setMySQLTablePre}reminders` WHERE `reminder_target_nick`='{$target}'";
  2057. if(dbQuery($mysql, $query, $result)) {
  2058. //FAIL!
  2059. $data = "An error occured in the database query. Check the console for details.";
  2060. } else {
  2061. //Success!
  2062. $success = true;
  2063. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  2064. $message = "{$userNick}: {$row['reminder_requester']} asked me at {$row['reminder_time']} (Y-M-D H:M:S, UTC) to tell you {$row['reminder_text']}";
  2065. fwrite($ircc, "PRIVMSG {$d[2]} :{$message}\r\n");
  2066. }
  2067. mysqli_free_result($result);
  2068. }
  2069. //...now delete those messages from the database.
  2070. if($success) {
  2071. $query = "DELETE FROM `{$setMySQLTablePre}reminders` WHERE `reminder_target_nick`='{$target}'";
  2072. dbQuery($mysql, $query, $result); unset($result);
  2073. }
  2074. mysqli_close($mysql);
  2075. }
  2076. }
  2077. if($success) { //Reload the arrays now, too
  2078. $reminder = array();
  2079. $query = "SELECT `reminder_id`, `reminder_target_nick` FROM `{$setMySQLTablePre}reminders` ORDER BY `reminder_id` ASC";
  2080. $mysql = dbConnect();
  2081. $r = dbQuery($mysql, $query, $result);
  2082. if($r) {
  2083. //Do nothing, it shouldn't cause *that* much harm....
  2084. } else {
  2085. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  2086. $reminder[$row['reminder_id']] = $row['reminder_target_nick'];
  2087. }
  2088. mysqli_free_result($result);
  2089. }
  2090. mysqli_close($mysql);
  2091. }
  2092. }
  2093. }
  2094. if($setEnableFishbot && hasPriv('fish')) {
  2095. $stop = FALSE;
  2096. $target = explode("!", $d[0]);
  2097. $e = $target[0];
  2098. if($d[2] == $nick) {
  2099. $target = explode("!", $d[0]);
  2100. $c = $target[0];
  2101. $e = NULL;
  2102. } else {
  2103. $c = $d[2];
  2104. }
  2105. unset($d[0], $d[1], $d[2]);
  2106. $fishdata = trim(implode(" ", $d));
  2107. if($fishdata) {
  2108. $data = NULL;
  2109. if(preg_match("/" . chr(001) . "ACTION.*/i", $fishdata)) {
  2110. //Type is CTCP ACTION
  2111. //$after = explode("\001ACTION", $d[3]);
  2112. //$new = explode("\001", $after[1]);
  2113. //$toProcess = trim($new[0]);
  2114. $toProcess = str_replace(array("\001ACTION ","\001"), array('',''), $fishdata);
  2115. /*
  2116. foreach($fishAresponses AS $regex => $response) {
  2117. if(preg_match($regex, $toProcess)) {
  2118. $data = $response;
  2119. } else {
  2120. $data = NULL;
  2121. }
  2122. } */
  2123. foreach($fishAresponses as $regex2 => $mtpl) {
  2124. $regex = str_replace('%f', preg_quote($nick, '/'), $regex2);
  2125. if(preg_match($regex,$toProcess,$m) && !$stop) {
  2126. $data = str_replace(array('%n','%c','%1'),array($e,$c,$m[1]),$mtpl);
  2127. $stop = TRUE;
  2128. }
  2129. }
  2130. } else {
  2131. //Type is standard message
  2132. /*
  2133. foreach($fishCresponses AS $regex => $response) {
  2134. if(preg_match($regex, trim($d[3]))) {
  2135. $data = $response;
  2136. } else {
  2137. $data = NULL;
  2138. }
  2139. }*/
  2140. foreach($fishCresponses as $regex2 => $mtpl) {
  2141. $regex = str_replace('%f', preg_quote($nick, '/'), $regex2);
  2142. if(preg_match($regex,$fishdata,$m) && !$stop) {
  2143. $data = str_replace(array('%n','%c','%1'),array($e,$c,$m[1]),$mtpl);
  2144. $stop = TRUE;
  2145. }
  2146. }
  2147. }
  2148. if($data) {
  2149. fwrite($ircc, "PRIVMSG $c :" . $data . "\r\n");
  2150. echo "-!- PRIVMSG $c :" . $data . "\r\n";
  2151. $fishcount++;
  2152. }
  2153. }
  2154. unset($fishdata, $toProcess);
  2155. }
  2156. }
  2157. if($d[3] == "{$setTrigger}mute" && hasPriv('mute')) {
  2158. $cmdcount++;
  2159. $target = explode("!", $d[0]);
  2160. $target2 = $target[0];
  2161. if(!stristr($d[2], "#")) {
  2162. $c = $target2[0];
  2163. }
  2164. $muted = $users['*!*@*'];
  2165. $users['*!*@*'] = 'ignore';
  2166. fwrite($ircc, "PRIVMSG $c :$target2: Bot now muted.\r\n");
  2167. }
  2168. if($d[3] == "{$setTrigger}unmute" && hasPriv('mute')) {
  2169. $cmdcount++;
  2170. $target = explode("!", $d[0]);
  2171. $target2 = $target[0];
  2172. if(!stristr($d[2], "#")) {
  2173. $c = $target2[0];
  2174. }
  2175. $users['*!*@*'] = $muted;
  2176. $muted = NULL;
  2177. fwrite($ircc, "PRIVMSG $c :$target2: Bot now unmuted.\r\n");
  2178. }
  2179. }