All pastes #966174 Raw Edit

Something

public php v1 · immutable
·published 2008-04-01 15:20 UTC
rendered paste body
<?php$botnick = spudbot;// Prevent PHP from stopping the script after 30 secset_time_limit(0);// and if the browser gets closedignore_user_abort(TRUE);// Opening the socket$socket = fsockopen("irc.prison.net", 6667);// Send auth infofputs($socket,"USER ".$botnick." php.net php :".$botnick."\n");fputs($socket,"NICK ".$botnick."\n");// Join channelusleep(100000);fputs($socket,"JOIN #dont.fucking.whois.me\n");// Force an endless whilewhile(1) {    // Continue the rest of the script here    while($data = fgets($socket, 128)) {    	echo nl2br($data);      flush();      // Separate all data      $ex = explode(' ', $data);		$command = str_replace(array(chr(10), chr(13)), '', $ex['3']);      preg_match('/^:(.*?)!(.*?)$/i', $ex[0], $matches);		$hostname = "!".$matches[2];		$username = $matches[1];                  // Send PONG back to the server      if($ex[0] == "PING"){      	fputs($socket, "PONG ".$ex['1']."\n");	    	echo "PONG".$ex['1']."<br />";      }            // Respond to !hello     	if ($command == ":!hello") {	   	fputs($socket, "PRIVMSG ".$ex['2']." :Hello ".$username."!\n");	   	echo "Said hello to ".$username." in ".$ex['2'].".<br />";      }            //Notice a username or channel      if ($command == ":!notice" && $username == "Spudchat") {      	//split $data into an array seperated by :      	$noticex = explode(':', $data);      	//remove !notice from the second part of the array created above      	//print_r($noticex);      	$noticex['2'] = substr($noticex['2'],8);      	//$noticercvr = characters up to the first space      	$noticercvr = substr($noticex['2'], 0, strpos($noticex['2'], " "));			$noticercvrlen = strlen($noticercvr);      	      	$notice = substr($noticex['2'],$noticercvrlen);      	$notice = trim($notice);	   	fputs($socket, "NOTICE ".$noticercvr." :".$notice."\n");	   	echo "NOTICE sent to ".$noticercvr." : ".$notice."<br />";      }				//Msg a username or channel      if ($command == ":!msg" && $username == "Spudchat") {      	//split $data into an array seperated by :      	$msgex = explode(':', $data);      	//remove !msg from the second part of the array created above      	//print_r($msgex);      	$msgex['2'] = substr($msgex['2'],5);      	//$msgrcvr = characters up to the first space      	$msgrcvr = substr($msgex['2'], 0, strpos($msgex['2'], " "));			$msgrcvrlen = strlen($msgrcvr);      	      	$msg = substr($msgex['2'],$msgrcvrlen);      	$msg = trim($msg);	   	fputs($socket, "PRIVMSG ".$msgrcvr." :".$msg."\n");	   	echo "MSG sent to ".$msgrcvr." : ".$msg."<br />";      }			//Join A Channel		if($command == ":!join" && $username == "Spudchat"){			fputs($socket,":".$botnick." JOIN ".$ex['4']."\n");			echo "JOINing ".$ex['4']."<br />";		}				//Part A Channel		if($command == ":!part" && $username == "Spudchat"){        		fputs($socket,":".$botnick." PART ".$ex['4']."\n");        		echo "PARTing ".$ex['4']."<br />";   	}   	   	//Change Nicks		if($command == ":!nick" && $username == "Spudchat"){        		fputs($socket,":".$botnick." NICK ".$ex['4']."\n");        		echo "NICK changed to ".$ex['4']." by ".$username.".<br />";   	}   			//Display Load Average		if($command == ":!load"){			$load=sys_getloadavg();			fputs($socket, "PRIVMSG ".$ex['2']." :\x0312Load Averages [ 1M \x0315".$load['0']."\x0312 ] [ 5M \x0315".$load['1']."\x0312 ] [ 15M \x0315".$load['2']."\x0312 ]\n");			echo "Load Averages [ 1M ".$load['0']." ] [ 5M ".$load['1']." ] [ 15M ".$load['2']." ] sent to ".$ex['2']."<br />";		}				//Display Uptime      if($command == ":!uptime"){      	$uptime=`uptime`;      	$uptime= preg_split( '/,/', $uptime, -1, PREG_SPLIT_NO_EMPTY );      	$uptime['0'] = substr_replace($uptime['0'], '', 0, 12);      	$uptime['0'] = substr($uptime['0'], 0, strpos($uptime['0'], " days"));      	$uptime2= preg_split( '/:/', $uptime['1'], -1, PREG_SPLIT_NO_EMPTY );      	fputs($socket, "PRIVMSG ".$ex['2']." :\x0312Uptime [\x0315".$uptime['0']."d ".trim($uptime2['0'])."h ".$uptime2['1']."m \x0312]\n");      	echo "Uptime sent to ".$username." ( ".$uptime['0']."d ".$uptime2['0']."h ".$uptime2['1']."m )<br />";      }		//Display Some Help      if($command == ":!help"){			fputs($socket, "NOTICE $username :Available Commands and Their Usage\n");			usleep(100000);			fputs($socket, "NOTICE $username :!die - Kill the bot (restricted to admin)\n");         usleep(100000);         fputs($socket, "NOTICE $username :!hello - Say hello\n");         usleep(100000);			fputs($socket, "NOTICE $username :!join #channel - Join #channel (restricted to admin)\n");			usleep(100000);			fputs($socket, "NOTICE $username :!load - Displays load averages for the last 1, 5, and 15 minutes\n");			usleep(100000);			fputs($socket, "NOTICE $username :!msg nick|channel message - Msg nick|channel message (restricted to admin)\n");			usleep(100000);						fputs($socket, "NOTICE $username :!nick newnick - Changes bot nick to newnick (restricted to admin)\n");			usleep(100000);			fputs($socket, "NOTICE $username :!notice nick|channel message - Notice nick|channel message (restricted to admin)\n");			usleep(100000);			fputs($socket, "NOTICE $username :!part #channel - Part #channel (restricted to admin)\n");			usleep(100000);         fputs($socket, "NOTICE $username :!uptime - Display bot's shell uptime\n");			echo "HELPing ".$ex['0']."<br />";      }			// Close the connection 		if($command == ":!die" && $username == "Spudchat"){			fputs($socket, "QUIT :Terminated with extreme prejudice.\n");			echo "Killed by ".$username."<br />";			die();      }	     	usleep(100000);	}}?>