select_db('wow'); $server = "game.zdechov.net"; $port = "6667"; $channel = "#wow"; $nick = "Harvester"; $jokefile = "jokes.txt"; $LastMessagesCount = 10; //Functions: function IRCConnect($fp, $nick, $channel, $joinwait) { fwrite($fp, "USER USER $nick # # :$nick\n"); fwrite($fp, "NICK $nick\n"); sleep($joinwait); fwrite($fp, "JOIN $channel\n"); } function irc_say($fp, $msg, $nick, $rcpto) { //fwrite($fp, ":$nick!~Harvie@r3ax157.net.upc.cz PRIVMSG $rcpto :$msg\n"); fwrite($fp, ": PRIVMSG $rcpto :$msg\n"); } //Code: $jokes = file($jokefile); $sfp = fsockopen($server, $port, $errno, $errstr, 5); IRCConnect($sfp, $nick, $channel, 0); $home_channel = $channel; fwrite($sfp, "JOIN $channel\n"); while(!fwrite($sfp, "")) { // ReadLine from IRC Server $line = (fgets($sfp)); echo($line); // IRC Sever PING/PONG Response $words = (explode(" ", $line)); if(count($words) > 0) { if ($words[0] == "PING") { fwrite($sfp, "PONG ".trim($words[1])."\n"); echo("-PONG ".trim($words[1])."\n"); } } if(count($words) > 2) { if((trim($words[1]) == "PART") or (trim($words[1]) == "QUIT")) { $UserNick = substr($words[0], 1, strpos($words[0], '!') - 1); $UserHost = substr($words[0], strpos($words[0], '@') + 1); $Channel = $channel; $DbResult = $Database->select('irc_user_leave', '*', 'nick="'.$UserNick.'" AND host="'.$UserHost.'" AND channel="'.$Channel.'"'); if($DbResult->num_rows > 0) $Database->update('irc_user_leave', 'nick="'.$UserNick.'" AND host="'.$UserHost.'" AND channel="'.$Channel.'"', array('time' => 'NOW()')); else $Database->insert('irc_user_leave', array('time' => 'NOW()', 'nick' => $UserNick, 'host' => $UserHost, 'channel' => $Channel)); } if(trim($words[1]) == "JOIN") { $UserNick = substr($words[0], 1, strpos($words[0], '!') - 1); $UserHost = substr($words[0], strpos($words[0], '@') + 1); $Channel = substr(trim($words[2]), 1); $DbResult = $Database->select('irc_user_leave', 'time', 'nick="'.$UserNick.'" AND host="'.$UserHost.'" AND channel="'.$Channel.'"'); if($DbResult->num_rows > 0) { $Row2 = $DbResult->fetch_array(); $UserLeave = $DbResult->fetch_array(); $DbResult = $Database->select('irc_messages', '*', 'channel="'.$Channel.'" AND time > "'.$Row2['time'].'" ORDER BY time ASC'); while($Row = $DbResult->fetch_array()) { irc_say($sfp, $Row['time'].' '.$Row['nick'].': '.$Row['message'], $nick, $UserNick); } } } } if(count($words) > 3) { // Prijem pozvanky if ( ( trim($words[1]) == "INVITE" ) && ( substr(trim($words[3]), 0, 2) == ":#" ) ) { $channel = substr(trim($words[3]), 1); fwrite($sfp, "JOIN $channel\n"); irc_say( $sfp, "Hello", $nick, $channel ); echo("-JOINED $channel\n"); } // Logování zpráv if ( ( trim($words[1]) == "PRIVMSG" ) && ( substr(trim($words[3]), 0, 1) == ":" ) ) { $Channel = trim($words[2]); $Message = trim(substr($words[3], 1)); $UserNick = substr($words[0], 1, strpos($words[0], '!') - 1); $UserHost = substr($words[0], strpos($words[0], '@') + 1); $Database->insert('irc_messages', array('time' => 'NOW()', 'channel' => $Channel, 'nick' => $UserNick, 'host' => $UserHost, 'message' => $Message)); } } $commands = (explode(":", $line)); if(count($commands) > 2) { //Harvester - Posle vizitku if ( trim($commands[2]) == "Harvester") { irc_say( $sfp, ("Ahoj lidi, ja jsem Harvieho bot. Random#: ".rand(0,10)), $nick, $channel); echo("-VISITCARD"."\n"); } //hhelp - vypise tuto napovedu if ( trim($commands[2]) == "hhelp") { irc_say( $sfp, "Ja jsem Harvester", $nick, $channel ); /* irc_say( $sfp, "Harvester - Posle vizitku", $nick, $channel ); irc_say( $sfp, "hhelp - vypise tuto napovedu", $nick, $channel ); irc_say( $sfp, "hsay:Message - Posle zpravu", $nick, $channel ); irc_say( $sfp, "hpsay:to:Message - Posle soukromou zpravu kanalu nebo osobe", $nick, $channel ); irc_say( $sfp, "hdo:Command - Posle serveru prikaz", $nick, $channel ); irc_say( $sfp, "hmove:Channel - Pripoji do kanalu / Zmeni aktivni kanal", $nick, $channel ); irc_say( $sfp, "/invite Harvester #channel - Pozve a pripoji bota do kanalu", $nick, $channel ); irc_say( $sfp, "hpart:Channel - Odpoji se z kanalu", $nick, $channel ); irc_say( $sfp, "hjoke - Posle \"nahodny\" vtip", $nick, $channel ); */ echo("-HELPED"."\n"); } //hsay:Message - Posle zpravu if ( trim($commands[2]) == "hsay") { irc_say( $sfp, trim($commands[3]), $nick, $channel ); echo("-SAID: ".trim($commands[3])."\n"); } //hpsay:to:Message - Posle soukromou zpravu kanalu nebo osobe if ( trim($commands[2]) == "hpsay") { irc_say( $sfp, trim($commands[4]), $nick, trim($commands[3]) ); echo("-SAID: ".trim($commands[4])." -- To: ".trim($commands[3])."\n"); } //hcol:to:Message - Posle kolizni zpravu kanalu nebo osobe if ( trim($commands[2]) == "hcol") { irc_say( $sfp, trim($commands[4]), trim($commands[3]), $channel ); echo("-COLIDED: ".trim($commands[4])." To: ".trim($commands[3])."\n"); } //hdo:Command - Posle serveru prikaz if ( trim($commands[2]) == "hdo") { $hdo = explode("hdo:", $line); fwrite( $sfp, trim($hdo[1])."\n" ); echo("-DONE: ".trim($hdo[1])."\n"); } //hpart:Channel - Odpoji se z kanalu if ( trim($commands[2]) == "hpart") { $hdo = explode("hpart:", $line); if ( trim($hdo[1]) != trim($home_channel) ) { fwrite( $sfp, "PART :".trim($hdo[1])."\n" ); echo("-PARTED: ".trim($hdo[1])."\n"); } } //hmove:Channel - Zmeni aktivni kanal if ( trim($commands[2]) == "hmove") { $hdo = explode("hmove:", $line); if ( trim($hdo[1]) != trim($home_channel) ) { $home_channel = trim($hdo[1]); fwrite($sfp, "JOIN $home_channel\n"); irc_say( $sfp, "Hi, im here...", $nick, $home_channel ); echo("-ACTIVATED: ".trim($hdo[1])."\n"); } } //htime - udaje o casu if ( trim($commands[2]) == "htime") { $msg = implode("-", getdate(time())); irc_say( $sfp, trim($msg), $nick, $channel ); echo("-TIMED"."\n"); } //hjoke - Posle nahodny vtip if ( trim($commands[2]) == "hjoke") { $joke = ($jokes[ rand(0, (sizeof($jokes)-1) ) ]); //$ftip = "Potkaji se dve blondyny a jedna rika te druhe: \"How do you do?\" a ta ji odpovi co? kde ses to naucila? To vis vzdycky pretocim radio doprava a tam mluvi jen anglicky tak se to tak ucim. Potkaji se za 2 tydny a jedna rika druhe How do you do a druha ji odpovi chsrchsrsrshchsrshchs"; irc_say( $sfp, trim($joke), $nick, $channel ); echo("-JOKED"."\n"); } //Navrat do domaciho kanalu $channel = $home_channel; } } echo("-Connection lost."); ?>