All pastes #584921 Raw Edit

Someone

public text v1 · immutable
·published 2007-06-22 23:53 UTC
rendered paste body
<?php
date_default_timezone_set('EST');

//
// Search for contents of messages
//
if ($msg_parts[0] == "search")
{
	if ($msg_parts[1] == "")
	{
		$msg = "You need to add arguments.";
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
		break;
	}
	$dataf = new FFDB("data.txt");
	$array = $dataf->get_table($recip);
	$more_parts = explode(' ', $msg_parts[1], 10);
	//$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $data->nick.': Searching for "'.$msg_parts[1].'"...');
	$results = 0;
	$i = 1;
	$by = null;
	foreach ($array as $id => $stuff)
	{
		$search = '';
		foreach ($more_parts as $ids => $stuff)
		{
			$by_pos = strpos($more_parts[$ids], "+by:");
			if ($by_pos !== false)
			{
				//echo "Looking for messages by: ".trim($more_parts[$ids],"+by:")."\n";
				$by = trim($more_parts[$ids],"+by:");
			} else {
				$pos = strpos(strtolower($array[$id]['msg']), strtolower($more_parts[$ids]));
				if ($pos === False)
				{
					$search .= '0';
				} else {
					$search .= '1';
				}
			}
		}
		$pos = strpos($search, '0');
		if ($pos === False)
		{
			$time = date('m/d/Y h:m:s e',$array[$id]['time']);
			if ($i < 6)
			{
				if ($by == $array[$id]['user'])
				{
					$msg = $i.". ".ucfirst($array[$id]['user'])." said \"".$array[$id]['msg']."\" on ".$time.".";
					$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
					unset($array[$id]);
					$i++;
				} elseif ($by == null) {
					$msg = $i.". ".ucfirst($array[$id]['user'])." said \"".$array[$id]['msg']."\" on ".$time.".";
					$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
					unset($array[$id]);
					$i++;
				}
				$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, "I = $i");
			}
			$results++;
		}
	}
	if ($results > 0)
	{
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, "Found ".number_format($results)." results.");
	} else {
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, "No results found.");
	}
}
//
// Recall a message from a date/time
//
if ($msg_parts[0] == "recall")
{
	$dataf = new FFDB("data.txt");
	$array = $dataf->get_table($recip);
	$recall = strtotime($msg_parts[1]);
	if ($recall === false)
	{
		$msg = "Date is not compatable.";
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
	} elseif ($recall > strtotime("now"))
	{
			$msg = "The future isn't written.";
			$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
	} else {
		$result = 1;
		$i = 1;
		foreach ($array as $id => $stuff)
		{
			if ($array[$id]['time'] == $recall)
			{
				//Ok, so the time is the same (by golly)
				if ($i < 6)
				{
					$msg = $result.". ".$array[$id]['user']." said ".$array[$id]['msg'].".";
					$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
					$i++;
				}
				$result++;
			}
			for ($offset = 1; $offset < 900; $offset++)
			{
				if ($recall-$offset == $array[$id]['time'] || $recall+$offset == $array[$id]['time'])
				{
					if ($i < 6)
					{
						$msg = $result.". ".$array[$id]['user']." said ".$array[$id]['msg'].".";
						$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
						$i++;
					}
					$result++;
				}
			}
		}
		if ($result == 1)
		{
			$msg = "No results found.";
			$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
		} else {
			$msg = number_format($result)." results found.";
			$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
		}
	}
}
//
// Gets the beginning of time
//
if ($msg_parts[0] == "time")
{
	$dataf = new FFDB("data.txt");
	$array = $dataf->get_table($recip);
	
	$time['past']['time'] = 1000000000;
	$time['past']['msg'] = "";
	$time['past']['user'] = "";
	
	foreach ($array as $id => $stuff)
	{
		if (strtotime("now") - $array[$id]['time'] < $time['past']['time'])
		{
			$time['past']['time'] = strtotime("now") - $array[$id]['time'];
			$time['past']['msg'] = $array[$id]['msg'];
			$time['past']['user'] = $array[$id]['user'];
		}
	}
	
	$msg = "Past: ".$time['past']['user']." said \"".$time['past']['msg']."\" on ".date('m/d/Y h:m:s e',$time['past']['time']).".";
	$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
}
//
// Get the last message posted by a user.
//
if ($msg_parts[0] == "last")
{
	$dataf = new FFDB("data.txt");
	$array = $dataf->get_table($recip);
	$today = strtotime("now");
	$last = array('dif' => 1000000000, 'msg' => '', 'user' => '');
	if ($msg_parts[1] != "")
	{
		//Search for a user
		foreach ($array as $id => $stuff)
		{
			$time = $array[$id]['time'];
			if ($today-$time < $last['dif'] && $last['user'] == $msg_parts[1])
			{
				$last['dif'] = $today - $time;
				$last['msg'] = $array[$id]['msg'];
				$last['user'] = $array[$id]['user'];
			}
		}
		if ($last['msg'] != "")
		{
			$msg = "Last message was \"".$last['msg']."\" by ".$last['user'].".";
		} else {
			$msg = "No user found.";
		}
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
	} else {
		//Or give the last message by any user
		foreach ($array as $id => $stuff)
		{
			$time = $array[$id]['time'];
			if ($today-$time < $last['dif'])
			{
				$last['dif'] = $today - $time;
				$last['msg'] = $array[$id]['msg'];
				$last['user'] = $array[$id]['user'];
			}
		}
		$msg = "Last message was \"".$last['msg']."\" by ".$last['user'].".";
		$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
	}
}
//
// Help
//
if ($msg_parts[0] == "help")
{
	$msg = "Commands: search, last, recall";
	$irc->message(SMARTIRC_TYPE_CHANNEL, $recip, $msg);
	
}

//
// Quit
//
if ($msg_parts[0] == "quit")
{
	if (!admin_identify($data->host,$data->nick,$data->channel)) { return; }
	$irc->quit('Everything has its time and everything dies.');
}

?>