<?php
class CMessage
{
var $all;
var $word; //[]
var $pasteTo; //if you recive msg and wanna to send to this people,
var $fromNick;
var $fromAddress;
var $fromPermission;
var $to;
var $command;
var $message;
var $params; //[]
}
set_time_limit(0);
define ('CRLF', "\r\n");
function bot_run()
{
//EDIT THIS DOWN
//EDIT THIS DOWN
$nick1 = 'nick1'; // owner of bot nick1
$nick2 = 'nick2'; // owner of bot nick2
$bot_nick = 'Live-Score'; // The nick
$username = 'Live'; // The Username (username@hostname)
$port = 6667; // Port number
$remotehost = 'irc.asenovgrad.net'; // The server we are connecting to
$realname = 'Live-Score 2 PHP IRC bot'; // Your realname
//--------------------------------------------------------------------------------------------------------
//====================================================================================
// Open the socket
$fp = fsockopen( $remotehost, $port, &$err_num, &$err_msg, 30 );
if(!$fp)
{
// Error trying to connect to server
LogFile("Error: The server is not currently available!");
exit;
}
$day = date('Y-m-d');
$timer = date('h-i-s');
$today_str = "$day chas $timer";
//====================================================================================
$Header = "NICK $bot_nick\n";
$Header .= "USER $username $localhost $remotehost: $realname\n";
fputs($fp, $Header);
//====================================================================================
//identification in nickserv
//EDIT THIS LINE DOWN
fputs( $fp, "PRIVMSG nickserv :identify q1w2e3r4\n");
//====================================================================================
//THIS IS FILE WHO SCRIPT USE FOR JOIN IN CHANNEL FILE IS join.txt
///
///////////
$fd = fopen("join.txt", "r");
while(!feof($fd))
{
$line = fgets($fd, 4096);
fputs( $fp, "JOIN $line\n");
sleep(4);
}
fclose($fd);
//====================================================================================
$response = '';
while( !feof($fp) )
{
$response = fgets($fp, 2048);
while ( substr_count( $response, CRLF ) != 0 )
{
// Check if there is CRLF (linesplit) in $response, and do that untill none
$offset = strpos( $response, CRLF ); // Just to know where the line ends
$data = substr( $response, 0, $offset ); // Split the line from the rest of the data
$response = substr( $response, $offset+2 ); // Split the rest from the line
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
$msg = new CMessage;
$msg = TranslateMessage($data);
//if use @quitnow bout will quit from irc
if($msg->command == "PRIVMSG" && $msg->word[0] == "@quit@")
{
if ($msg->fromNick == $nick1 or $msg->fromNick == $nick2)
{fputs($fp, "QUIT :Authorized by $msg->fromNick\n");
sleep(3);
LogFile("\n$msg->fromNick use @quit@ in $today_str ");
exit;
}
else
{
}
}
//ON ERROR BOT WILL RECONNECT AUTO
if($msg->command == "ERROR")
{
LogFile("\n vazniknala greshka ERROR: ".$msg->message);
return;
}
// COMMAND FOR JOIN IN CHANNEL WITHOUT ADD IN join.txt
if($msg->command == "PRIVMSG" && $msg->word[0] == "@join@")
{
if ($msg->fromNick == $nick1 or $msg->fromNick == $nick2)
{ fputs( $fp, "JOIN {$msg->word[1]}".CRLF );
LogFile("\n$msg->fromNick izpolzva @join@ v $today_str ");
}
else
{
}
}
//COMMAND FOR PART OF CHANNEL
if($msg->command == "PRIVMSG" && $msg->word[0] == "@part@")
{
if ($msg->fromNick == $nick1 or $msg->fromNick == $nick2)
{
fputs( $fp, "PART {$msg->word[1]}".CRLF );
LogFile("\n$msg->fromNick use @part@ on $today_str ");
}
else
{
}
}
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//adding channel to join.txt and join to channel
if($msg->command == "PRIVMSG" && $msg->word[0] == "@addchan@")
{
if ($msg->fromNick == $nick1 or $msg->fromNick == $nick2)
{
fputs( $fp, "JOIN {$msg->word[1]}".CRLF );
$f = fopen("join.txt", "at");
fputs($f, "\n{$msg->word[1]}");
fclose($f);
LogFile("\n$msg->fromNick use @addchan@ in $today_str ");
}
else
{
}
}
if($msg->command == "PRIVMSG" && $msg->word[0] == "\001VERSION\001")
{
fputs( $fp, "NOTICE {$msg->fromNick} :Live-Score bot ver. 3.0 2007".CRLF );
fputs( $fp, "NOTICE {$msg->fromNick} :Programmed by OnL1Ne".CRLF );
fputs( $fp, "NOTICE {$msg->fromNick} :mrandreev@gmail.com".CRLF );
}
//ping-pong :)
if($msg->command == "PING")
{
fputs($fp, "PONG :{$msg->message}\n");
}
if($msg->command == "PRIVMSG" && substr($msg->message,0,1) == '!')
{
ResFootball($fp, $msg);
}
unset($msg);
//----------------------------------------------------------------------------
}
} //end while
//------------------------------------------------------------------------------------
fclose($fp);
LogFile("\nExit from function bot_run()");
unset($msg,$data,$response,$offset,$Header,$nick,$username,$localhost,$remotehost,$realname,$channels,$port,$fp );
sleep(2);
return;
}
//============================================================================================
// TranslateMessage function
//============================================================================================
function TranslateMessage($data)
{
$msg = new CMessage;
$msg->all = $data;
if( substr($data, 0, 1) == ":")
{
$data = substr($data, 1 );
$pos = strpos( $data, " ");
$temp = substr( $data, 0, $pos );
$data = substr( $data, $pos+1 );
if( is_int ($pos = strpos( $temp, "!")) )
{
$msg->fromNick = substr( $temp, 0, $pos );
$msg->fromAddress = trim( substr( $temp, $pos+1 ) );
}
else
{
$msg->fromAddress = $temp;
}
$pos = strpos( $data, " ");
$msg->command = substr( $data, 0, $pos );
$data = substr( $data, $pos+1 );
if( is_int($pos = strpos( $data, ":") )) //ako ima belejka
{
$msg->message = trim( substr( $data, $pos+1 ) );
$msg->word = split(" ", $msg->message);
$data = trim( substr( $data, 0, $pos - 1 ) );
}
if( $data != "" )
{
$msg->params = split(" ", $data); //params
$msg->to = $msg->params[0];
}
}
else
{
// $all PING xx yy :irc.techno-link.com
// $command PING
// $message irc.techno-link.com
// $params[] xx yy
$pos = strpos( $data, " " );
$msg->command = substr( $data, 0, $pos ); //PING
$data = substr( $data, $pos + 1 ); //xx yy :irc.techno-link.com
if( is_int($pos = strpos( $data, ":") ))
{
$msg->message = trim( substr( $data, $pos + 1 ) ); //irc.techno-link.com
$msg->word = split(" ", $msg->message);
$data = trim( substr( $data, 0, $pos - 1 ) );
}
$msg->params = split( " ", $data );
}
$msg->pasteTo = $msg->to;
if( substr($msg->pasteTo, 0, 1) != '#') $msg->pasteTo = $msg->fromNick;
unset($data, $pos, $temp);
return $msg;
}
//============================================================================================
// FootBall function
//============================================================================================
function ResFootball($fp, $msg)
{
$day = date('Y-m-d');
$timer = date('h-i-s');
$today_str = "$day chas $timer";
$d = substr($msg->message, 1);
if ($d == "euro2004" or $d == "eurocups" or $d == "live" or $d == "wc2006" or $d == "intl" or $d == "england" or $d == "italy" or $d == "spain" or $d == "germany" or $d == "france" or $d == "holland" or $d == "belgium" or $d == "portugal" or $d == "scotland" or $d == "austria" or $d == "denmark" or $d == "finland" or $d == "greece" or $d == "iceland" or $d == "ireland" or $d == "norway" or $d == "sweden" or $d == "turkey" or $d == "bulgaria" or $d == "croatia" or $d == "hungary" or $d == "poland" or $d == "russia" or $d == "slovenia" or $d == "ukraine" or $d == "argentina" or $d == "brazil" or $d == "mexico" or $d == "usa" or $d == "southamerica")
{
}
//===========================================
//!help
elseif ($d == help)
{
$fd = fopen("help.txt", "r");
while(!feof($fd))
{
$line = fgets($fd, 4096);
fputs( $fp, "PRIVMSG $msg->fromNick :$line".CRLF );
sleep(2);
}
LogFile("$msg->fromNick iska !help v $today_str ");
fclose($fd);
return;
}
//!credits
elseif ($d == credits)
{
$fd = fopen("credits.txt", "r");
while(!feof($fd))
{
$line = fgets($fd, 4096);
fputs( $fp, "PRIVMSG $msg->fromNick :$line".CRLF );
}
LogFile("$msg->fromNick iska !credits v $today_str ");
fclose($fd);
return;
}
else
{
return;
}
fputs( $fp, "PRIVMSG $msg->fromNick :LiveScore DataBase Loading....".CRLF );
fputs( $fp, "PRIVMSG $msg->fromNick :\0031 ".CRLF );
LogFile("$msg->fromNick iska rezultat ot $d v $today_str ");
//----------------------------------------------------------------------
//connection
if(!($f = fsockopen("www.livescore.com", 80, $errno, $errstr, 20)) )
{
fputs( $fp, "PRIVMSG $msg->fromNick :sorry, server not working!".CRLF );
return;
}
$url = "http://www.livescore.com/default.dll?page=$d";
fputs ($f, "GET $url HTTP/1.0\r\nHost: www.livescore.com\r\n\r\n");
$buffer = "";
while (!feof($f)) $buffer .= fgets ($f, 60000);
fclose ($f);
$start = strpos($buffer, 'type="hidden"') + 13;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, 'name="') + 6;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '"');
$keyname = substr( $buffer, 0, $start );
$buffer = substr( $buffer, $start );
$start = strpos($buffer, 'value="') + 7;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '"');
$keyval = substr( $buffer, 0, $start );
//----------------------------------------------------------------------
//connection
if(!($f = fsockopen("www.livescore.com", 80, $errno, $errstr, 20)) )
{
fputs( $fp, "PRIVMSG $msg->fromNick :Sujalqvam v momenta nqma vruzka sus servera!!".CRLF );
return;
}
$url = "http://www.livescore.com/default.dll?page=$d&$keyname=$keyval";
fputs ($f, "GET $url HTTP/1.0\r\nHost: www.livescore.com\r\n\r\n");
$buffer = "";
while (!feof($f)) $buffer .= fgets ($f, 60000);
fclose ($f);
if( strlen($buffer) < 2400 )
{
fputs( $fp, "PRIVMSG $msg->fromNick :sorry but now can use a bot!".CRLF );
return;
}
$start = strpos($buffer, '<tr bgcolor="#cfcfcf">') + 22;
$buffer = substr( $buffer, $start );
fputs( $fp, "PRIVMSG $msg->fromNick : $d".CRLF );
fputs( $fp, "PRIVMSG $msg->fromNick : -----------------------------------------------------------------".CRLF );
sleep(1);
//----------------------------------------------------------------------
while(1)
{
if(! is_int( $start = strpos($buffer, '<td width="45" height="18">')) ) break;
if($start > 310) break;
$start += 27;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '</td>');
$time = substr( $buffer, 0, $start );
$time = str_replace( " ", "", $time );
while( is_int( $start = strpos($time, '<')) )
{
$end = strpos($time, '>') + 1;
$time = substr( $time, 0, $start ) . substr( $time, $end );
}
$time = trim($time);
if ($time == "FT")
{
$time = "KRAEN";
}
elseif ($time == "HT")
{
$time = "POLUVREME";
}
elseif ($time < 90)
{
$time = $time;
}
else
{
$time = $time + 2;
}
$start = strpos($buffer, '<td ');
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '">') + 2;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '</td>');
$otbor1= substr( $buffer, 0, $start );
$start = strpos($buffer, '<td ');
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '">') + 2;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '</td>');
$result= substr( $buffer, 0, $start );
while( is_int( $start = strpos($result, '<')) )
{
$end = strpos($result, '>') + 1;
$result = substr( $result, 0, $start ) . substr( $result, $end );
}
$start = strpos($buffer, '<td ');
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '">') + 2;
$buffer = substr( $buffer, $start );
$start = strpos($buffer, '</td>');
$otbor2= substr( $buffer, 0, $start );
//-----------------------------------
$spc = " ";
$time = $time . substr( $spc, 0, strlen($spc) - strlen($time) );
$spc = " ";
$otbor1 = substr( $spc, 0, strlen($spc) - strlen($otbor1) ) . $otbor1;
$spc = " ";
$result = $result . substr( $spc, 0, strlen($spc) - strlen($result) );
$spc = " ";
$otbor2 = $otbor2 . substr( $spc, 0, strlen($spc) - strlen($otbor2) );
if(strlen($time) + strlen($otbor1) + strlen($result) + strlen($otbor2) > 200)
{
fputs( $fp, "PRIVMSG $msg->fromNick :sorry try letter!".CRLF );
return;
}
fputs( $fp, "PRIVMSG $msg->fromNick : $time $otbor1 $result $otbor2".CRLF );
sleep(1);
}//end while
fputs( $fp, "PRIVMSG $msg->fromNick :------------------------------------------------------------------\0037 ".CRLF );
//ignorva za 5-secundi
sleep(6);
}//end function
//============================================================================================
// LogFile function
//============================================================================================
function LogFile($str)
{
$f = fopen("logfile.txt", "at");
fputs($f, "$str\n");
fclose($f);
}
//============================================================================================
// execute the main function;
//============================================================================================
while(1) bot_run();
?>
selam arkadaşlar acaba bu kodları nasıl uyarlıyabilirim siteme bi turlu çıkartamadım yardımcı olabilecek varmı