BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: Wanuarmi on November 27, 2005, 11:54:44 pm

Title: Custom Timers
Post by: Wanuarmi on November 27, 2005, 11:54:44 pm
This will add the commands !timer and !timers to your bot.

You can set a timer by using "!timer 0:5:0 Test" to add a 5 minutes timer and so on.

The script will notify the chat group every 2/1 hours, and 30/15/5 minutes before timer expires.

Also you can use "!timer <ID>" to check remaining time.
Title: Custom Timers
Post by: Wanuarmi on November 27, 2005, 11:55:33 pm
help/timer.txt
help/timers.txt

Code: [Select]
<font color=CCInfoHeader><pre>timer | <pre>timers</font>
<font color=CCInfoText>Shows current timers.

<font color=CCInfoHeader><pre>timer &lt;HH:MM:SS&gt; &lt;description&gt;</font>
<font color=CCInfoText>Sets a timer. The timer will be announced 1 hour, 30 minutes, 15 minutes and 5 minutes before it ends.

<font color=CCInfoHeader><pre>timer del &lt;ID&gt;</font>
<font color=CCInfoText>Deletes a timer. Use the ID from the timers list.
Title: Custom Timers
Post by: Khalem on November 27, 2005, 11:57:18 pm
Nice one. Will play with it later :)
Title: Custom Timers
Post by: Xenixa on December 07, 2005, 04:43:32 am
This module is screwed. If there's no Timers in the DB it spams the console with:
Warning: Invalid argument supplied for foreach() in \Bebot\modules\CustomTimers.php on line 69

Also gives the same warning at start up but on line 164.

Suggest you test for Timer entries before you process those code pieces.
Title: Custom Timers
Post by: Wanuarmi on December 07, 2005, 08:52:59 am
try placing

Code: [Select]


if (!empty($this -> timers)) {


}



around those foreach statements, my php doesnt show warnings

I wonder if anyone else is using this, I used it for about two weeks before posting, and so far I havent had problems with it

btw thanks khalem :) tell me if you guys find other problems with it

im not updating it to fix warnings unless thats the way most windows users have php setted for
Title: Custom Timers
Post by: Xenixa on December 07, 2005, 09:22:37 am
The Default for PHP.exe CLI is to show all warnings. Since most Windows users use the very minimal php.ini that comes with the Bot, it's best just to clean the code up so the Warnings don't happen... least the log fills up with a Warning for each time the cron job runs.

I had already placed those if() statements in the copy I'm running btw just so php wasn't spamming the hell out of the php window on my server.
Just wanted you to know it was broken if used as is. The same warnings would appear on Linux/Unix machines also, but I think most users of Linux use a global php.ini that has Warnings like that turned off.
Title: Re: Custom Timers
Post by: Wanuarmi on December 15, 2005, 12:11:11 am
updated, fixed xenixa's bug and did some minor tweakings so the code looks better
Title: Re: Custom Timers
Post by: Wanuarmi on January 09, 2006, 08:55:56 pm
updated, added command !timer <ID> that will show how much time until expiration
Title: Re: Custom Timers
Post by: jokerjr on January 13, 2006, 01:06:36 am
I use this module a lot thanks I love it.
Title: Re: Custom Timers
Post by: Wanuarmi on January 24, 2006, 10:29:47 pm
thanks man, I appreciate it :)

updated, fixed a bug with dates, using gmdate() now instead of date()
Title: Re: Custom Timers
Post by: Glarawyn on February 07, 2006, 01:46:34 am
Hm, tried it on my bot and the time is 6 hours off.

My timezone is set to GMT -6...
Title: Re: Custom Timers
Post by: Wanuarmi on February 07, 2006, 05:50:38 pm
this module uses GMT 0, for it to work on your timezone you would need to change all gmdate() for date() and gmmktime() for mktime()
Title: Re: Custom Timers
Post by: Glarawyn on February 08, 2006, 12:17:21 am
My point is the way you've coded it isn't time zone neutral. I had similar issues when working on my spawn time guesstimator, who would have thought a simple thing like time could have gotten so confusing? :)

The problem is gmmktime() assumes you are passing a GMT timestamp, and using just gmmktime() is fine if your system clock is set to GMT. If however you're system's clock is set to the local time zone, it seems you actually get local time, not GMT. The documentation leads me to believe that you should be getting a GMT timestamp, but in practice gmmktime() is giving me local time.

Using time() would be the correct method as time() always returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT), and hence will always be GMT time no matter what the system time zone is set to.

So in the end, the correct fix is to continue using gmdate(), but use time() instead of gmmktime(). I made this change on my bot and it works fine, and it should work no matter what my time zone the system is using.

(And please feel free to correct me if I've interpreted the PHP documentation incorrectly!)

* Although civil time, e.g., the Greenwich Time Signal in Great Britain, is now based on UTC, it is still popularly called GMT. See UTC (http://en.wikipedia.org/wiki/Utc) and GMT (http://en.wikipedia.org/wiki/Greenwich_Mean_Time) at Wikipedia. :)
Title: Re: Custom Timers
Post by: Wanuarmi on February 08, 2006, 03:09:59 am
I hate php date functions, I always lose time with them trying to get them right. You seem to be right with the time() function, though times are right on my bot and my server's local time isnt gmt. Ill check this out better later.
Title: Re: Custom Timers
Post by: Glarawyn on February 08, 2006, 10:01:21 pm
I hate php date functions, I always lose time with them trying to get them right.

I totally agree.  ;D
Title: Re: Custom Timers
Post by: buff on March 24, 2006, 01:41:02 am
What do I have to modify so bot will send a PM to whoever set the timer when timer goes off or when it is 1hr/30min/15min/5min left?
Title: Re: Custom Timers
Post by: Alreadythere on March 24, 2006, 12:05:04 pm
Add something like that to the cron job.
Title: Re: Custom Timers
Post by: Sabkor on March 28, 2006, 08:13:21 pm
Slightly modified version of this, with the change that buff was asking about above.

Changes:
- sends the timer messages also in a /tell to the person who started the timer, along with pgroup and guild
- if the timer is started via a /tell, it ONLY responds back via a /tell with the timer alerts
- a few more ways of starting timers, it can now be started with any of the following:
timer hh:mm:ss note
timer hh:mm note
timer mm note

Code: [Select]
<?
$customTimers = new CustomTimers($bot);

$db -> query("CREATE TABLE IF NOT EXISTS `timers` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`setby` VARCHAR( 100 ) NOT NULL ,
`description` VARCHAR( 255 ) NOT NULL ,
`expires` INT( 11 ) NOT NULL ,
`tell` BOOLEAN ,
PRIMARY KEY ( `id` )
);"); 

$commands["tell"]["timer"] = &$customTimers;
$commands["pgmsg"]["timer"] = &$customTimers;
$commands["gc"]["timer"] = &$customTimers;
$commands["tell"]["timers"] = &$customTimers;
$commands["pgmsg"]["timers"] = &$customTimers;
$commands["gc"]["timers"] = &$customTimers;

$cron["2sec"][] = &$customTimers;


class CustomTimers
{
var $bot;
var $timers;
var $output;
var $date_format;

var $description_color;
var $time_color;
var $id_color;


function CustomTimers (&$bot)
{
$this -> bot = &$bot;

$this -> date_format = "G:i:s n/j/y";

$this -> description_color = "#31D6FF";//#FF3131
$this -> time_color = "#C6D6FF";
$this -> id_color = "#FFCC66";//white

$this -> load_timers();
}


function tell($name, $msg)
{
$this -> bot -> send_tell($name, $this -> process_command($name, $msg, 1));
}


function pgmsg($name, $msg)
{
$this -> bot -> send_pgroup($this -> process_command($name, $msg, 0));
}


function gc($name, $msg)
{
$this -> bot -> send_gc($this -> process_command($name, $msg, 0));
}


function process_command($name, $msg, $tell)
{
if (preg_match("/^" . $this -> bot -> commpre . "timer$/i", $msg))
return $this -> show_timers();
if (preg_match("/^" . $this -> bot -> commpre . "timers$/i", $msg))
return $this -> show_timers();
if (preg_match("/^" . $this -> bot -> commpre . "timer ([0-9]+)$/i", $msg, $info))
return $this -> show_timer($info[1]);
if (preg_match("/^" . $this -> bot -> commpre . "timer ([0-9][0-9]?):([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, $info[1], $info[2], $info[3], $info[4], $tell);
if (preg_match("/^" . $this -> bot -> commpre . "timer ([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, $info[1], $info[2], 0, $info[3], $tell);
if (preg_match("/^" . $this -> bot -> commpre . "timer ([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, 0, $info[1], 0, $info[2], $tell);
if (preg_match("/^" . $this -> bot -> commpre . "timer del ([0-9]+)$/i", $msg, $info))
return $this -> delete_timer($info[1]);
return "Invalid syntax. Please /tell <bot> !help !timer";
}


function set_timer($name, $hours, $minutes, $seconds, $description, $tell)
{
$stamp = gmmktime() + ($hours*60*60) + ($minutes*60) + $seconds;
$this -> bot -> db -> query("INSERT INTO " . $this -> bot -> get_tablename("timers") . " (setby, description, expires, tell) VALUES ('$name', '$description', $stamp, $tell)");
$this -> load_timers();
return "Timer set.";
}


function load_timers()
{
$this -> timers = $this -> bot -> db -> select("SELECT * FROM " . $this -> bot -> get_tablename("timers") . " WHERE expires > ".gmmktime()." ORDER BY id ASC");
$this -> update_output();
}


function delete_timer($id)
{
        $result = $this -> bot -> db -> select ("SELECT id FROM " . $this -> bot -> get_tablename("timers") . " WHERE id = $id");
        if (empty($result)) return "No timer with that ID.";
$this -> bot -> db -> query("DELETE FROM " . $this -> bot -> get_tablename("timers") . " WHERE id = $id");
$this -> load_timers();
return "Timer deleted.";
}


// keeps a list updated so we dont have to make one all the time
function update_output()
{
$description_color = $this -> description_color;
$time_color = $this -> time_color;
$id_color = $this -> id_color;
$output = "";
if (!empty($this -> timers)) {
foreach($this -> timers AS $timer)
{
$time = gmdate($this -> date_format, $timer[3]);
$output .= "\n\n<font color=$id_color>#$timer[0]  <font color=$description_color>$timer[2]  <font color=$time_color>$time</font></font></font>";
}
}
$this -> output = $output;
}


function show_timers()
{
if (empty($this -> output))
{
return "No timers set.";
}
else
{
$output = "<font color=CCInfoHeader>::::: TIMERS :::::\n" . $this -> output;
$output .= "\n\n\nTime now " . gmdate($this -> date_format, gmmktime());
return "Timers :: " . $this -> bot -> make_blob("click to view", $output);
}
}


function show_timer($id)
{
if (empty($this -> output))
{
return "Timer $id does not exist.";
}
else
{
$dcolor = $this -> description_color;
$tcolor = $this -> time_color;
        $result = $this -> bot -> db -> select ("SELECT * FROM " . $this -> bot -> get_tablename("timers") . " WHERE id = $id");
        if (empty($result)) return "Timer $id does not exist.";
$remain = $this -> format_seconds($result[0][3] - gmmktime());
$desc = $result[0][2];
return "Timer: <font color=$dcolor>$desc in <font color=$tcolor>$remain";
}
}


function format_seconds($totalsec)
{
$hours = floor( $totalsec / (60*60) );
$rest = $totalsec % (60*60);
$minutes = floor( $rest / 60 );
$seconds = $rest % 60;
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
}


function cron()
{
if (empty($this -> timers)) return;

$dcolor = $this -> description_color;
$tcolor = $this -> time_color;
foreach($this -> timers AS $timer)
{
$secleft = $timer[3] - gmmktime();
if( $secleft <= 3600 && $secleft >= 3599 ) {
$msg = "Timer: <font color=$dcolor>$timer[2] in <font color=$tcolor>1 hour</font>!";
if($timer[4] == 0) {
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}
$this -> bot -> send_tell($timer[1], $msg);
}
else if( $secleft <= 7200 && $secleft >= 7199 ) {
$msg = "Timer: <font color=$dcolor>$timer[2] in <font color=$tcolor>2 hours</font>!";
  if($timer[4] == 0) {
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}
$this -> bot -> send_tell($timer[1], $msg);
}
else if( $secleft <= 1800 && $secleft >= 1799 ) {
$msg = "Timer: <font color=$dcolor>$timer[2] in <font color=$tcolor>30 minutes</font>!";
if($timer[4] == 0) {
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}
$this -> bot -> send_tell($timer[1], $msg);
}
else if( $secleft <= 900 && $secleft >= 899 ) {
$msg = "Timer: <font color=$dcolor>$timer[2] in <font color=$tcolor>15 minutes</font>!";
if($timer[4] == 0) {
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}
$this -> bot -> send_tell($timer[1], $msg);
}
else if( $secleft <= 300 && $secleft >= 299 ) {
$msg = "Timer: <font color=$dcolor>$timer[2] in <font color=$tcolor>5 minutes</font>!";
  if($timer[4] == 0) {
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}
$this -> bot -> send_tell($timer[1], $msg);
}
else if( $secleft <= 1 ) {
$msg = "Timer: <font color=$dcolor>$timer[2] <font color=$tcolor>now</font>!";
if($timer[4] == 0) {
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}
$this -> bot -> send_tell($timer[1], $msg);

$this -> bot -> db -> query("DELETE FROM " . $this -> bot -> get_tablename("timers") . " WHERE id = ".$timer[0]);
$this -> load_timers();
}
}
}


}
?>
Title: Re: Custom Timers
Post by: jjones666 on March 28, 2006, 08:53:22 pm
I had to replace GMMKTIME() with TIME() in the previous version as it was quoting GMT time in the text but actually using the time from my system (GMT+1).

Cheers,

-jj-
Title: Re: Custom Timers
Post by: Xenixa on March 30, 2006, 09:10:17 am
gmmktime() is for when running PHP script on Servers with thier System Clocks set to GMT.
Hence the error in the time. :) Why the the PHP Group did it that way is beyond me when Time() is not Time Zone dependent.

Always use time() and date() for systems with thier time/date set to thier current physical time zone.
Use gmdate() to display the correct GMT Date/Time ingame with a local time() stamp.
Title: Re: Custom Timers
Post by: buff on March 31, 2006, 06:28:01 am
Code: [Select]
// keeps a list updated so we dont have to make one all the time
function update_output()
{
$description_color = $this -> description_color;
$time_color = $this -> time_color;
$id_color = $this -> id_color;
$output = "";
if (!empty($this -> timers)) {
foreach($this -> timers AS $timer)
{
$time = gmdate($this -> date_format, $timer[3]);
$output .= "\n\n<font color=$id_color>#$timer[0]  <font color=$description_color>$timer[2]  <font color=$time_color>$time</font></font></font>";
}
}
$this -> output = $output;
}

how do i modify the codes above so when i do !timers
it will show the remaining time on each timer instead of giving me the expire time in gmdate format?
Title: Re: Custom Timers
Post by: Alreadythere on March 31, 2006, 09:46:37 am
$remaining_time = time() - $timer[3];

At least if my limited information is right.
The result will be the remaining seconds of that timer.
Title: Re: Custom Timers
Post by: buff on March 31, 2006, 10:52:53 am
I'm using Sabkor's customtimer module
so if u can take some time and look at his code and tell me how i can modify it to make it show remaining timer instead of the end time in gmdate format that would be awesome :)
Title: Re: Custom Timers
Post by: Sabkor on March 31, 2006, 10:45:54 pm
You could not just rewrite that portion of the file to get it to work that way. The update_output is only run when a timer is added or removed, not every second. If you were to rewrite it to put the seconds left in the list (not the time the timer expires), this would put a larger load on the bot, as it would have to requery the database every 2 seconds to find out all the timers, or it would have to be rewritten to generate the output for that section on the fly (which depending on how often people are checking may not be effeciant). Really, what you are asking is what the !timer <number> command is for.
Title: Re: Custom Timers
Post by: Xenixa on April 01, 2006, 08:57:50 am
An here's an updated timer.txt help file for Sabkor's modifications.
Code: [Select]
<font color=CCInfoHeader>USAGE: <pre>timer | <pre>timers</font>
<font color=CCInfoText>Shows a list of current timers.</font>

<font color=CCInfoHeader><pre>timer &lt;ID&gt;</font>
<font color=CCInfoText>Shows remaining time on a specific timer. Use the ID from the timers list.</font>

<font color=CCInfoHeader><pre>timer &lt;HH:MM:SS&gt; &lt;description&gt;</font>
<font color=CCInfoHeader><pre>timer &lt;HH:MM:&gt; &lt;description&gt;</font>
<font color=CCInfoHeader><pre>timer &lt;MM&gt; &lt;description&gt;</font>
<font color=CCInfoText>Sets a timer. The timer will be announced 1 hour, 30 minutes, 15 minutes and 5 minutes before it ends.</font>

<font color=CCInfoHeader><pre>timer del &lt;ID&gt;</font>
<font color=CCInfoText>Deletes a timer. Use the ID from the timers list.</font>

<font color=CCInfoText>NOTES: - Bot sends the timer messages in a /tell to the person who started the timer, along with guild and guest channel announcements.\n
If the timer is started via a /tell, it ONLY responds back via a /tell with the timer alerts to the person who set it.</font>
Title: Re: Custom Timers
Post by: stonybg on April 17, 2006, 05:48:58 am
have one idea if bee geed to add in replay blob can see after timers (examle: "#1  sdf  7:38:11 4/17/06") add left time in format (example Left Time: .:::days:hh:mm:ss:::.)
tink base in my very litle programer skill need add only one function and edit creation replay blob stile
Sotny
Title: Re: Custom Timers
Post by: jjones666 on April 17, 2006, 07:38:03 pm
Hi all,

What would the correct PHP syntax be to send the tell to all admins, instead of person who updated timer?

Cheers,

-jj-
Title: Re: Custom Timers
Post by: jjones666 on January 16, 2007, 02:02:58 am
- updated to use Glarawyn's New Module Settings plugin (http://bebot.link/index.php/topic,607.msg4218.html#msg4218) (v2.0.3 or above required): configurable time alerts and output locations.
- switched to Europe time format.
- tidied up and expanded output slightly.
- for longer timers (2HR, 1HR, 30mins) it will send the complete timers information as well as alert.

PHP v1 (see below) (http://www.jjones.co.uk/files/customtimers.php)
PHP v2 (see below) (http://www.jjones.co.uk/files/customtimers2.php)
HELP (http://www.jjones.co.uk/files/timer.txt)
HELP (http://www.jjones.co.uk/files/timers.txt)

PHP v1:
removed sending tells back to person who set timer.
added sending timers to selected admin group (ie. raidleader).
configuration with: !set Customtimers admingroup <group> required.

PHP v2:
will send timers back via tell to whoever set them (be that in GC, tell or pgroup).  I didn't test this version but it should work fine.  If not, I'll find out when I add it to org bot tomorrow ;D

Obviously v1 is more suitable to a raidbot type setup due to spamming ability, whereas v2 is meant for normal guildbot.  You can't use both at the same time in case anyone tries ;D

Cheers,

-jj-
Title: Re: Custom Timers
Post by: Brianich on January 16, 2007, 02:41:54 am
Quote
Fatal error: Call to undefined method Bot::get_tablename() in ...blablabla\modules\Customtimers.php on line 137

:D
Title: Re: Custom Timers
Post by: jjones666 on January 16, 2007, 02:46:16 am
ROFL, not much luck :-)

Ok, you need to do the following:-

Open bot.php, somewhere close to the bottom add the following code:-

Code: [Select]

function get_tablename($table)
{
return $table;
}


Updated both files to remove Zodsnet from the timer description :-)
Title: Re: Custom Timers
Post by: Csavarkulcs on February 18, 2007, 06:11:44 pm
Any future plans with implementing a loop option to the timers?  ???
I'd like to try to do it myself, but first i have to learn how to program in php and mysql....  :o

btw v2 works fine
Title: Re: Custom Timers
Post by: buff on March 01, 2007, 03:12:35 am
get this error msg when i use this module in 0.2.11

Fatal error: Call to a member function create() on a non-object in D:\Bebot\Viraid_new\modules\customtimers2.php on line 51


Hope to get this fixed so i can start using the new module, it works fine w/ my 0.2.5 old module XD
Title: Re: Custom Timers
Post by: jjones666 on March 01, 2007, 08:10:25 am
If you are using one of my modules, it requires additionally the module settings plugin: http://bebot.link/index.php/topic,607.msg4218.html#msg4218

-jj-
Title: Re: Custom Timers
Post by: buff on March 01, 2007, 07:49:36 pm
aaah i think i forgot to use that pluggin in the new bebot module XD
I have that in old one ... hehe ;P
Title: Re: Custom Timers
Post by: buff on March 17, 2007, 12:22:38 am
I tried the customtimer2 out, its nice, except 1 part
"everyone" can delete the timer :X
is there anyway to restrict it by only the owner and admins can delete the timer??
Title: Re: Custom Timers
Post by: SalmonSeller on January 07, 2014, 11:16:21 pm
I know this an old thread, but does anyone have these custom timer files that they could upload somewhere? None of these links seem to work any more.

Also, as regards timers, and the !timer command, was it ever made possible to check timers from alt toons (AoC specifically). I saw a few posts that asked for it, and it was something to be looked at, but couldn't spot if it was implemented - something like mentioned here (another old thread): http://bebot.link/feedback-and-suggestions/!timers-suggestions-alts-public-timers-in-tell-different-default-levels/msg10407/#msg10407
SimplePortal 2.3.7 © 2008-2024, SimplePortal