rendered paste body<?php$botnick = spudbot;$admin = Spudchat;function Uptime() { $ut = strtok( exec( "cat /proc/uptime" ), "." ); $days = sprintf( "%2d", ($ut/(3600*24)) ); $hours = sprintf( "%2d", ( ($ut % (3600*24)) / 3600) ); $min = sprintf( "%2d", ($ut % (3600*24) % 3600)/60 ); $sec = sprintf( "%2d", ($ut % (3600*24) % 3600)%60 ); return array( $days, $hours, $min, $sec );}// 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.nac.net", 6667) or die();// 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 == $admin) { //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 == $admin) { //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 == $admin){ fputs($socket,":".$botnick." JOIN ".$ex['4']." ".$ex['5']."\n"); echo "JOINing ".$ex['4']."<br />"; } //Join A Channel on Admin INVITE if($ex['1'] == "INVITE" && $username == $admin){ fputs($socket,":".$botnick." JOIN ".$ex['3']."\n"); echo "Invited to ".$ex['3']."<br />"; } //Part A Channel if($command == ":!part" && $username == $admin){ fputs($socket,":".$botnick." PART ".$ex['4']."\n"); echo "PARTing ".$ex['4']."<br />"; } //Change Nicks if($command == ":!nick" && $username == $admin){ fputs($socket,":".$botnick." NICK ".$ex['4']."\n"); echo "NICK changed to ".$ex['4']." by ".$username.".<br />"; } //Display the #channel topic //if($command == ":!topic"){ //fputs($socket,":".$botnick." TOPIC ".$ex['2']."\n"); //echo "Displaying TOPIC for ".$ex['2']."<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(); fputs($socket, "PRIVMSG ".$ex['2']." :\x0312Uptime [\x0315 ".trim($uptime['0'])."d ".trim($uptime['1'])."h ".trim($uptime['2'])."m ".trim($uptime['3'])."s \x0312]\n"); echo "Uptime sent to ".$username." ( ".$uptime['0']."d ".$uptime['1']."h ".$uptime['2']."m ".$uptime['3']."s )<br />"; } //Display RAM Usage if($command == ":!ram"){ foreach(file('/proc/meminfo') as $ri) $m[strtok($ri, ':')] = strtok(''); fputs($socket, "PRIVMSG ".$ex['2']." :\x0312Memory [\x0315 ".round($m['MemFree'] / 1024)." MB (".round(($m['MemFree'] / $m['MemTotal']) * 100)."%) Free \x0312|\x0315 ".round(($m['MemTotal'] - $m['MemFree']) / 1024)." MB (".round((($m['MemTotal'] - $m['MemFree']) / $m['MemTotal']) * 100)."%) Used \x0312|\x0315 ".round($m['MemTotal'] / 1024)." MB Total \x0312]\n"); echo "RAM Usage sent to ".$username." ( ".round($m['MemFree'] / 1024)." MB (".round(($m['MemFree'] / $m['MemTotal']) * 100)."%) Free | ".round(($m['MemTotal'] - $m['MemFree']) / 1024)." MB (".round((($m['MemTotal'] - $m['MemFree']) / $m['MemTotal']) * 100)."%) Used | ".round($m['MemTotal'] / 1024)." MB Total )<br />"; } //Display Some Help if($command == ":!help"){ fputs($socket, "NOTICE $username :Available Commands and Their Usage\n"); usleep(1000000); fputs($socket, "NOTICE $username :!die - Kill the bot (restricted to admin)\n"); usleep(1000000); fputs($socket, "NOTICE $username :!hello - Say hello\n"); usleep(1000000); fputs($socket, "NOTICE $username :!join #channel (key) - Join #channel with (key) (restricted to admin) **\n"); usleep(1000000); fputs($socket, "NOTICE $username :!load - Displays load averages for the last 1, 5, and 15 minutes\n"); usleep(1000000); fputs($socket, "NOTICE $username :!msg nick|channel message - Msg nick|channel message (restricted to admin)\n"); usleep(1000000); fputs($socket, "NOTICE $username :!nick newnick - Changes bot nick to newnick (restricted to admin)\n"); usleep(1000000); fputs($socket, "NOTICE $username :!notice nick|channel message - Notice nick|channel message (restricted to admin)\n"); usleep(1000000); fputs($socket, "NOTICE $username :!part #channel - Part #channel (restricted to admin)\n"); usleep(1000000); fputs($socket, "NOTICE $username :!ram - Displays RAM usage\n"); //usleep(1000000); //fputs($socket, "NOTICE $username :!topic - Display current channel's topic (currently unimplemented)\n"); //usleep(1000000); //fputs($socket, "NOTICE $username :!topic newtopic - Change current channel's topic (currently unimplemented|restricted to admin)\n"); usleep(1000000); fputs($socket, "NOTICE $username :!uptime - Display bot's shell uptime\n"); usleep(1000000); fputs($socket, "NOTICE $username :** - The bot will also join #channel upon being invited by it's admin (".$admin.").\n"); echo "HELPing ".$ex['0']."<br />"; } // Close the connection if($command == ":!die" && $username == $admin){ fputs($socket, "QUIT :Terminated with extreme prejudice.\n"); echo "Killed by ".$username."<br />"; die(); } usleep(100000); }}?>