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: Personal Timers  (Read 4158 times)

0 Members and 1 Guest are viewing this topic.

Offline Wanuarmi

  • Contributor
  • *******
  • Posts: 121
  • Karma: +0/-0
Personal Timers
« on: December 11, 2005, 11:41:53 am »
Been using it for some time and I think its working fine

This will let you set private timers. The bot will send you a tell
when the timer expires, and also 1 hour before it expires.

You need to edit the users array and put your player name or multiple multiple names in it.
It should be easy to make a command to add users, too many timers would lag the bot though.

$this -> users = array("wanuarmi");
$this -> users = array("wanuarmi", "user2");

Commands were made this way to be simple and fast to type

!st HH:MM:SS <description> (sets a timer with hour, minutes and seconds)
!st MM:SS <description> (sets a timer with minutes and seconds)
!st MM <description> (sets a timer with minutes)
!t (shows timers with number, description and remaining time)
!t del <ID> (deletes a timer using the number)
!t sort (id|name|time) (changes timer list sorting; superadmin only)
!t color (id|description|time|alert) (just to test colors without restarting the bot, after you are done you should edit the file; superadmin only)

enjoy :)


modules/PersonalTimers.php
Code: [Select]
<?
$personalTimers = new PersonalTimers($bot);

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

$commands["tell"]["t"] = &$personalTimers;
$commands["tell"]["st"] = &$personalTimers;

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


class PersonalTimers
{
var $bot;
var $timers;
var $users;

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

var $sort_order;


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

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

$this -> sort_order = "expires";

$this -> users = array("wanuarmi");

$this -> get_timers();
}


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



// check permissions and return messages
function process_command($name, $msg)
{
$users = $this -> users;
if (!in_array(strtolower($name), $users))
return "You don't have access to this command.";

if (preg_match("/^" . $this -> bot -> commpre . "t$/i", $msg))
return $this -> show_timers($name);
else if (preg_match("/^" . $this -> bot -> commpre . "t del ([0-9]+)$/i", $msg, $info))
return $this -> delete_timer($name, $info[1]);
else if (preg_match("/^" . $this -> bot -> commpre . "st ([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, 0, $info[1], 0, $info[2]);
else if (preg_match("/^" . $this -> bot -> commpre . "st ([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, 0, $info[1], $info[2], $info[3]);
else if (preg_match("/^" . $this -> bot -> commpre . "st ([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]);
else if (preg_match("/^" . $this -> bot -> commpre . "t sort (id|name|time)$/i", $msg, $info))
{
if ($this -> bot -> admin -> in_group($name, "superadmin"))
return $this -> change_sort($info[1]);
}
else if (preg_match("/^" . $this -> bot -> commpre . "t color (id|description|time|alert) (.*)$/i", $msg, $info))
{
if ($this -> bot -> admin -> in_group($name, "superadmin"))
return $this -> change_color($info[1], $info[2]);
}

return "Invalid syntax. Please use !st HH:MM:SS &lt;description&gt; // !st MM:SS &lt;description&gt; // !st MM &lt;description&gt; // !t // !t del <number>";
}


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


function get_timers()
{
$sort_order = $this -> sort_order;
$this -> timers = $this -> bot -> db -> select("SELECT * FROM personaltimers WHERE expires > ".gmmktime()." ORDER BY $sort_order ASC");
}


function change_sort($new)
{
if ($new == "id") { $this -> sort_order = "id"; }
else if ($new == "name") { $this -> sort_order = "description"; }
else if ($new == "time") { $this -> sort_order = "expires"; }
else { return "Invalid sort mode. Valid modes are (id|name|time)."; }
$this -> get_timers();
return "Sort mode changed to '$new'.";
}


function change_color($change, $color)
{
if ($change == "id") { $this -> id_color = $color; }
else if ($change == "description") { $this -> description_color = $color; }
else if ($change == "time") { $this -> time_color = $color; }
else if ($change == "alert") { $this -> alert_color = $color; }
else { return "Invalid color option. Valid options are (id|description|time|alert)."; }
return ucfirst($change)." color changed to $color.";
}


function delete_timer($name, $id)
{
        $result = $this -> bot -> db -> select ("SELECT id, setby, description FROM personaltimers WHERE id = $id");
        if (empty($result)) { return "No timer with that number."; }
if (strtolower($result[0][1]) != strtolower($name)) { return "No timer with that number."; }
$description = $result[0][2];
$this -> bot -> db -> query("DELETE FROM personaltimers WHERE id = $id");
$this -> get_timers();
return "Personal timer '$description' deleted.";
}


function show_timers($name)
{
if (empty($this -> timers))
{
return "No personal timers set.";
}
else
{
$idcolor = $this -> id_color;
$desccolor = $this -> description_color;
$timecolor = $this -> time_color;

// make output
//$output = "\n<font color=#ffff00>--------------------------------------------------------</font>\n";
$output = "Personal timers";
foreach($this -> timers as $timer)
{
if ($timer[1] == $name)
{
$time = $this -> format_seconds($timer[3] - gmmktime());
$output .= "\n    <font color=$idcolor>$timer[0]. <font color=$desccolor>$timer[2] <font color=$timecolor>$time";
}
}
//$output = "<font color=#ffff00>--------------------------------------------------------</font>";
return $output;
}
}


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()
{
$alertcolor = $this -> alert_color;
$tcolor = $this -> time_color;
if (!empty($this -> timers))
{
foreach($this -> timers as $timer)
{
$secleft = $timer[3] - gmmktime();
if( $secleft <= 3600 && $secleft >= 3599 ) {
$this -> bot -> send_tell($timer[1], "Timer: <font color=$alertcolor>$timer[2] in <font color=$tcolor>1 hour</font>!");
}
else if( $secleft <= 1 ) {
$this -> bot -> send_tell($timer[1], "Timer: <font color=$alertcolor>$timer[2] <font color=$tcolor>now</font>!");
$this -> bot -> db -> query("DELETE FROM personaltimers WHERE id = ".$timer[0]);
$this -> get_timers();
}
}
}
}

}
?>
« Last Edit: January 13, 2006, 07:00:53 am by Wanuarmi »

Offline Wanuarmi

  • Contributor
  • *******
  • Posts: 121
  • Karma: +0/-0
Re: Personal Timers
« Reply #1 on: January 13, 2006, 07:04:01 am »
updated, fixed a bug where all users could see all timers

Offline Plac3bo

  • BeBot User
  • **
  • Posts: 50
  • Karma: +0/-0
Re: Personal Timers
« Reply #2 on: April 28, 2006, 11:34:12 pm »

You need to edit the users array and put your player name or multiple multiple names in it.
It should be easy to make a command to add users, too many timers would lag the bot though.

$this -> users = array("wanuarmi");
$this -> users = array("wanuarmi", "user2");


Could you explain a bit more what needs to be done to the db? array? Im some what confused :)

Offline Tsuyoi

  • BeBot User
  • **
  • Posts: 30
  • Karma: +0/-0
  • BigT
    • Adrenaline Rush Forums
Re: Personal Timers
« Reply #3 on: May 02, 2006, 05:11:33 pm »
You need to edit the users array and put your player name or multiple multiple names in it.
It should be easy to make a command to add users, too many timers would lag the bot though.

$this -> users = array("wanuarmi");
$this -> users = array("wanuarmi", "user2");

Located:
Code: [Select]
function PersonalTimers (&$bot)
{
$this -> bot = &$bot;

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

$this -> sort_order = "expires";

$this -> users = array("wanuarmi");

$this -> get_timers();
}

And is checked:
Code: [Select]
// check permissions and return messages
function process_command($name, $msg)
{
$users = $this -> users;
if (!in_array(strtolower($name), $users))
return "You don't have access to this command.";

if (preg_match("/^" . $this -> bot -> commpre . "t$/i", $msg))
return $this -> show_timers($name);


So basically what you're doing w/ the array is adding all the people who can use this command on your bot.  If you want everyone to be able to use it, remove the check from the process_command function.  It's there basically to keep from everyone adding a ton of timers to the bot for obscure and meaningless reasons as that would bog down your bot without reason.

Hope that helps (and is acurate :D)...

Offline Plac3bo

  • BeBot User
  • **
  • Posts: 50
  • Karma: +0/-0
Re: Personal Timers
« Reply #4 on: June 09, 2006, 03:52:35 pm »
It works great! want a couple more functions, if possible  ::)

!stg sets a global timer that everyone can see
!tg shows global timers
!ta admin users can show all timers global and personal

Possibiliy to set alert at 1 min left and 10 sek left of timer in addition to the 1 hour warning.. :)
« Last Edit: June 09, 2006, 04:03:58 pm by Plac3bo »

Offline Plac3bo

  • BeBot User
  • **
  • Posts: 50
  • Karma: +0/-0
Re: Personal Timers
« Reply #5 on: July 24, 2006, 11:08:53 pm »
I got guildie to modify the code some for me, since I wanted some extra options.
Whats added:
Global timers
Removed hardcoded user array (now checks nickname in members table)

How does it work:
You can still do a !st as normal, but you got an option to do !sgt (set global timer).. global timers will send a tell to every member on timerchecks, wich I ave modifed to be at 1hour left, 10 minutes left and when it expires.
A !t now shows personal and global timers

output looks like this:
 --- Global Timers: ---
 30.  00:55:33  APF (Set by: Nurfest)
 31.  01:46:10  TARA (Set by: Nurfest)
 32.  05:01:06  ZOD> 2nd middle (Set by: Nurfest)
 33.  05:21:19  ZOD> TNH (Set by: Nurfest)
 --- Personal timers ---
    34.  test  00:00:58


It might get lagged down when sending tells to alot of members, what could be done is doing a check for nickname in custom admin groups instead.

heres the code, enjoy :

Code: [Select]
<?
$personalTimers = new PersonalTimers($bot);

$db -> query("CREATE TABLE IF NOT EXISTS `personaltimers` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`setby` VARCHAR( 100 ) NOT NULL ,
`description` VARCHAR( 255 ) NOT NULL ,
`expires` INT( 11 ) NOT NULL ,
`global` tinyint NOT NULL DEFAULT 0,
PRIMARY KEY ( `id` )
);");

$commands["tell"]["t"] = &$personalTimers;
$commands["tell"]["st"] = &$personalTimers;
$commands["tell"]["sgt"] = &$personalTimers;

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


class PersonalTimers
{
var $bot;
var $timers;
var $users;

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

var $sort_order;


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

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

$this->sort_order = "expires";

// check 'select count(*) from members where nickname='.
$this->users =& $this->bot->db->select("select * from members");

$this->get_timers();
}


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



// check permissions and return messages
function process_command($name, $msg)
{
// if this bit doesn`t work again delete $a = mysql_blh below and change $a[0] to $r[0]

        if(in_array($name,$this->users))
return "You don't have access to this command.";

if (preg_match("/^" . $this -> bot -> commpre . "t$/i", $msg))
return $this -> show_timers($name);
else if (preg_match("/^" . $this -> bot -> commpre . "t del ([0-9]+)$/i", $msg, $info))
return $this -> delete_timer($name, $info[1]);
else if (preg_match("/^" . $this -> bot -> commpre . "st ([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, 0, $info[1], 0, $info[2]);
else if (preg_match("/^" . $this -> bot -> commpre . "st ([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_timer($name, 0, $info[1], $info[2], $info[3]);
else if (preg_match("/^" . $this -> bot -> commpre . "st ([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]);
// global versions
else if (preg_match("/^" . $this -> bot -> commpre . "sgt ([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_globalTimer($name, 0, $info[1], 0, $info[2]);
else if (preg_match("/^" . $this -> bot -> commpre . "sgt ([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_globalTimer($name, 0, $info[1], $info[2], $info[3]);
else if (preg_match("/^" . $this -> bot -> commpre . "sgt ([0-9][0-9]?):([0-9][0-9]?):([0-9][0-9]?) (.*)$/i", $msg, $info))
return $this -> set_globalTimer($name, $info[1], $info[2], $info[3], $info[4]);
else if (preg_match("/^" . $this -> bot -> commpre . "t color (id|description|time|alert) (.*)$/i", $msg, $info))
{
if ($this->bot->admin->in_group($name, "superadmin"))
return $this -> change_color($info[1], $info[2]);
}

return "Invalid syntax. Please use !st HH:MM:SS &lt;description&gt; // !st MM:SS &lt;description&gt; // !st MM &lt;description&gt; // !t // !t del <number>";
}


function set_timer($name, $hours, $minutes, $seconds, $description)
{
$stamp = gmmktime() + ($hours*60*60) + ($minutes*60) + $seconds;
$this -> bot -> db -> query("INSERT INTO personaltimers (setby, description, expires, global) VALUES ('$name', '$description', $stamp, 0)");
$this -> get_timers();
return "Personal timer set.";
}

    function set_globalTimer($name, $hours, $minutes, $seconds, $description)
{
$stamp = gmmktime() + ($hours*60*60) + ($minutes*60) + $seconds;
$this->bot->db->query("INSERT INTO personaltimers (setby, description, expires, global) VALUES ('$name', '$description', $stamp, 1)");
$this->get_timers();
return "Global timer set.";
}

function get_timers()
{
$sort_order = $this -> sort_order;
$this->timers = $this->bot->db->select("SELECT * FROM personaltimers WHERE expires > ".gmmktime()." ORDER BY $sort_order ASC");
}


function change_sort($new)
{
if ($new == "id") { $this -> sort_order = "id"; }
else if ($new == "name") { $this -> sort_order = "description"; }
else if ($new == "time") { $this -> sort_order = "expires"; }
else { return "Invalid sort mode. Valid modes are (id|name|time)."; }
$this -> get_timers();
return "Sort mode changed to '$new'.";
}


function change_color($change, $color)
{
if ($change == "id") { $this -> id_color = $color; }
else if ($change == "description") { $this -> description_color = $color; }
else if ($change == "time") { $this -> time_color = $color; }
else if ($change == "alert") { $this -> alert_color = $color; }
else { return "Invalid color option. Valid options are (id|description|time|alert)."; }
return ucfirst($change)." color changed to $color.";
}


function delete_timer($name, $id)
{
        $result = $this->bot->db->select("SELECT id, setby, description FROM personaltimers WHERE id = $id");
        if (empty($result)) { return "No timer with that number."; }
if (strtolower($result[0][1]) != strtolower($name)) { return "No timer with that number."; }
$description = $result[0][2];
$this->bot->db->query("DELETE FROM personaltimers WHERE id = $id");
$this->get_timers();
return "Personal timer '$description' deleted.";
}


function show_timers($name)
{
if (empty($this->timers))
{
return "No personal timers set.";
}
else
{
    $idcolor = $this->id_color;
$desccolor = $this->description_color;
$timecolor = $this->time_color;
    // show global
    $output = "\n --- Global Timers: ---";
    foreach($this->timers as $timer)
{
if($timer[4] == 1)
{
$time = $this->format_seconds($timer[3] - gmmktime());
$output .= "\n <font color=$idcolor>$timer[0]. <font color=\"$timecolor\"> $time  </font><font color=\"$desccolor\">$timer[2]</font> (Set by: $timer[1])";
}
}
// make output
$output .= "\n --- Personal timers ---";
foreach($this->timers as $timer)
{
if(($timer[1] == $name) && ($timer[4] == 0))
{
$time = $this -> format_seconds($timer[3] - gmmktime());
$output .= "\n    <font color=$idcolor>$timer[0]. <font color=$desccolor> $timer[2] </font><font color=$timecolor> $time </font>";
}
}
//$output = "<font color=#ffff00>--------------------------------------------------------</font>";
return $output;
}
}


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()
{
$alertcolor = $this->alert_color;
$tcolor = $this->time_color;
if (!empty($this->timers))
{
    $members =& $this->users;

foreach($this->timers as $timer)
{
    // ok if global iterate through all members sending tells to each else single tell to owner
$secleft = $timer[3] - gmmktime();
if( $secleft <= 3600 && $secleft >= 3599 )
                {
                    if($timer[4] == 1)
                    {
                        foreach($members AS $member)
                            $this->bot->send_tell($member[1], "Timer: <font color=$alertcolor>$timer[2] in <font color=$tcolor>1 hour</font>!");
                    }
                    else
   $this->bot->send_tell($timer[1], "Timer: <font color=$alertcolor>$timer[2] in <font color=$tcolor>1 hour</font>!");
}
else if($secleft <= 600 && $secleft >= 599 )
                {
                    if($timer[4] == 1)
                    {
                        foreach($members AS $member)
                            $this->bot->send_tell($member[1], "Timer: <font color=$alertcolor>$timer[2] in <font color=$tcolor>10 minutes</font>!");
                    }
                    else
                        $this->bot->send_tell($timer[1], "Timer: <font color=$alertcolor>$timer[2] in <font color=$tcolor>10 minutes</font>!");
                }
else if($secleft <= 1 )
                {
                    if($timer[4] == 1)
                    {
                        foreach($members AS $member)
                            $this -> bot -> send_tell($member[1], "Timer: <font color=$alertcolor>$timer[2] <font color=$tcolor>now</font>!");
                    }
                    else
   $this -> bot -> send_tell($timer[1], "Timer: <font color=$alertcolor>$timer[2] <font color=$tcolor>now</font>!");

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

}
?>

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Personal Timers
« Reply #6 on: July 28, 2006, 08:03:14 am »
You can add the aoc -> buddy_online in each instance where it is sending tells to ensure that no tells are sent if member is offline.  Should speed it up somewhat.

IE:

Code: [Select]
$msg = "ZODSNET TIMER: <font color=$dcolor>$timer[2] <font color=$tcolor>now</font>!";
if($timer[4] == 1)
{
foreach($members AS $member)
if ($this -> bot -> aoc -> buddy_online($member[1]))
$this -> bot -> send_tell($member[1], $msg);
$this -> bot -> send_pgroup($msg);
$this -> bot -> send_gc($msg);
}

You could use this SQL to pull names from a particular admin group (in this case "Zodsnet"):

Code: [Select]
$this -> users = $this -> bot -> db -> select ("SELECT admin_members.name FROM admin_members, admin_groups WHERE admin_members.admin_group = admin_groups.id AND admin_groups.name = 'zodsnet'");

Offline Newsworthy

  • BeBot User
  • **
  • Posts: 27
  • Karma: +0/-0
Re: Personal Timers
« Reply #7 on: May 30, 2007, 03:27:52 pm »
I added those codes that check the offline status, and it made a HUGE difference!

I ran this a couple of times without, and, well, my org has over 1k of members, and only 5 online... Lets just say that the bot became somewhat less functional for about, an hour... ;)

 

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