Monday, June 9, 2008

an irc bot "PHP"

<
IRC Bot




Nick:

Password:

Realname:

Owner: Note: Please use the full host of owner (nick!user@host)

Server:

Port:





set_time_limit(0);
if ($_GET[nick]) { $usernick = $_GET[nick]; }
else { $usernick = PHPBot; }
if ($_GET[realname]) { $realname = $_GET[realname]; }
else { $realname = PHPBot; }
if ($_GET[server]) { $server = $_GET[server]; }
else { $server = "irc.waypasteleven.com"; }
if ($_GET[port]) { $port = $_GET[port]; }
else { $port = 6667; }
if ($_GET[pass]) { $pass = $_GET[pass]; }
else { $pass = password; }
if ($_GET[owner]) { $pass = $_GET[owner]; }
else { $owner = "Sockmonkey!SockMonkey@says.you.are.a-freak.com"; }
$socket = fsockopen($server, $port);
fputs($socket,"USER $usernick socky-bot.net Socky :" . $realname . "\n");
fputs($socket,"NICK " . $usernick . "\n");
while(1) {
while($data = fgets($socket, 128)) {
echo nl2br($data);
flush();
$ex = explode( , $data);
if ($ex[0] == "PING"){
fputs($socket, "PONG ".$ex[1]."\n");
}
$command = str_replace(array(chr(10), chr(13)), , $ex[3]);
preg_match(/^:(.*?)!(.*?)$/i, $ex[0], $matches);
$host = "!".$matches[2];
$nick = $matches[1];
if ($ex[0] == ":irc.waypasteleven.com") {
if ($ex[1] == "433") {
fputs($socket, "NICK ".$usernick."_\n");
}
}
if ($ex[1] == "NOTICE") {
if ($ex[0] == ":NickServ!services@waypasteleven.com") {
if ($ex[3] == ":This") {
fputs($socket, "PRIVMSG NickServ :identify $pass\n");
echo($server." PRIVMSG NickServ identify ".$pass."")
}
}
}
/* Work on this */
if ($command == ":!say") {
fputs($socket, "PRIVMSG $ex[2] :".$ex[4]."\n");
}
if ($command == ":!commands") {
fputs($socket, "PRIVMSG $nick :!JOIN - !PART - !SAY - !CYCLE - !STOP\n");
}
if ($command == ":!join") {
fputs($socket, "JOIN ".$ex[4]."\n");
}
if ($command == ":!cycle") {
if ($ex[0] == ":".$owner) {
fputs($socket, "PART ".$ex[4]."\n");
fputs($socket, "JOIN ".$ex[4]."\n");
}
}
if ($command == ":!part") {
if ($ex[0] == ":".$owner) {
fputs($socket, "PART ".$ex[4]."\n");
}
}

//* THIS BIT *//
if ($ex[3] == ":".chr(1)."VERSION".chr(1)) {
fputs($socket, "notice $ex[2] :".chr(1)."Version PHP".chr(1)."\n");
}
if ($command == ":!stop"){
if ($ex[0] == ":".$owner) {
fputs($socket,"PRIVMSG $ex[2] Bot stopped!\n");
fputs($socket,"QUIT :Bot stopped by ".$nick."\n");
die("
$nick ended the bot.");
}
else {
fputs($socket,"KICK $ex[2] " . $nick . " Fuck you!\n");
}
}
}
sleep(0.1);
}
?>

No comments: