"; } // Respond to !hello if ($command == ":!hello") { fputs($socket, "PRIVMSG ".$ex['2']." :Hello ".$username."!\n"); echo "Said hello to ".$username." in ".$ex['2'].".
"; } //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."
"; } //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."
"; } //Join A Channel if($command == ":!join" && $username == $admin){ fputs($socket,":".$botnick." JOIN ".$ex['4']." ".$ex['5']."\n"); echo "JOINing ".$ex['4']."
"; } //Join A Channel on Admin INVITE if($ex['1'] == "INVITE" && $username == $admin){ fputs($socket,":".$botnick." JOIN ".$ex['3']."\n"); echo "Invited to ".$ex['3']."
"; } //Part A Channel if($command == ":!part" && $username == $admin){ fputs($socket,":".$botnick." PART ".$ex['4']."\n"); echo "PARTing ".$ex['4']."
"; } //Change Nicks if($command == ":!nick" && $username == $admin){ fputs($socket,":".$botnick." NICK ".$ex['4']."\n"); echo "NICK changed to ".$ex['4']." by ".$username.".
"; } //Display the #channel topic //if($command == ":!topic"){ //fputs($socket,":".$botnick." TOPIC ".$ex['2']."\n"); //echo "Displaying TOPIC for ".$ex['2']."
"; //} //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']."
"; } //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 )
"; } //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 )
"; } //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']."
"; } // Close the connection if($command == ":!die" && $username == $admin){ fputs($socket, "QUIT :Terminated with extreme prejudice.\n"); echo "Killed by ".$username."
"; die(); } usleep(100000); } } ?>