All pastes #584939 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-06-23 00:09 UTC
rendered paste body
<?php
include("SmartIRC/SmartIRC.php");
include("ffdb.php");
include('config.php');

//error_reporting(0);

$irc = &new Net_SmartIRC();

function admin_identify($host,$user,$channel)
{
	global $admins;
	$nick_admin = false;
	foreach ($admins as $cert_host)
	{	
		if ($host == $cert_host)
		{
			$nick_admin = true;
		}
	}
	if (!$nick_admin)
	{
		global $irc;
		$irc->message(SMARTIRC_TYPE_CHANNEL, $channel, $user.': Ah...No!');
	}
	return $nick_admin;
}

class bot 
{
	function parse(&$irc, &$data) 
	{
		$recip = $data->channel;
		$msgToMe = false; 
		$msgPrefix = 'nothing';
		$msg = $data->message;
	
		global $triggers;
		foreach ($triggers as $prefix)
		{
			if ( substr($msg, 0, strlen($prefix)) == $prefix )
			{
				$msgToMe = true;
				$msgwithoutident = substr($msg, strlen($prefix));
			}
		}   
		
		if ($msgToMe == true)
		{
			$msg_parts = explode(' ', $msgwithoutident, 2);
			echo date("H:i:s")." - ".$data->nick." @ ".$recip." =>"; 
			foreach ($msg_parts as $stuff)
			{
				echo " ".$stuff."";
			}
			echo "\n";
			include("functions.php");
		} else {		
			//Store the message with a time and date
			$dataf = new FFDB("data.txt");
			$array = $dataf->get_table($recip);
			$array[] = array("user" => $data->nick, "time" => strtotime("now"), "msg" => $data->message);
			$dataf->write_table($recip,$array);
		}
	}
	function action(&$irc, &$data)
	{
		$recip = $data->channel;
		$msg = "*".substr($data->message, 7, -1);
		
		$dataf = new FFDB("data.txt");
		$array = $dataf->get_table($recip);
		$array[] = array("user" => $data->nick, "time" => strtotime("now"), "msg" => $msg);
		$dataf->write_table($recip,$array);
	}
	function part(&$irc, &$data)
	{
		$recip = $data->channel;
		
		$msg = $data->nick." left at ".date('m/d/Y h:m:s e',strtotime("now"))."";
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
		
		$datap = new FFDB("data_users.txt");
		$arrayp = $datap->get_table($recip);
		$arrayp[] = array("user" => $data->nick, "left" => strtotime("now"));
		echo $data->nick." left at ".strtotime("now")."\n";
		$datap->write_table($recip,$arrayp);
	}
	function join(&$irc, &$data)
	{		
		$recip = $data->channel;
		
		$msg = $data->nick." joined at ".date('m/d/Y h:m:s e',strtotime("now"))."";
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
		
		$data_users = new FFDB("data_users.txt");
		$users = $data_users->get_table($recip);
		foreach ($users as $id_users => $n_users)
		{
			if ($users[$id_users]['user'] == $data->nick)
			{
				$data_msg = new FFDB("data.txt");
				$messages = $data_msg->get_table($recip);
				$i = 0;
				foreach ($messages as $id => $n_messages)
				{
					if ($messages[$id]['time'] > $users[$id_users]['left'] && $messages[$id]['time'] < strtotime("now"))
					{
						//echo "Msg time: ".$messages[$id]['time']." Left time: ".$users[$id_users]['left']." Now: ".strtotime("now")." I: $i\n";
						echo "Content: ".$messages[$id]['msg']."\n";
						echo "Msg:  ".$messages[$id]['time']."\n";
						echo "Left: ".$users[$id_users]['left']."\n";
						echo "Now:  ".strtotime("now")."\n";
						echo "--------------------------\n";
						if ($i < 5)
						{
							$msg = "[".date('m/d/Y h:m:s e',$messages[$id]['time'])."] <".$messages[$id]['user'].">: ".$messages[$id]['msg']."";
							$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
							unset($messages[$id]['msg']);
							$i++;
						}
					}
				}
				unset($messages[$id]);
				break;
			}
		}
	}
}

$bot = new bot();
$irc = &new Net_SmartIRC();
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL|SMARTIRC_TYPE_QUERY, '.*', $bot, 'parse');
$irc->registerActionhandler(SMARTIRC_TYPE_ACTION, '.*', $bot, 'action');
//$irc->registerActionhandler(SMARTIRC_TYPE_PART, '.*', $bot, 'part');
//$irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'join');
$irc->setUseSockets(TRUE);
$irc->setChannelSyncing(TRUE);
$irc->setSenddelay(500);
echo date("H:i:s")." - Connecting to irc.freenode.net:6667...\n";
$irc->connect('irc.freenode.net', 6667);
$irc->login($bot_name, $bot_real_name, 0, 'Net_SmartIRC', $bot_password);
foreach ($channels as $chan)
{
	echo date("H:i:s")." - Joining channel $chan...\n";
	//Set mili to 0
	$dataf = new FFDB("data.txt");
	$array = $dataf->get_table($chan);
	$array['mili'] = time()+microtime(true);
	$dataf->write_table($chan,$array);
}
$irc->join($channels);
echo date("H:i:s")." - Listening...\n";
$irc->listen();
echo date("H:i:s")." - Disconnecting...\n";
$irc->disconnect();

?>