Guest User

Easton

a guest
May 7th, 2010
199
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Prevent PHP from stopping the script after 30 sec
  3. set_time_limit(0);
  4.  
  5. //Settings
  6. $chan = "#channel";
  7. $server = "irc.example.com";
  8. $port = 6667;
  9. //I tacked on a random # at the end, since the bot would sometimes linger after it quit.
  10. $nick = "name".rand(2, 444);
  11. //
  12.  
  13. $socket = fsockopen($server, $port);
  14. fputs($socket,"USER $nick $nick $nick $nick :$nick\n");
  15. fputs($socket,"NICK $nick\n");
  16.  
  17. //some servers dont let you join a channel instantly
  18. while($logincount < 10) {
  19. $logincount++;
  20. $data = fgets($socket, 128);
  21. echo nl2br($data);
  22.  
  23. // Separate all data
  24. $ex = explode(' ', $data);
  25.  
  26. // Send PONG back to the server
  27. if($ex[0] == "PING"){
  28. fputs($socket, "PONG ".$ex[1]."\n");
  29. }
  30. flush();
  31. }
  32. sleep(1);
  33.  
  34.  
  35. fputs($socket,"JOIN ".$chan."\n");
  36.  
  37. while(1) {
  38.     while($data = fgets($socket)) {
  39.             echo nl2br($data);
  40.             flush();
  41.  
  42.             $ex = explode(' ', $data);
  43.         $rawcmd = explode(':', $ex[3]);
  44.         $oneword = explode('<br>', $rawcmd);
  45.             $channel = $ex[2];
  46.         $nicka = explode('@', $ex[0]);
  47.         $nickb = explode('!', $nicka[0]);
  48.         $nickc = explode(':', $nickb[0]);
  49.  
  50.         $host = $nicka[1];
  51.         $nick = $nickc[1];
  52.             if($ex[0] == "PING"){
  53.                 fputs($socket, "PONG ".$ex[1]."\n");
  54.             }
  55.  
  56.         $args = NULL; for ($i = 4; $i < count($ex); $i++) { $args .= $ex[$i] . ' '; }
  57.  
  58.    
  59.  switch(rtrim($rawcmd[1])) {
  60.  //start commands
  61.  
  62.  
  63.             case ".sayit":
  64.                 fputs($socket, "PRIVMSG ".$channel." :".$args." \n");  
  65.                     if ($ex[1] == "KICK"){ fputs($socket,"JOIN ".$chan."\n"); }    
  66.             break;       
  67.  
  68.                 case ".md5":
  69.                fputs($socket, "PRIVMSG ".$channel." :MD5 ".md5($args)."\n");
  70.             break;
  71.  
  72.            
  73.                    case ".exit":
  74.                   fputs($socket,"PRIVMSG $channel :baibai\n");
  75.                   fputs($socket,"QUIT Client Disconnected!\n");
  76.             die('Exited!');
  77.            break;
  78.            //done commands
  79.     }
  80.  
  81.     }
  82.    
  83.    
  84. }
  85.  
  86. ?>
RAW Paste Data