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, 12:39:45 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: Personal Timers
Pages: [1]   Go Down
« previous next »
Print
Author Topic: Personal Timers  (Read 1508 times)
0 Members and 1 Guest are viewing this topic.
Wanuarmi
BeBot Contributor
Apprentice
*******
Offline Offline

Posts: 121


Personal Timers
« on: December 11, 2005, 05: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 Smiley


modules/PersonalTimers.php
Code:
<?
$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, 01:00:53 AM by Wanuarmi » Logged
Wanuarmi
BeBot Contributor
Apprentice
*******
Offline Offline

Posts: 121


Re: Personal Timers
« Reply #1 on: January 13, 2006, 01:04:01 AM »

updated, fixed a bug where all users could see all timers
Logged
Plac3bo
Rookie
**
Offline Offline

Gender: Male
Posts: 50



Re: Personal Timers
« Reply #2 on: April 28, 2006, 04:34:12 PM »

Quote from: Wanuarmi on December 11, 2005, 05:41:53 AM

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 Smiley
Logged
Tsuyoi
Rookie
**
Offline Offline

Gender: Male
Posts: 30


BigT


WWW
Re: Personal Timers
« Reply #3 on: May 02, 2006, 10:11:33 AM »

Quote from: Wanuarmi on December 11, 2005, 05:41:53 AM
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:
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:
// 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 Cheesy)...
Logged
Plac3bo
Rookie
**
Offline Offline

Gender: Male
Posts: 50



Re: Personal Timers
« Reply #4 on: June 09, 2006, 08:52:35 AM »

It works great! want a couple more functions, if possible  Roll Eyes

!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.. Smiley
« Last Edit: June 09, 2006, 09:03:58 AM by Plac3bo » Logged
Plac3bo
Rookie
**
Offline Offline

Gender: Male
Posts: 50



Re: Personal Timers
« Reply #5 on: July 24, 2006, 04: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:
<?
$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();
}
}
}
}

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

Posts: 353


Re: Personal Timers
« Reply #6 on: July 28, 2006, 01: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:
$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:
$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'");
Logged
Newsworthy
Rookie
**
Offline Offline

Posts: 27


Re: Personal Timers
« Reply #7 on: May 30, 2007, 08:27:52 AM »

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... Wink
Logged
Pages: [1]   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: Personal 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: 2
Guests: 20
Total: 22
xlDanek
Temar

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