<?php
// Prevent PHP from stopping the script after 30 sec
set_time_limit(0);
//Settings
$chan = "#channel";
$server = "irc.example.com";
$port = 6667;
//I tacked on a random # at the end, since the bot would sometimes linger after it quit.
$nick = "name".rand(2, 444);
//
$socket = fsockopen($server, $port);
fputs($socket,"USER $nick $nick $nick $nick :$nick\n");
fputs($socket,"NICK $nick\n");
//some servers dont let you join a channel instantly
while($logincount < 10) {
$logincount++;
$data = fgets($socket, 128);
echo nl2br($data);
// Separate all data
$ex = explode(' ', $data);
// Send PONG back to the server
if($ex[0] == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
flush();
}
sleep(1);
fputs($socket,"JOIN ".$chan."\n");
while(1) {
while($data = fgets($socket)) {
echo nl2br($data);
flush();
$ex = explode(' ', $data);
$rawcmd = explode(':', $ex[3]);
$oneword = explode('<br>', $rawcmd);
$channel = $ex[2];
$nicka = explode('@', $ex[0]);
$nickb = explode('!', $nicka[0]);
$nickc = explode(':', $nickb[0]);
$host = $nicka[1];
$nick = $nickc[1];
if($ex[0] == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
$args = NULL; for ($i = 4; $i < count($ex); $i++) { $args .= $ex[$i] . ' '; }
switch(rtrim($rawcmd[1])) {
//start commands
case ".sayit":
fputs($socket, "PRIVMSG ".$channel." :".$args." \n");
if ($ex[1] == "KICK"){ fputs($socket,"JOIN ".$chan."\n"); }
break;
case ".md5":
fputs($socket, "PRIVMSG ".$channel." :MD5 ".md5($args)."\n");
break;
case ".exit":
fputs($socket,"PRIVMSG $channel :baibai\n");
fputs($socket,"QUIT Client Disconnected!\n");
die('Exited!');
break;
//done commands
}
}
}
?>