KeiroD

bone282

Dec 19th, 2009
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 29.34 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6. /***** USER SETTINGS START *****/
  7.  
  8.  
  9. $GLOBALS['config'] = array();
  10.  
  11.  
  12. /* Connection & Typical Settings. */
  13. $GLOBALS['config']['server']        = "irc.shatteredtears.com";
  14. $GLOBALS['config']['port']          = 6667;
  15. $GLOBALS['config']['botname']       = "";
  16. $GLOBALS['config']['realname']      = "PHP Bot";
  17. $GLOBALS['config']['password']      = "";
  18. $GLOBALS['config']['emailadd']      = "";
  19. $GLOBALS['config']['bot_owner']     = "";
  20. $GLOBALS['config']['user_modes']    = "+R";
  21.  
  22. /* Do Not Edit This Line. */
  23. $GLOBALS['config']['authd_user']    = array();
  24.  
  25. /* Add Authd Users Here.
  26. (extend the list if you wish) */
  27. $GLOBALS['config']['authd_user'][1] = "";
  28. $GLOBALS['config']['authd_user'][2] = "";
  29. $GLOBALS['config']['authd_user'][3] = "";
  30.  
  31. /* Quit Message. */
  32. $GLOBALS['config']['quit_message']  = "";
  33.  
  34. /* Autojoin Rooms.
  35. (extend the list if you wish) */
  36. $GLOBALS['config']['autojoin'][1] = "";
  37. $GLOBALS['config']['autojoin'][2] = "";
  38. $GLOBALS['config']['autojoin'][3] = "";
  39. $GLOBALS['config']['autojoin'][4] = "";
  40. $GLOBALS['config']['autojoin'][5] = "";
  41.  
  42.  
  43.  
  44. /* Bot Commands Prefix. */
  45. $pf = ".";
  46.  
  47. /* Max String Length The IRC Server Will Allow Per Line. */
  48. $MaxStrlen = 340;
  49.  
  50. /* Pandora Ai Bot Identities. */
  51. //botid name: Tom Riddle      key: c96f911b3e35f9e1
  52. //botid name: ALiCE             key: f5d922d97e345aa1 key: 890e7e46de354b3c
  53. //botid name: Zog (alien)      key: c1baddb74e35ebd0
  54. //botid name: LOLA              key: 9848c44e7e366751
  55. //botid name: steve atkins    key: e49a37390e35f8d4
  56. //botid name: meghan           key: a814d6c1ce361ff9
  57. //botid name: g. bot             key: f48cf50a3e345c5a
  58. //botid name: afrobot           key: 9d3dc63c7e34956d
  59. //botid name: einstein          key: ea77c0200e365cfb
  60. //botid name: santa             key: e389e9f48e360811
  61. //botid name gwen stefani    key: eacb36ccde34ac59
  62. //botid name: ben franklin    key: d06aabcbae3682d3
  63. //botid name: hotbot            key: 9b288cb0ee36f4cc
  64. //botid name: Tony (mobster) key: b33924685e3544b6
  65. //botid name: Uncivilized       key: b21c22c62e34ac34
  66.  
  67. //Pick a bot id/key from the list above.
  68. $AIBotID = "b21c22c62e34ac34";
  69.  
  70. /* AI Chat. */
  71. $AIChat = false;
  72.  
  73.  
  74.  
  75.  
  76. /***** USER SETTINGS END *****/
  77.  
  78. /* A Var For The Login. */
  79. $startup = 0;
  80.  
  81. /* Define The Socket. */
  82. $socket = ircConnect();
  83.  
  84. /* Font Type Variables Array. */
  85. $font['n'] = "\x0f";// normal font & color.
  86. $font['b'] = "\x02";// bold.
  87. $font['u'] = "\x1f";// underline.
  88. $font['k'] = chr(3);// mIRC Equivalent Of Ctrl+K.
  89.  
  90. $inchan = false;
  91.  
  92. /* Main Loop. */
  93. while(1){
  94.     /* Read Server Data. */
  95.     $buffer = @socket_read($socket, 256, 0);
  96.    
  97.     /* Print All Data */
  98.     echo date('H:i:s')." - ".$buffer;
  99.     file_put_contents("log.txt", date('H:i:s')." - ".$buffer, FILE_APPEND);
  100.    
  101.     /* Force Reconnection if Ping Timeout. */
  102.     if ($buffer == false){ socket_close($socket); $socket = ircConnect(); }
  103.    
  104.     /* Seperate All Data */
  105.     preg_match("/^:(.*?)!(.*?)@(.*?)[\s](.*?)[\s](.*?)[\s]:(.*?)$/",$buffer, $rawdata);
  106.     $nick = $rawdata[1];
  107.     $ident = $rawdata[2];
  108.     $host = $rawdata[3];
  109.     $msg_type = $rawdata[4];
  110.     $chan = $rawdata[5];
  111.     $args = trim($rawdata[6]);
  112.  
  113.     /* Split Data Into An Array. */
  114.     $ex = explode(' ', $buffer);
  115.  
  116.     /* Send PONG Back To The Server. */
  117.     if($ex[0] == "PING"){
  118.         SockSend($socket, "PONG ".trim($ex[1]));
  119.         if ($inchan == false){
  120.             IdentifyAndJoin($socket);
  121.             $inchan = true;
  122.             }
  123.         }
  124.     if(preg_match('/\nPING\s:(.*?)\n/', $buffer, $match)){
  125.         SockSend($socket, "PONG :".trim($match[1]));
  126.         if ($inchan == false){
  127.             IdentifyAndJoin($socket);
  128.             $inchan = true;
  129.             }
  130.         }
  131.  
  132.    
  133.     /* Rejoin On Kick. */
  134.     if ($ex[1] == "KICK"){ SockSend($socket, "JOIN ".trim($ex[2])); }
  135.  
  136.     /* Handle A Private Message 'PM'. */
  137.     if ($chan == $GLOBALS['config']['botname']){ $chan = $nick; }
  138.    
  139.  
  140.     /* Create The Trigger. */
  141.     $args = explode(" ", $args);
  142.     $trigger = array_shift($args);
  143.     $args = implode(" ", $args);
  144.  
  145.     /* Create A Switch For  The Trigger. */
  146.     switch (strtolower($trigger)){
  147.  
  148.         /*** Owner Commands Start. ***/
  149.  
  150.         /* Quit Irc. */
  151.         case $pf."quit":
  152.             if ($nick == $GLOBALS['config']['bot_owner']){
  153.                 if ($args == ''){
  154.                     SockSend($socket, "QUIT :".$GLOBALS['config']['quit_message']);
  155.                 } else {
  156.                     SockSend($socket, "QUIT :".$args);
  157.                     }
  158.                 die('Terminating Client Session . . .');
  159.                 }
  160.             break;
  161.  
  162.         /* Restart Client */
  163.         case $pf."restart":
  164.             if ($nick == $GLOBALS['config']['bot_owner']){
  165.                 socket_close($socket); $socket = ircConnect();
  166.                 }
  167.             break;
  168.  
  169.         /* Add, Del, List, Authd User. */
  170.         case $pf."auth":
  171.             if ($nick == $GLOBALS['config']['bot_owner']){
  172.                 $args = explode(" ", $args);
  173.                 $authcmd = array_shift($args);
  174.                 $args = implode(" ", $args);
  175.                 switch(strtolower($authcmd)){
  176.                     case "add":
  177.                         if ($args == '') {
  178.                             NOTICE($nick, $font['b']."You must supply a nick you want adding to the list");
  179.                         } elseif (in_array($args, $GLOBALS['config']['authd_user'], true)){
  180.                             NOTICE($nick, $font['b']."".$args." is already in the authd user list.");
  181.                         } else {
  182.                             array_push($GLOBALS['config']['authd_user'], $args);
  183.                             NOTICE($nick, $font['b']."".$args." added to temp authd user list.");
  184.                             }
  185.                         break;
  186.                     case "del":
  187.                         if ($args == '') {
  188.                             NOTICE($nick, $font['b']."You must supply a nick you want deleting from the list.");
  189.                         } elseif (in_array($args, $GLOBALS['config']['authd_user'], true)){
  190.                             foreach($GLOBALS['config']['authd_user'] as $k => $v){
  191.                                 if ($v == $args){
  192.                                     unset($GLOBALS['config']['authd_user'][$k],$GLOBALS['config']['authd_user'][$v]);
  193.                                     NOTICE($nick, $font['b']."".$args." deleted from temp authd user list.");
  194.                                 }
  195.                             }
  196.                         } else {
  197.                             NOTICE($nick, $font['b']."".$args." not found in temp authd user list.");
  198.                             }
  199.                         break;
  200.                     case "list":
  201.                         NOTICE($nick, $font['b']."".$GLOBALS['config']['botname']."'s Auth'd User list.");
  202.                         NOTICE($nick, $font['b']."    Num  Nick");
  203.                         foreach($GLOBALS['config']['authd_user'] as $k => $v){
  204.                             if ($v == ''){ $v = 'Not Set..'; }
  205.                             if ($k > 9){
  206.                                 NOTICE($nick, $font['b']."     ".$k."  ".$v);
  207.                             } else {
  208.                                 NOTICE($nick, $font['b']."      ".$k."  ".$v);
  209.                                 }  
  210.                             }
  211.                         break;
  212.                     default:
  213.                         NOTICE($nick, $font['b']."Auth Commands Help.");
  214.                         NOTICE($nick, $font['b']."".$pf."auth add nick");
  215.                         NOTICE($nick, $font['b']."".$pf."auth del nick");
  216.                         NOTICE($nick, $font['b']."".$pf."auth list");
  217.                         break;
  218.                     }
  219.                 }
  220.             break;
  221.        
  222.        
  223.         /* Ai Chat. */
  224.         case $pf."ai":
  225.             if ($nick == $GLOBALS['config']['bot_owner']){
  226.                 $word = explode(" ", $args);
  227.                 switch(strtolower($word[0])){
  228.                     case "on":
  229.                         if ($AIChat === true){ NOTICE($nick, $font['b']."AI Chat Is Already Enabled."); } else { $AIChat = true; NOTICE($nick, $font['b']."AI Chat Enabled."); }
  230.                         break;
  231.                     case "off":
  232.                         if ($AIChat === false){ NOTICE($nick, $font['b']."AI Chat Is Already Disabled."); } else { $AIChat = false; NOTICE($nick, $font['b']."AI Chat Disabled."); }
  233.                         break;
  234.                     }
  235.                 }
  236.             break;
  237.  
  238.         /* Exec PHP code. Use 'Print'. */
  239.         case $pf."eval":
  240.             if ($nick == $GLOBALS['config']['bot_owner']){
  241.                 PRIVMSG($chan, $nick.": ".EvalBuffer($args));
  242.                 }
  243.             break;
  244.  
  245.         /*** Owner Commands End. ***/
  246.         /*** Auth'd & Owner Commands Start. ***/
  247.  
  248.         /* Join Room. */
  249.         case $pf."join":
  250.             if ($nick == $GLOBALS['config']['bot_owner'] || in_array($nick, $GLOBALS['config']['authd_user'])){
  251.                 if (preg_match("%^#[A-Za-z0-9\\\/.\-_']+$%", $args)){
  252.                     PRIVMSG($chan, "Joining ".$args);
  253.                     SockSend($socket, "JOIN ".$args);
  254.                 } else {
  255.                     PRIVMSG($chan, $args." Invalid room name.");
  256.                 }
  257.             }
  258.             break;
  259.  
  260.         /* Part Room. */
  261.         case $pf."part":
  262.             if ($nick == $GLOBALS['config']['bot_owner'] || in_array($nick, $GLOBALS['config']['authd_user'])){
  263.                 if ($args == ''){
  264.                     PRIVMSG($chan, "Parting ".$chan);
  265.                     SockSend($socket, "PART ".$chan);
  266.                 } else {
  267.                     if (preg_match("%^#[A-Za-z0-9\\\/.\-_']+$%", $args)){
  268.                         PRIVMSG($chan, "Parting ".$args);
  269.                         SockSend($socket, "PART ".$args);
  270.                     } else {
  271.                         PRIVMSG($chan, $args." Invalid room name.");
  272.                         }
  273.                     }
  274.                 }
  275.             break;
  276.  
  277.         /* Change The Commands Trigger. */
  278.         case $pf."trigger":
  279.             if ($nick == $GLOBALS['config']['bot_owner'] || in_array($nick, $GLOBALS['config']['authd_user'])){
  280.                 if (strlen($args) === 1){
  281.                     $pf = $args;
  282.                     PRIVMSG($chan, "Trigger changed to: ".$pf);
  283.                 } else {
  284.                     NOTICE($nick, $font['b']."You may only set 1 character as the commands trigger.");
  285.                     }
  286.                 }
  287.             break;
  288.  
  289.         /*** Auth'd & Owner Commands End. ***/
  290.         /*** All User Commands Start. ***/
  291.  
  292.         /* TinyUrl. */
  293.         case $pf."tinyurl":
  294.             PRIVMSG($chan, TinyUrl($args));
  295.             break;
  296.  
  297.         /* Random Facts. */
  298.         case $pf."jack":
  299.             Truncate(JackBauer(), $chan);
  300.             break;
  301.         case $pf."chuck":
  302.         case $pf."mrt":
  303.         case $pf."vin":
  304.             $Person = ltrim($trigger, $pf);
  305.             Truncate(RandomFacts($Person), $chan);
  306.             break;
  307.  
  308.         /* Weather. */
  309.         case $pf."wz":
  310.             PRIVMSG($chan, WunderGround($args, $nick));
  311.             break;
  312.  
  313.         /* Urban Dictionary. */
  314.         case $pf."urban":
  315.             UrbanDict($args, $chan);
  316.             break;
  317.  
  318.         /* Google search. */
  319.         case $pf."gs":
  320.         case $pf."google":
  321.             if($trigger == $pf."google"){ GoogleSearch($args, $chan, 3); } else { GoogleSearch($args, $chan, 1); }
  322.             break;
  323.  
  324.         /* Site search. (3 results) */
  325.         case $pf."youtube":
  326.         case $pf."discogs":
  327.         case $pf."imdb":
  328.             GoogleSearch($args, $chan, 3, $siteSearch = ltrim($trigger, $pf));
  329.             break;
  330.  
  331.         /* Site Search. (1 result)  */
  332.         case $pf."php":
  333.             GoogleSearch($args, $chan, 1, $siteSearch = ltrim($trigger, $pf));
  334.             break;
  335.  
  336.         /* Acronyms. */
  337.         case $pf."acro":
  338.             Acronyms($args, $chan);
  339.             break;
  340.            
  341.         /* Port Scan. */
  342.         case $pf."port":
  343.             list($host, $port) = explode(' ', $args);
  344.             if(empty($port)){
  345.                 list($host, $port) = explode(':', $args);
  346.                 }
  347.             Portscan($host, $port, $chan);
  348.             break;
  349.            
  350.         /* Google Calculator. */
  351.         case $pf."calc":
  352.             PRIVMSG($chan, GoogleCalc($args));
  353.             break;
  354.            
  355.         /* Wikipedia. */
  356.         case $pf."wiki":
  357.             Wikipedia($args, $chan);
  358.             break;
  359.            
  360.         /* Imdb Quotes. */
  361.         case $pf."quote":
  362.             ImdbQuotes($args, $chan);
  363.             break;
  364.        
  365.         /*Google Traslator. */
  366.         case $pf."trans":
  367.             $words = explode(" ", $args);
  368.             if (count($words) < 3) {
  369.                 PRIVMSG($chan, "Please ".$pf."trans langfrom langto yourtextyouwanttranslating");
  370.                 break;
  371.                 }
  372.             $from = array_shift($words);
  373.             $to = array_shift($words);
  374.             $words = implode(" ", $words);
  375.             translate($from, $to, $words, $chan);
  376.             break;
  377.            
  378.         default:
  379.             if ($AIChat == true && $msg_type == 'PRIVMSG'){
  380.                 $chatter = $trigger.' '.$args;
  381.                 $message = aichat($chatter, $nick);
  382.                 if ($message){ PRIVMSG($chan, $message); }
  383.                 }
  384.             break;
  385.  
  386.         /*** All User Commands End. ***/
  387.  
  388.         } // End Of Switch.
  389.     }
  390.  
  391. /* Irc Connect. */
  392. function ircConnect(){
  393.     global $startup;
  394.     if($startup == 1){ print("Restarting Client . . .\n"); }
  395.     if($startup == 0){ print("Starting Client Session . . .\n".date('l jS \of F Y H:i:s')."\n"); $startup = 1; }
  396.  
  397.     /* Create a TCP/IP Socket. */
  398.     print(date('H:i:s')." - Creating Socket...\n");
  399.     $socket = @socket_create( AF_INET, SOCK_STREAM, 0);
  400.     if ($socket < 0) {
  401.         print(date('H:i:s')." - \"socket_create()\" failed.\nReason: ".socket_strerror($socket)."\n");
  402.         exit;
  403.     } else {
  404.         print(date('H:i:s')." - OK!\n");
  405.     }
  406.    
  407.     /* Attempt To Connect To Server. */
  408.     print(date('H:i:s')." - Attempting to Connect to ".$GLOBALS['config']['server']." on Port ".$GLOBALS['config']['port']."...\n");
  409.     $result = @socket_connect($socket, $GLOBALS['config']['server'], $GLOBALS['config']['port']);
  410.     if ($result === FALSE) {
  411.         print(date('H:i:s')." - \"socket_connect()\" failed.\nReason: ".socket_strerror($result)."\n");
  412.         exit;
  413.     } else {
  414.         print(date('H:i:s')." - OK!\n");   
  415.     }
  416.     ircLogin($socket);
  417.    
  418.     /* Return Socket. */
  419.     return $socket;
  420.     }
  421.  
  422. function ircLogin($socket){
  423.     /* Login. */
  424.     print(date('H:i:s')." - Sending Login Data...\n");
  425.     if (empty($GLOBALS['config']['botname'])){ print(date('H:i:s')." - Exiting Client. . .\nReason: The Bot Name Has Not Been Set . . ."); exit; }
  426.     if (empty($GLOBALS['config']['bot_owner'])){ print(date('H:i:s')." - Exiting Client. . .\nReason: The Bot Owner Has Not Been Set . . ."); exit; }
  427.     SockSend($socket, "USER ".strtolower($GLOBALS['config']['botname'])." ".strtolower($GLOBALS['config']['botname'])." ".strtolower($GLOBALS['config']['botname'])." :".$GLOBALS['config']['realname'], "login");
  428.     SockSend($socket, "NICK ".$GLOBALS['config']['botname'], "login");
  429.     sleep(2);
  430.     }
  431.    
  432. function IdentifyAndJoin($socket){
  433.     if (!empty($GLOBALS['config']['password'])){ SockSend($socket, "PRIVMSG NICKSERV :IDENTIFY ".$GLOBALS['config']['password']); }
  434.     if (!empty($GLOBALS['config']['user_modes'])){ SockSend($socket, "MODE ".$GLOBALS['config']['botname']." ".$GLOBALS['config']['user_modes']); }
  435.     print(date('H:i:s')." - Attempting To Join Rooms...\n");
  436.     foreach ($GLOBALS['config']['autojoin'] as $key => $rooms){
  437.         if ($rooms != ''){
  438.             SockSend($socket,"JOIN ".$rooms, "login");
  439.             }
  440.         }
  441.     return;
  442.     }
  443.  
  444. /* print(Infos @Browser. */
  445. function PrintData($Message, $User = null){
  446.     global $msg_type,$chan;
  447.     $Time = date('H:i:s');
  448.     if ($User === null){
  449.         $User = $GLOBALS['config']['botname'];
  450.         $Print = $Time." - ".$User." ".$Message;
  451.     } else {
  452.         $Print = $Time." - ".$User." ".$msg_type." ".$chan." :".$Message."\n";
  453.         }
  454.     print($Print);
  455.     }
  456.  
  457. /* Socket Send: Login, Join, Parts, Quits, Etc. */
  458. function SockSend($socket, $data, $login = null){
  459.     $data = $data."\n";
  460.     if(@socket_send($socket, $data , strlen($data), 0) == true){
  461.     } else {
  462.         if($login == 'login'){
  463.             print(date('H:i:s')." - \"socket_send()\" failed. (Throttled: Reconnecting too fast?)...\nTry Reconnecting In A Minute . . .\n");
  464.             exit;
  465.         } else {
  466.             print(date('H:i:s')." - \"send failed.\nReason: ".socket_strerror($socket)."\n");
  467.             exit;
  468.             }
  469.         }
  470.     PrintData($data);
  471.     }
  472.  
  473. /* Privmsg. */
  474. function PRIVMSG($msgTarget, $msgContents){
  475.     global $socket;
  476.     $msgData = "PRIVMSG ".$msgTarget." :".$msgContents."\n";
  477.     socket_send($socket, $msgData, strlen($msgData), 0);
  478.     PrintData($msgData);
  479.     }
  480.  
  481. /* Notice. */
  482. function NOTICE($msgTarget, $msgContents){
  483.     global $socket;
  484.     $msgData = "NOTICE ".$msgTarget." :".$msgContents."\n";
  485.     socket_send($socket, $msgData, strlen($msgData), 0);
  486.     PrintData($msgData);
  487.     }
  488.  
  489. /* Chanserv. */
  490. function CHANSERV($msgContents){
  491.     global $socket;
  492.     $msgData = "CHANSERV ".$msgContents."\n";
  493.     socket_send($socket, $msgData, strlen($msgData), 0);
  494.     PrintData($msgData);
  495.     }
  496.  
  497. /* Nickserv. */
  498. function NICKSERV($msgContents){
  499.     global $socket;
  500.     $msgData = "PRIVMSG NICKSERV ".$msgContents."\n";
  501.     socket_send($socket, $msgData, strlen($msgData), 0);
  502.     PrintData($msgData);
  503.     }
  504.  
  505. /* Mode. */
  506. function MODE($msgContents){
  507.     global $socket;
  508.     $msgData = "MODE ".$msgContents."\n";
  509.     socket_send($socket, $msgData, strlen($msgData), 0);
  510.     PrintData($msgData);
  511.     }
  512.  
  513.  
  514. /*** General Functions. ***/
  515.  
  516.  
  517. /* Eval. */
  518. function EvalBuffer($code){
  519.     @trigger_error("");
  520.     ob_start();
  521.     eval($code);
  522.     $code = ob_get_contents();
  523.     ob_end_clean();
  524.     $e = error_get_last();
  525.     if ($e['message'] and $e['type'] != 2048){
  526.         return '['.$e['type'].'] '.strip_tags($e['message']);
  527.     } else {
  528.         return $code;
  529.         }
  530.     }
  531.  
  532. /* TinyUrl */
  533. function TinyUrl($url){
  534.     global $font;
  535.     if(preg_match('/http:\/\/tinyurl\.com\/[a-zA-Z0-9-]{4,30}+$/', $url)){
  536.         $key = explode('.com/', $url);
  537.         preg_match('/<a id="redirecturl" href="(.*)">/', file_get_contents('http://preview.tinyurl.com/'.$key[1]), $reply);
  538.         return 'TinyUrl: '.$font['u'].$reply[1];
  539.     } else {
  540.         return 'TinyUrl: '.$font['u'].file_get_contents('http://tinyurl.com/api-create.php?url='.$url);
  541.         }
  542.     }
  543.  
  544. /* Random Facts. Chuck, Vin, Mrt. */
  545. function RandomFacts($Person){
  546.     $url = "http://4q.cc/index.php?pid=atom&person=".$Person;
  547.     preg_match_all('/<summary>(.*?)<\/summary>/', file_get_contents($url), $matches);
  548.     return html_entity_decode($matches[1][array_rand($matches[1])]);
  549.     }
  550.  
  551. /* Random Facts. Jack Bauer. */
  552. function JackBauer(){
  553.     $url = "http://www.jackbauerfacts.com/fact/random";
  554.     preg_match('/<div style=".*">Fact ID #\d{1,5}:[\s](.*?)<\/div>/', file_get_contents($url), $matches);
  555.     return html_entity_decode($matches['1']);
  556.     }
  557.  
  558. /* Urban Dictionary. */
  559. function UrbanDict($urban_query, $chan){
  560.     global $font;
  561.     $url = "http://www.urbandictionary.com/define.php?term=" . urlencode($urban_query);
  562.     $contents = file_get_contents($url);
  563.     if ($urban_query == null){
  564.         PRIVMSG($chan, "Please provide a search query.");
  565.     } else if (strpos($contents, $urban_query . " isn't defined")){
  566.         PRIVMSG($chan, $urban_query." isn't defined yet.");
  567.     } else if (strpos($contents, "Service Temporarily Unavailable")) {
  568.         PRIVMSG($chan, "Service temporarily unavailable. Please try again later.");
  569.     } else {
  570.         preg_match_all("/<a.*href=.*defin.*term=.*>(.*?)<\/a>/", $contents, $matches);
  571.         $limit = count($matches['0']) < 18 ? count($matches['0']) : 18;
  572.         for($i=0; $i < $limit; $i++){
  573.             preg_match("/<a.*href=.*defin.*term=.*>(.*?)<\/a>/", $matches['0'][$i], $titles);
  574.             $urban_titles .= ", ".$titles['1'];
  575.             }
  576.         $contents = trim(preg_replace('/[\r\n\t ]+/', ' ', $contents));
  577.         preg_match_all("/<div class='definition'>(.*?)<div class='example'>/", $contents, $matches1);
  578.         preg_match_all("/<div class='example'>(.*?)<div class='greenery'>/", $contents, $matches2);
  579.         $num = array_rand($matches1[1]);
  580.         PRIVMSG($chan, $font['b']."Urban Dictionary:".$font['n']." ".ucwords(strtolower($urban_query)));
  581.         sleep(1);
  582.         Truncate($font['b']."Definition:".$font['n']." ".html_entity_decode(strip_tags(trim($matches1[1][$num]))), $chan);
  583.         sleep(1);
  584.         Truncate($font['b']."Example:".$font['n']." ".html_entity_decode(strip_tags(trim($matches2[1][$num]))), $chan);
  585.         sleep(1);
  586.         PRIVMSG($chan, $font['b']."Nearby Titles:".$font['n']." ".substr($urban_titles, 2));
  587.         }
  588.     }
  589.  
  590. /* Weather Underground. */
  591. function WunderGround($WeatherLocation, $user){
  592.     $url = 'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query='.urlencode($WeatherLocation);
  593.     $s = @simplexml_load_file($url);
  594.     if ($s){
  595.         if ($s->display_location->city != ''){
  596.             if ($s->observation_time != 'Last Updated on , '){ $lupd = ' Lastupd('.str_replace('Last Updated on ', '', $s->observation_time).')'; } else { $lupd = ''; }
  597.             if ($s->windchill_f != 'NA'){ $feelslike = ' feels like '.$s->windchill_f.'�F/'.$s->windchill_c.'�C'; } else { $feelslike = ''; }
  598.             if ($s->temp_f != ''){ $temp = ' Temp('.$s->temp_f.'�F/'.$s->temp_c.'�C'.$feelslike.')'; } else { $temp = ''; }
  599.             if ($s->weather != ''){ $cond = ' Cond('.$s->weather.')'; } else { $cond = ''; }
  600.             if ($s->wind_string != ''){ $wind = ' Wind('.trim($s->wind_string).')'; } else { $wind = ''; }
  601.             if ($s->relative_humidity != ''){ $hum = ' Hum('.$s->relative_humidity.')'; } else { $hum = ''; }
  602.             if ($s->dewpoint_f != ''){ $dewpnt = ' Dewpnt('.$s->dewpoint_f.'�F/'.$s->dewpoint_c.'�C)'; } else { $dewpnt = ''; }
  603.             return $user.': from '.$s->display_location->full.'.'.$lupd.''.$temp.''.$cond.''.$wind.''.$hum.''.$dewpnt;
  604.         } else {
  605.             return $user.': City Not Found.';
  606.             }
  607.     } else {
  608.         return $user.': '.$http_response_header[0];
  609.         }
  610.     }
  611.  
  612. /* Acronyms. */
  613. function Acronyms($query, $chan){
  614.     if ($query == null){ PRIVMSG($chan, "Please provide a search query.");
  615.     } else{
  616.         $url = "http://acronyms.thefreedictionary.com/".$query;
  617.         preg_match_all('/<*td><td>(.*?)<\/td>/', file_get_contents($url), $matches);
  618.         if (!$matches[1][0]){
  619.             PRIVMSG($chan, "There were no results for $query");
  620.         } else {
  621.             $limit1 = count($matches['0']) < 5 ? count($matches['0']) : 5;
  622.             $limit2 = count($matches['0']) < 10 ? count($matches['0']) : 10;
  623.             for($i=0; $i < $limit1; $i++){ $result1 .= " | ".html_entity_decode(strip_tags($matches[1][$i])); }
  624.             for($i=$limit1; $i < $limit2; $i++){ $result2 .= " | ".html_entity_decode(strip_tags($matches[1][$i])); }
  625.             PRIVMSG($chan, substr($result1, 3)); if ($limit2 > 5) { PRIVMSG($chan, substr($result2, 3)); }
  626.             }
  627.         }
  628.     }
  629.  
  630. /* Google & Site Search. */
  631. function GoogleSearch($query, $chan, $limit, $siteSearch = null){
  632.     if ($query == null){ PRIVMSG($chan, "Please provide a search query.");
  633.     } else {
  634.         switch($siteSearch){
  635.             case "discogs":
  636.                 $site = '+site%3Adiscogs.com';
  637.                 break;
  638.             case "youtube":
  639.                 $site = '+site%3Ayoutube.com';
  640.                 break;
  641.             case "imdb":
  642.                 $site = '+site%3Aimdb.com';
  643.                 break;
  644.             case "php":
  645.                 $site = '+site%3Aphp.net';
  646.                 break;
  647.             case "quotes":
  648.                 $site = '+quotes+site%3Aimdb.com';
  649.                 break;
  650.             default:
  651.                 $site = '';
  652.                 break;
  653.             }
  654.         $url = 'http://www.google.com/search?q='.urlencode($query).$site;
  655.         preg_match_all('/<h3 class=r>(.|[\r\n])*?<\/h3>/', file_get_contents($url), $matches);
  656.         $limit = count($matches[0]) < $limit ? count($matches[0]) : $limit;
  657.         for($i=0; $i < $limit; $i++){
  658.             preg_match('/href="(.*?)"/', $matches[0][$i], $matches1);
  659.             preg_match('/<h3 class=r>(.*?)<\/a>/', $matches[0][$i], $matches2);
  660.             if($siteSearch == "quotes"){
  661.                 return $matches1[1];
  662.             } else {
  663.                 PRIVMSG($chan , html_entity_decode(strip_tags(str_replace("&#39;", "'", $matches2[1])))." -> \x1f".$matches1[1]);
  664.                 }
  665.             }
  666.         }
  667.     }
  668.    
  669. /* Port Scan. */
  670. function Portscan($host, $port, $chan){
  671.     $fp = @fsockopen($host, $port, $errno, $errstr, 4);
  672.     if($fp){
  673.         PRIVMSG($chan, $host.':'.$port.' OPEN');
  674.     } else {
  675.         PRIVMSG($chan, $host.':'.$port.' CLOSED');
  676.         }
  677.     }
  678.  
  679. /* Google Calculator. */
  680. function GoogleCalc($query){
  681.     if (!empty($query)){
  682.         $url = "http://www.google.co.uk/search?q=".urlencode($query);
  683.         preg_match('/<h2 class=r style="font-size:138%">(.*?)<\/b><\/h2>/', file_get_contents($url), $matches);
  684.         if (!$matches['1']){
  685.             return 'Your input could not be processed..';
  686.         } else {
  687.             return str_replace(array("�", "<font size=-2> </font>", " &#215; 10", "<sup>", "</sup>"), array("", "", "e", "^", ""), $matches['1']);
  688.             }
  689.         }
  690.     }
  691.    
  692. /* Wikipedia. */
  693. function Wikipedia($query, $chan){
  694.     global $font;
  695.     $url = "http://www.google.co.uk/search?q=en.wikipedia.org+".urlencode($query);
  696.     preg_match_all('/<h3 class=r>(.|[\r\n])*?<\/h3>/', @file_get_contents($url), $match);
  697.     for($i=0; $i < 1; $i++){
  698.         preg_match('/href="(.*?)"/', $match['0'][$i], $f_match);
  699.         }
  700.     if(strstr($f_match['1'], 'en.wikipedia.org') == true){ // else we didnt find a match
  701.         $contents = @file_get_contents($f_match['1']);
  702.         preg_match_all('/<p>(.*?)<\/p>/', $contents, $matches);
  703.         $l=8;
  704.         for($i=0; $i < $l; $i++){
  705.             preg_match('/<p>(.*?)<\/p>/', $matches['0'][$i], $matches1);
  706.             $matches1[$i] = strip_tags(str_replace(array("", ""), array($font['b'], $font['b']), $matches1[$i]));
  707.             $matches1[$i] = html_entity_decode(preg_replace("/\[\d{1,2}\]/", "", $matches1[$i]));
  708.             if (strlen($matches1[$i]) > 110){
  709.                 $l=$i;
  710.                 Truncate($matches1[$i], $chan);
  711.                 }
  712.             }
  713.         PRIVMSG($chan, $font['u']."".$f_match['1']);
  714.     } else {
  715.         PRIVMSG($chan, "No page with that title exists.");
  716.         }
  717.     }
  718.    
  719.    
  720. /* IMDB Film Quotes. */
  721. function ImdbQuotes($SearchQuery, $chan){
  722.     if (!empty($SearchQuery)){
  723.         $url = GoogleSearch($SearchQuery, $chan, 1, "quotes");
  724.         $contents = file_get_contents($url);
  725.         $contents = strstr($contents, '<!-- End TOP_RHS -->');
  726.         $contents = preg_replace('/[\r\n\t ]+/', ' ', $contents);
  727.         $contents = str_replace('&#x27;', "'", $contents);
  728.         $array = explode('<hr width="30%">', trim($contents));
  729.         $num = count($array);
  730.         if ($num){
  731.             $num = mt_rand(0,$num)-1;
  732.             preg_match_all('/(.*?)<\/b>:(.*?)<br>/', $array[$num], $matches);
  733.             $count = count($matches['0']);
  734.             for($i=0; $i < $count; $i++){
  735.                 preg_match('/(.*?)<\/b>:(.*?)<br>/', $matches['0'][$i], $matches1);
  736.                 Truncate(trim(strip_tags($matches1['1'])).': '.trim(strip_tags($matches1['2'])), $chan);sleep(1);
  737.             }
  738.         } else {
  739.             PRIVMSG($chan,'There were no results for "'.$SearchQuery.'".');
  740.             }
  741.     } else {
  742.         PRIVMSG($chan,'Try searching a Film/Show title.');
  743.         }
  744.     }
  745.  
  746. /* Truncate & Split Messages. */
  747. function Truncate($string, $chan, $order = null){
  748.     global $MaxStrlen;
  749.     if (strlen($string) > $MaxStrlen){
  750.         $msg1 = substr($string, 0, $MaxStrlen);
  751.         $end = strrpos($msg1, " ");
  752.         if($order == 1){ $msg1 = "..." . substr(trim($msg1), 0, $end); } else { $msg1 = substr($msg1, 0, $end); }
  753.         $msg2 = substr($string, $end);
  754.         PRIVMSG($chan, $msg1);
  755.     } else {
  756.         PRIVMSG($chan, $string);
  757.         }
  758.     if (strlen($msg2) > $MaxStrlen){
  759.         Truncate($msg2, $chan, 1);
  760.     } elseif (!empty($msg2)) {
  761.         PRIVMSG($chan, "..." . trim($msg2));
  762.         }
  763.     }
  764.    
  765.    
  766. /* Pandora Bot's AI Chat. */
  767. function aichat($chatter, $user){
  768.     global $AIBotID;
  769.     $url = 'http://www.pandorabots.com/pandora/talk-xml?botid='.$AIBotID.'&input='.urlencode($chatter).'&custid=thisuser';
  770.     $page = aichatCurl($url);
  771.     $xml = @simplexml_load_string($page);
  772.     if ($page === "timed_out"){
  773.         echo date('H:i:s')." - AI Chat: Timed Out.. \r\n";
  774.     } elseif(!$xml){
  775.         echo date('H:i:s')." - AI Chat: Page Failed To Load.. \r\n";
  776.     } else {
  777.         $f = array('  ', 'thisuser',' 3F', 'Om', 'unknown person', 'ALICE', '%25');
  778.         $t = array(' ', '', $user, $user, $user, $GLOBALS['config']['botname'], '%');
  779.         $xml->that = preg_replace('/[\r\n]+/', ' ', trim($xml->that));
  780.         return str_replace($f, $t, strip_tags(strtolower($xml->that)));
  781.         }
  782.     }
  783.    
  784. /* Pandora Bot's Curl. */
  785. function aichatCurl($url){
  786.     $ch = curl_init($url);
  787.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
  788.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  789.     $chBuffer = curl_exec($ch);
  790.     curl_close($ch);
  791.     if (empty($chBuffer)){
  792.         return "timed_out";
  793.     } else {
  794.         return trim($chBuffer);
  795.         }
  796.     }
  797.    
  798. /*Google Traslator. (Language Check) */
  799. function lang_check($lang, $languages) {
  800.    
  801.     /* Convert to lower case and trim. */
  802.     $lang = trim(strtolower($lang));
  803.    
  804.     /* Check to see if the language is in the array. */
  805.     if (array_key_exists($lang, $languages)) { return $lang; }
  806.     foreach ($languages as $this_lang => $this_init) {
  807.         if ($lang == $this_init) { return $this_lang; }
  808.         }
  809.        
  810.     /* Check for abbreviations and mis-spellings. */
  811.     switch ($lang) {
  812.         case "sq":
  813.         case "alb":
  814.         case "alban":
  815.         case "albanien":
  816.         case "albanese":
  817.             return "albanian";
  818.             break;
  819.         case "cs":
  820.         case "check":
  821.         case "chezc":
  822.         case "cz":
  823.             return "czech";
  824.             break;
  825.         case "da":
  826.         case "dane":
  827.         case "dan":
  828.             return "danish";
  829.             break;
  830.         case "nl":
  831.         case "ned":
  832.         case "nederlands":
  833.             return "dutch";
  834.             break;
  835.         case "en":
  836.         case "eng":
  837.         case "england":
  838.         case "brit":
  839.         case "british":
  840.             return "english";
  841.             break;
  842.         case "et":
  843.         case "est":
  844.         case "estonien":
  845.             return "estonian";
  846.             break;
  847.         case "tl":
  848.         case "fil":
  849.         case "filapino":
  850.         case "philipino":
  851.             return "filipino";
  852.             break;
  853.         case "fi":
  854.         case "fin":
  855.         case "finn":
  856.         case "finish":
  857.             return "finnish";
  858.             break;
  859.         case "fr":
  860.         case "fra":
  861.         case "fren":
  862.         case "fre":
  863.         case "francais":
  864.             return "french";
  865.             break;
  866.         case "gl":
  867.         case "gal":
  868.         case "galicien":
  869.             return "galician";
  870.             break;
  871.         case "de":
  872.         case "germ":
  873.         case "deutsche":
  874.         case "deutch":
  875.         case "ger":
  876.             return "german";
  877.             break;
  878.         case "el":
  879.         case "grek":
  880.         case "greece":
  881.         case "grk":
  882.         case "gre":
  883.             return "greek";
  884.             break;
  885.         case "hu":
  886.         case "hun":
  887.         case "hungary":
  888.         case "hungarien":
  889.             return "hungarian";
  890.             break;
  891.         case "in":
  892.         case "ind":
  893.         case "indonesien":
  894.             return "indonesian";
  895.             break;
  896.         case "it":
  897.         case "ita":
  898.         case "italy":
  899.             return "italian";
  900.             break;
  901.         case "ja":
  902.         case "jap":
  903.         case "japan":
  904.         case "japenese":
  905.             return "japanese";
  906.             break;
  907.         case "lv":
  908.         case "lat":
  909.         case "latvien":
  910.             return "latvian";
  911.             break;
  912.         case "pt":
  913.         case "por":
  914.         case "port":
  915.         case "portugal":
  916.         case "portugese":
  917.             return "portuguese";
  918.             break;
  919.         case "es":
  920.         case "sp":
  921.         case "spa":
  922.         case "spain":
  923.         case "spannish":
  924.             return "spanish";
  925.             break;
  926.         case "ru":
  927.         case "rus":
  928.         case "russia":
  929.         case "russien":
  930.             return "russian";
  931.             break;
  932.         }
  933.        
  934.     /* Return FALSE if we havent found a match. */
  935.     return FALSE;
  936.    
  937.     }
  938.  
  939. /*Google Traslator. (Main) */
  940. function translate($from, $to, $TextToTranslate, $chan) {
  941.    
  942.     // Define languages and their initials.
  943.     $languages = array(
  944.         "albanian"=>"sq",
  945.         "czech"=>"cs",
  946.         "danish"=>"da",
  947.         "dutch"=>"nl",
  948.         "english"=>"en",
  949.         "estonian"=>"et",
  950.         "filipino"=>"tl",
  951.         "finnish"=>"fi",
  952.         "french"=>"fr",
  953.         "galician"=>"gl",
  954.         "german"=>"de",
  955.         "greek"=>"el",
  956.         "hungarian"=>"hu",
  957.         "indonesian"=>"id",
  958.         "italian"=>"it",
  959.         "latvian"=>"lv",
  960.         "japanese"=>"ja",
  961.         "portuguese"=>"pt",
  962.         "spanish"=>"es",
  963.         "russian"=>"ru",
  964.         );
  965.        
  966.     // Parse for alternative spellings.
  967.     $to = lang_check($to, $languages);
  968.     $from = lang_check($from, $languages);
  969.    
  970.     // Check to and from languages.
  971.     if ($to == "" || $from == "" || !array_key_exists($to, $languages)
  972.     || !array_key_exists($from, $languages) || $to === FALSE || $from === FALSE) {
  973.         return FALSE;
  974.         }
  975.     $url = "http://www.google.com/translate_t?text=".urlencode($TextToTranslate)."&langpair=".$languages[$from]."|".$languages[$to]."#";
  976.     $contents = @file_get_contents($url);
  977.     if ($contents){
  978.         preg_match('/<input type=hidden name=gtrans value="(.*?)">/', $contents, $match);
  979.         //$result = iso2ascii($match['1']);
  980.         $result = Translation . ' ('.ucfirst($from).' to '.ucfirst($to).'): ' . trim(preg_replace('/[\r\n\t ]+/', ' ', $match['1']));
  981.         PRIVMSG($chan, $result);
  982.     } else {
  983.         PRIVMSG($chan, $http_response_header[0]);
  984.         }
  985.     }
  986.  
  987. ?>
Add Comment
Please, Sign In to add comment