collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Timer  (Read 3219 times)

0 Members and 1 Guest are viewing this topic.

Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Timer
« on: July 29, 2007, 01:24:37 pm »
Request :) MUHAHA! :)

I dont know how to do it :)
and the old module did not work. :/

Offline Etric

  • BeBot Rookie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Timer
« Reply #1 on: July 30, 2007, 04:04:39 pm »
This is the Custom Timer Modul i use with the new BeBot.
it's just rewritten and the original code is from someoneelse in this forum (sorry forgett where i've got the code from)

only downside, everyone can delete every timer, this should be changed to the new restriction.

code see below post
« Last Edit: July 30, 2007, 07:26:05 pm by Etric »

Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Re: Timer
« Reply #2 on: July 30, 2007, 04:51:49 pm »
So that timer module dont use the settings module?

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Timer
« Reply #3 on: July 30, 2007, 04:52:01 pm »
Looks like you saved me a bit of work as this was on my personal ToDo list :P

I'll have a look at it later :)
BeBot Founder and Fixer Kingpin

Offline Etric

  • BeBot Rookie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Timer
« Reply #4 on: July 30, 2007, 05:08:10 pm »
So that timer module dont use the settings module?

i've made this more as a personal hack than something that should run for everyone, thats the reason it does'nt use the settings or access restriction parts of the bot (had no need for that)

but it's not that hard to implement this if you wish.

(and just as a side note to Khalem and the rest of the BeBot team: you done an awsome job with the new 0.4.0 version. All the changes since the 0.3 version i've used bevor are really great :)

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Timer
« Reply #5 on: July 30, 2007, 07:18:13 pm »
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.

Offline Etric

  • BeBot Rookie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Timer
« Reply #6 on: July 30, 2007, 07:25:45 pm »
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 :)

Code: [Select]
<?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$msg1);
}

function pgmsg($source$msg)
{
$this -> handler ($source$msg2);
}

function gc($source$msg)
{
$this -> handler ($source$msg3);
}

/*
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 )
       {
           $rest1 = ($rest 3600);
           $hours = ($rest $rest1) / 3600;

           if( $rest1 60 )
           {
               $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 $timer[4] - mktime();
if( $secleft <= 7200 && $secleft >= 7199 )
{
$timeleft "##error##2 hour##end## left!";
$show true;
}
else if( $secleft <= 3600 && $secleft >= 3599 )
{
$timeleft "##error##1 hour##end## left!";
$show true;
}
else if( $secleft <= 1800 && $secleft >= 1799 )
{
$timeleft "##error##30 min##end## left!";
$show true;
}
else if( $secleft <= 900 && $secleft >= 899 )
{
$timeleft "##error##15 min##end## left!";
$show true;
}
else if( $secleft <= 300 && $secleft >= 299 )
{
$timeleft "##error##5 min##end## left!";
$show true;
}
else if( $secleft <= 60 && $secleft >= 59 )
{
$timeleft "##error##1 min##end## left!";
$show true;
}
else if( $secleft <= )
{
$timeleft "##error##NOW!!!##end##";
$this -> bot -> db -> query("DELETE FROM #___timers WHERE id = ".$timer[0]);
$this -> load_timers();
$show true;
}

if($show == true)
{
if($timer[1] == "p")
{
$this -> bot -> send_output($timer[2], "Timer: ##highlight##".$timer[3]."##end## :: ".$timeleft1);
}
else
{
$this -> bot -> send_output($timer[2], "Timer: ##highlight##".$timer[3]."##end## :: ".$timeleft2);
$this -> bot -> send_output($timer[2], "Timer: ##highlight##".$timer[3]."##end## :: ".$timeleft3);
}
}

}
}
}
?>


Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Re: Timer
« Reply #7 on: July 31, 2007, 11:27:08 am »
Ah it looks so good :)
I will put it on my bot as I get home :)

Offline Parfet

  • BeBot User
  • **
  • Posts: 33
  • Karma: +0/-0
Re: Timer
« Reply #8 on: August 01, 2007, 06:00:06 am »
little tip to clear potential errors in descriptions, add the line

$description=mysql_real_escape_string($description);

into the top of the set_timer() fuction, and perhaps other variables as needed

Offline Nytridr

  • BeBot Expert
  • ****
  • Posts: 262
  • Karma: +0/-0
    • Rising Sun
Re: Timer
« Reply #9 on: August 01, 2007, 06:03:28 am »
looks good, but I  do have a suggestion.

have some custom timers that are preset where you can do just a command and the bot will notify you that it has started the timer, and will count the timer down like every 5 mins till it hits zero.

like for raids,
Bio dome raid for the keys, I know there are a few more but cant think of any atm.
Co-Prez of Rising Sun RK1 (1st & only org I will ever belong to)

Offline lazarus

  • BeBot User
  • **
  • Posts: 25
  • Karma: +0/-0
Re: Timer
« Reply #10 on: August 02, 2007, 07:41:24 pm »
OK it work :)

Thro the timer list dont update the time left on the popup. it just remain the same as I told it to time.

Offline Aesgaard

  • BeBot Apprentice
  • ***
  • Posts: 82
  • Karma: +0/-0
  • .:.Alpha.:.
Re: Timer
« Reply #11 on: August 30, 2007, 05:23:36 am »
Really nice module, thank you very much :)
-*tinkers*-

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 689
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal