All pastes #796273 Raw Edit

irc bot

public php v1 · immutable
#796273 ·published 2007-11-24 22:50 UTC
rendered paste body
<? // define your variables $host = "irc.freenode.net"; $port=6667; $nick="rmbot644"; $ident="rmbot644"; $chan="#phpc"; $readbuffer=""; $realname = "rmaste644bot"; // open a socket connection to the IRC server $fp = fsockopen($host, $port, $erno, $errstr, 30); // print the error if ther eis no connection if (!$fp) {     echo $errstr." (".$errno.")<br />\n"; } else {     // write data through the socket to join the channel     fwrite($fp, "NICK ".$nick."\r\n");     fwrite($fp, "USER ".$ident." ".$host." bla :".$realname."\r\n");     fwrite($fp, "JOIN :".$chan."\r\n");          // write data through the socket to print text to the channel     fwrite($fp, "PRIVMSG ".$chan." :Hello There!\r\n");     fwrite($fp, "PRIVMSG ".$chan." :I am a bot. Runemaste644's first bot, to be exact.\r\n");          // loop through each line to look for ping      while (!feof($fp)) {                   $line =  fgets($fp, 128);         echo $line."\n";                  $line = explode(":ping ", $line);                  echo $line[0]."\n";         if ($line[1]) {                          fwrite($fp, "PONG ".$line[1]."\r\n");          }         // Say something in the channel        $command = str_replace(array(chr(10), chr(13)), '', $ex[3]);        if ($command == ":!ping") {            fputs($socket, "PRIVMSG ".$ex[2]." :pong\n");        }    }          fclose($fp); } ?>