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: Custom Timers  (Read 24915 times)

0 Members and 1 Guest are viewing this topic.

Offline buff

  • BeBot User
  • **
  • Posts: 36
  • Karma: +0/-0
Re: Custom Timers
« Reply #15 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?

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Custom Timers
« Reply #16 on: March 24, 2006, 12:05:04 pm »
Add something like that to the cron job.

Offline Sabkor

  • Contributor
  • *******
  • Posts: 30
  • Karma: +0/-0
Re: Custom Timers
« Reply #17 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();
}
}
}


}
?>

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Custom Timers
« Reply #18 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-

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Custom Timers
« Reply #19 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.
« Last Edit: April 05, 2006, 09:45:22 am by Xenixa »
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline buff

  • BeBot User
  • **
  • Posts: 36
  • Karma: +0/-0
Re: Custom Timers
« Reply #20 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?

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Custom Timers
« Reply #21 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.

Offline buff

  • BeBot User
  • **
  • Posts: 36
  • Karma: +0/-0
Re: Custom Timers
« Reply #22 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 :)

Offline Sabkor

  • Contributor
  • *******
  • Posts: 30
  • Karma: +0/-0
Re: Custom Timers
« Reply #23 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.

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Custom Timers
« Reply #24 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>
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline stonybg

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Custom Timers
« Reply #25 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
« Last Edit: April 17, 2006, 09:39:04 pm by stonybg »

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Custom Timers
« Reply #26 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-

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Custom Timers
« Reply #27 on: January 16, 2007, 02:02:58 am »
- 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 ;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-
« Last Edit: January 16, 2007, 02:53:43 am by jjones666 »

Offline Brianich

  • BeBot Rookie
  • *
  • Posts: 18
  • Karma: +0/-0
  • Kingpin Fixer
Re: Custom Timers
« Reply #28 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
Super "Fixbrian" Girl
RK1, Clan
Current project: No data avaible...

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Custom Timers
« Reply #29 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 :-)
« Last Edit: January 16, 2007, 04:56:52 pm by jjones666 »

 

* 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: 494
  • 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