I'm working on a more complex timer implementation for 0.4/0.5, will make a post when I got a first running version.
ah nice

until that comes here is the first version with security, settings and table prefix implementation.
if your timer implements loops i'll make a little backflip here

<?php
/*
* CustomTimer.php - enables custom private/open timer.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stensås, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
/*
Add a "_" at the beginning of the file (_ClassName.php) if you do not want it to be loaded.
*/
$db -> query("CREATE TABLE IF NOT EXISTS " . $db -> define_tablename("timers", "true") . " (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`type` VARCHAR( 1 ) NOT NULL ,
`setby` VARCHAR( 100 ) NOT NULL ,
`description` VARCHAR( 255 ) NOT NULL ,
`expires` INT( 11 ) NOT NULL ,
PRIMARY KEY ( `id` )
);");
$customTimer = new CustomTimer($bot);
$commands["tell"]["timer"] = &$customTimer;
$commands["pgmsg"]["timer"] = &$customTimer;
$commands["gc"]["timer"] = &$customTimer;
$cron["2sec"][] = &$customTimer;
/*
The Class itself...
*/
class CustomTimer
{
var $bot;
var $help;
var $timers;
var $output;
var $date_format;
/*
Constructor:
Hands over a referance to the "Bot" class.
Defines access control for the commands
Creates settings for the module
Defines help for the commands
*/
function CustomTimer (&$bot)
{
$this -> bot = &$bot;
$this -> bot -> accesscontrol -> create ('all', 'timer', 'GUEST');
$this -> bot -> settings -> create('CustomTimers', 'date_format', 'M j, Y, G:i', 'sets the format for the date/time shown in the blob window');
$this -> bot -> settings -> create('CustomTimers', 'Security', 'superadmin', 'Defines which group is allowed to delete timers beside the owner');
$this -> help['description'] = 'Custom Timer modul. This enables you to set your own custom timers.';
$this -> help['command']['timer']="- Shows the current timer";
$this -> help['command']['timer o h:m:s <text>']="- Adds a new open timer. Counts in guildchat.";
$this -> help['command']['timer p h:m:s <text>']="- Adds a new private timer. Counts in tell.";
$this -> help['command']['timer del <id>']="- Deletes the timer <id> if you are the owner or have the rights to do it.";
$this -> help['command']['timer reload']="- realoads the timer if something strange is shown.";
$this -> load_timers();
}
/*
This is somewhat a kludge until the internal handling of commands gets altered, in the future, these functions will be depreciated and
the command handler will be called directly.
Just pass off to the unified handler
*/
function tell($source, $msg)
{
$this -> handler ($source, $msg, 1);
}
function pgmsg($source, $msg)
{
$this -> handler ($source, $msg, 2);
}
function gc($source, $msg)
{
$this -> handler ($source, $msg, 3);
}
/*
Unified message handler
$source: The originating player
$msg: The actual message, including command prefix and all
$type: The channel the message arrived from. 1 Being tells, 2 being private groupm 3 being guildchat
*/
function handler($source, $msg, $type)
{
$vars = explode(' ', strtolower($msg));
if (!empty($this -> bot -> commpre))
{
$vars[0] = substr($vars[0], 1);
}
$command = $vars[0];
switch($command)
{
case 'timer':
if($vars[1] == "")
$this -> bot -> send_output($source, $this -> show_timers(), $type);
else if($vars[1] == "o" || $vars[1] == "p")
{
preg_match("/^" . $this -> bot -> commpre . "timer (o|p) ([0-9][0-9]?):([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info);
$this -> bot -> send_output($source, $this -> set_timer($source, $info[1], $info[2], $info[3], $info[4], $info[5]), $type);
}
else if($vars[1] == "del")
$this -> bot -> send_output($source, $this -> delete_timer($source, $vars[2]), $type);
else if($vars[1] == "reload")
$this -> bot -> send_output($source, $this -> reload_timers(), $type);
else
{
$this -> bot -> send_output($source, "##error##Invalid syntax##end##. Please use ##highlight##!timer [o|p] h:m:s text##end##", $type);
}
break;
default:
// Just a safety net to allow you to catch errors where a module has registered a command, but fails to actually do anything about it
// $this -> bot -> send_output($source, $text, $type) will send $text to $source by tell if $type is 1 (tell) or to the apropriate channel if $type is 2 or 3.
$this -> bot -> send_output($source, "Broken plugin, recieved unhandled command: $command", $type);
}
}
function set_timer($name, $type, $hours, $minutes, $seconds, $description)
{
$stamp = mktime() + ($hours*60*60) + ($minutes*60) + $seconds;
$this -> bot -> db -> query("INSERT INTO #___timers (type, setby, description, expires) VALUES ('$type','$name', '$description', $stamp)");
$this -> load_timers();
return "##highlight##Timer set.##end##";
}
function load_timers()
{
$this -> timers = $this -> bot -> db -> select("SELECT * FROM #___timers WHERE expires > ".mktime()." ORDER BY id ASC");
$this -> update_output();
}
function reload_timers()
{
$this -> timers = $this -> bot -> db -> select("SELECT * FROM #___timers WHERE expires > ".mktime()." ORDER BY id ASC");
$this -> update_output();
return "##highlight##Timer neu geladen.##end##";
}
function delete_timer($name, $id)
{
$result = $this -> bot -> db -> select ("SELECT id, setby FROM #___timers WHERE id = $id");
if (empty($result))
return "##error##No timer with that ID.##end##";
if($this -> bot -> security -> check_access($name, $this -> bot -> settings -> get("CustomTimers", "Security")) || strtolower($name) == strtolower($result[0][1]))
{
$this -> bot -> db -> query("DELETE FROM #___timers WHERE id = $id");
$this -> load_timers();
return "##highlight##Timer deleted.##end##";
}
else
{
return "##error##Sorry, you are not allowed to delete this timer.##end##";
}
}
// keeps a list updated so we dont have to make one all the time
function update_output()
{
$output = "";
if (!empty($this -> timers))
{
foreach($this -> timers AS $timer)
{
$dateFrom = date("d-m-Y H:i:s", mktime());
$dateTo = date("d-m-Y H:i:s", $timer[4]);
$diffa = $this -> getDateDifference($dateFrom, $dateTo);
$time_ago = $diffa['days']." days ".$diffa['hours']."h ".$diffa['minutes']. "min ".$diffa['seconds']. "sec left";
if($timer[1] == "p") { $timertype = "private"; }
if($timer[1] == "o") { $timertype = "open"; }
$output .= "\n\n###error##".$timer[0]."##end## :: ##highlight##".$timertype."##end## :: setby ##highlight##".$timer[2]."##end## :: ##normal##".$timer[3]."##end## :: ##highlight##".$time_ago."##end##";
}
}
$this -> output = $output;
}
function show_timers()
{
if (empty($this -> output))
{
return "##error##No timers set.##end##";
}
else
{
$output = "##blob_title##::::: TIMER Overview :::::##end##\n\n";
$output .= "Time now :: ##highlight##" . date($this -> bot -> settings -> get("CustomTimers", "date_format"), mktime())."##end##\n";
$output .= "______________________________________________________\n" . $this -> output;
return "Timers :: " . $this -> bot -> make_blob("click to view", $output);
}
}
function getDateDifference($dateFrom, $dateTo)
{
$difference = null;
$dateFromElements = split(' ', $dateFrom);
$dateToElements = split(' ', $dateTo);
$dateFromDateElements = split('-', $dateFromElements[0]);
$dateFromTimeElements = split(':', $dateFromElements[1]);
$dateToDateElements = split('-', $dateToElements[0]);
$dateToTimeElements = split(':', $dateToElements[1]);
// Get unix timestamp for both dates
$date1 = mktime($dateFromTimeElements[0], $dateFromTimeElements[1], $dateFromTimeElements[2], $dateFromDateElements[1], $dateFromDateElements[0], $dateFromDateElements[2]);
$date2 = mktime($dateToTimeElements[0], $dateToTimeElements[1], $dateToTimeElements[2], $dateToDateElements[1], $dateToDateElements[0], $dateToDateElements[2]);
if( $date1 > $date2 )
{
return null;
}
$diff = $date2 - $date1;
$days = 0;
$hours = 0;
$minutes = 0;
$seconds = 0;
if ($diff % 86400 <= 0) // there are 86,400 seconds in a day
{
$days = $diff / 86400;
}
if($diff % 86400 > 0)
{
$rest = ($diff % 86400);
$days = ($diff - $rest) / 86400;
if( $rest % 3600 > 0 )
{
$rest1 = ($rest % 3600);
$hours = ($rest - $rest1) / 3600;
if( $rest1 % 60 > 0 )
{
$rest2 = ($rest1 % 60);
$minutes = ($rest1 - $rest2) / 60;
$seconds = $rest2;
}
else
{
$minutes = $rest1 / 60;
}
}
else
{
$hours = $rest / 3600;
}
}
$difference = array (
"days" => $days,
"hours" => $hours,
"minutes" => $minutes,
"seconds" => $seconds
);
return $difference;
}
/*
This gets called on cron
*/
function cron()
{
if (empty($this -> timers)) return;
foreach($this -> timers AS $timer)
{
$type = $timer[1]; // o/p
$soruce = $timer[2]; // name
$show = false;
$secleft