Here's a IRC bot I worked on a few years back. Worked fine back then.
Never finished it, but I just thought I'd share
PHP Code:
<?php // By Thomas "TyR" Pedersen // license: http://www.gnu.org/licenses/gpl.txt // www.n1studios.net class Bot {
var $nickname = "Weehbot"; var $server = "irc.quakenet.org"; //Quakenet don't work anymore (protection) var $port="6667"; var $connected=0; var $socket; var $password = "pennyless"; var $received; var $string; var $privarray;
function bot(){ $this->bot_send_out(); } function bot_send_out(){
echo "Connecting to server...\n";
if ($this->socket=fsockopen($this->server, $this->port)) { $this->connected = 1; echo "Connected to ".gethostbyname($this->server)."\n"; $this->bot_send("PASS " . $this->password); $this->bot_send("NICK " . $this->nickname); $this->bot_send("USER guest 0 * :Botboy"); $this->bot_send("JOIN #weehbot"); $this->bot_send("PRIVMSG #weehbot Hia!");
} else { echo "Connection failed\n"; } }
function bot_send($string){ fputs($this->socket,$string."\r\n"); }
function bot_receive(){ if ($this->connected){ $this->received=fgets($this->socket,520); $this->received=$this->bot_format_content($this->received); return $this->received; } }
function bot_format_content($string){
switch ($string){ case eregi("PRIVMSG", $string)==true: $privmsg=explode(" ",$string); $this->bot_commands($privmsg[3],$privmsg[2]); break;
case substr($string,0,4)=="PING": $string=str_replace("PING","PONG",$string); $this->bot_send($string); $string="<-- PING\n -->PONG \n"; break; }
return $string; } function bot_commands($string,$to){ $string=trim(substr($string,1,strlen($string))); switch ($string){ case "Hello": $this->bot_send("PRIVMSG $to Hi there ^-^\r\n"); break; case "!bye": $this->connected=0; break; case "!join": echo "moo"; $this->bot_send("JOIN #weeh\r\n"); break; case "MODE $this->nickname +i": echo "moo"; $this->bot_send("JOIN #weeh\r\n"); break; } } }
echo "\-----------------------------------------\ \n"; echo " \ IRC BOT v0.1 by Thomas Pedersen aka TyR \ \n"; echo " \-----------------------------------------\ \n"; $bott = new Bot; while($bott->connected) { echo $bott->bot_receive(); } ?>
EDIT:
I just tested the script and it didn't work 100% now.
But it still connects to irc and can receive private messages etc... it just wont join any channels.
Last edited by TyR; 02-18-2007 at 10:24 AM..
|