L* R*
HOME FORUM DOWNLOADS
Content
  Links
     Browse SVN
     SVN Commit log
     Documentation (Wiki)
  Developers
     Taskmanager
User
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 22, 2008, 01:55:35 PM

Login with username, password and session length
Search



Advanced search
Support GoPHP5.org
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Modules > Modules for older versions > 0.2.x Custom/Unofficial Modules > Topic: Custom Timers
Pages: 1 [2] 3   Go Down
« previous next »
Print
Author Topic: Custom Timers  (Read 3707 times)
0 Members and 1 Guest are viewing this topic.
buff
Rookie
**
Offline Offline

Posts: 36


Re: Custom Timers
« Reply #15 on: March 23, 2006, 07:41:02 PM »

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?
Logged
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1077


Re: Custom Timers
« Reply #16 on: March 24, 2006, 06:05:04 AM »

Add something like that to the cron job.
Logged
Sabkor
Rookie
**
Offline Offline

Posts: 21


Re: Custom Timers
« Reply #17 on: March 28, 2006, 01: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:
<?
$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();
}
}
}


}
?>
Logged
jjones666
BeBot Contributor
Champion
*******
Offline Offline

Posts: 353


Re: Custom Timers
« Reply #18 on: March 28, 2006, 01: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-
Logged
Xenixa
BeBot Contributor
Expert
*******
Offline Offline

Posts: 307



Re: Custom Timers
« Reply #19 on: March 30, 2006, 02: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. Smiley 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.
« Last Edit: April 05, 2006, 02:45:22 AM by Xenixa » Logged

<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky
buff
Rookie
**
Offline Offline

Posts: 36


Re: Custom Timers
« Reply #20 on: March 30, 2006, 11:28:01 PM »

Code:
// 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?
Logged
Alreadythere
BeBot Maintainer
Administrator
Grandmaster
********
Offline Offline

Posts: 1077


Re: Custom Timers
« Reply #21 on: March 31, 2006, 02: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.
Logged
buff
Rookie
**
Offline Offline

Posts: 36


Re: Custom Timers
« Reply #22 on: March 31, 2006, 03: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 Smiley
Logged
Sabkor
Rookie
**
Offline Offline

Posts: 21


Re: Custom Timers
« Reply #23 on: March 31, 2006, 03: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.
Logged
Xenixa
BeBot Contributor
Expert
*******
Offline Offline

Posts: 307



Re: Custom Timers
« Reply #24 on: April 01, 2006, 01:57:50 AM »

An here's an updated timer.txt help file for Sabkor's modifications.
Code:
<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>
Logged

<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky
stonybg
Rookie
**
Offline Offline

Posts: 23


Re: Custom Timers
« Reply #25 on: April 16, 2006, 10:48:58 PM »

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
« Last Edit: April 17, 2006, 02:39:04 PM by stonybg » Logged
jjones666
BeBot Contributor
Champion
*******
Offline Offline

Posts: 353


Re: Custom Timers
« Reply #26 on: April 17, 2006, 12: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-
Logged
jjones666
BeBot Contributor
Champion
*******
Offline Offline

Posts: 353


Re: Custom Timers
« Reply #27 on: January 15, 2007, 08:02:58 PM »

- updated to use Glarawyn's New Module Settings plugin (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)
PHP v2 (see below)
HELP
HELP

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 Grin

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 Grin

Cheers,

-jj-
« Last Edit: January 15, 2007, 08:53:43 PM by jjones666 » Logged
Brianich
Freshman
*
Offline Offline

Gender: Male
Posts: 18


Kingpin Fixer


Re: Custom Timers
« Reply #28 on: January 15, 2007, 08:41:54 PM »

Quote
Fatal error: Call to undefined method Bot::get_tablename() in ...blablabla\modules\Customtimers.php on line 137

Cheesy
Logged

Super "Fixbrian" Girl
RK1, Clan
Current project: No data avaible...
jjones666
BeBot Contributor
Champion
*******
Offline Offline

Posts: 353


Re: Custom Timers
« Reply #29 on: January 15, 2007, 08:46:16 PM »

ROFL, not much luck :-)

Ok, you need to do the following:-

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

Code:

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


Updated both files to remove Zodsnet from the timer description :-)
« Last Edit: January 16, 2007, 10:56:52 AM by jjones666 » Logged
Pages: 1 [2] 3   Go Up
Print
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Modules > Modules for older versions > 0.2.x Custom/Unofficial Modules > Topic: Custom Timers
« previous next »
 
Jump to:  

Recent
Change text in remember "...
by gerborg
[November 21, 2008, 05:14:57 PM]

Log playtime from buddys ...
by Temar
[November 20, 2008, 10:33:57 AM]

Vote Core module and Simp...
by Temar
[November 19, 2008, 09:26:52 AM]

Restrict access for one m...
by Organizer
[November 19, 2008, 03:21:19 AM]

Custom / Revised Modules ...
by Elesar1
[November 17, 2008, 03:51:46 PM]

TWC
by Temar
[November 16, 2008, 11:39:12 AM]

Are there any FUN modules...
by Elesar1
[November 15, 2008, 07:39:15 PM]

Call to a member function...
by exxie
[November 15, 2008, 09:29:31 AM]

Ported Modules
by Alreadythere
[November 14, 2008, 06:10:07 PM]

cURL and other non-defaul...
by Temar
[November 14, 2008, 04:11:44 PM]
Stats
Members
Total Members: 1235
Latest: DDDepressionnn
Stats
Total Posts: 11037
Total Topics: 1496
Online Today: 18
Online Ever: 168
(July 01, 2007, 09:30:02 PM)
Users Online
Users: 0
Guests: 23
Total: 23

Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.8 © Bloc | NewDef design by Bloc
Page created in 1.247 seconds with 29 queries. (Pretty URLs adds 0.047s, 4q)
Loading...