BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: Areteh on October 02, 2006, 08:51:34 pm

Title: Modified is to accept multiple usernames
Post by: Areteh on October 02, 2006, 08:51:34 pm
Really simple, but damn it was bugging me.  Modified is to accept multiple usernames to check on the same line. 

ie. !is user1 user2 user3 user4
Title: Re: Modified is to accept multiple usernames
Post by: Malosar on October 02, 2006, 10:45:19 pm
Useful :)
Title: Re: Modified is to accept multiple usernames
Post by: Malosar on October 17, 2006, 04:12:02 pm
here's a working version:

Code: [Select]
<?


/*


* Is.php - Check if a player is online.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
*
* Developed by Blondengy (RK1)
* Modified by Areteh (RK1) to support multiple names per command 2006-10-02
* Special thanks goes out to Khalem (RK1) for his support.
*
* File last changed at $LastChangedDate: ... $
* Revision: $Id: Is.php ... $

*/


$is = new Is($bot);


$commands["tell"]["is"] = &$is;
$commands["gc"]["is"] = &$is;
$commands["pgmsg"]["is"] = &$is;
$commands["buddy"][] = &$is;


/*
The Class itself...
*/

class Is
{

var $bot;
var $query;

/*
Constructor:
Hands over a referance to the "Bot" class.
*/

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

/*
This gets called on a tell with the command
*/

function tell($name, $msg)
{
$this -> is_online ($name, $msg);
}

/*
This gets called on a msg in the guildchat with the command
*/

function gc($name, $msg)
{
$this -> is_online ("gc", $msg);
}

/*
This gets called on a msg in the guildchat with the command
*/

function pgmsg($name, $msg)
{
$this -> is_online ("pgroup", $msg);
}

/*
Handles the acutally online/offline code
*/

function is_online ($where, $msg)
{
if(!preg_match("/^" . $this -> bot -> commpre . "is (.+)$/i", $msg, $info))
$msg = "Please enter a valid name.";

else
{
$names = preg_split ("/\s+/", $info[1]);
foreach ($names as $name)
{
$name = ucfirst(strtolower($name));
$msg = "";

if (!$this -> bot -> aoc -> get_uid($name))
$msg = "Player " . $name . " does not exist.";

else if ($name == ucfirst(strtolower($this -> bot -> botname)))
$msg = "I'm online!";

else if ($this -> bot -> aoc -> buddy_exists($name))
{
if ($this -> bot -> aoc -> buddy_online($name))
$msg = $name . " is <font color=#00ff00>online</font>";
else
$msg = $name . " is <font color=#ff0000>offline</font>";
}

else
{
$this -> query[$name] = $where;
$this -> bot -> aoc -> buddy_add($name);
}
                if (!empty($msg) && $where == "gc")
                        $this -> bot -> send_gc($msg);
                else if (!empty($msg) && $where == "pgroup")
                        $this -> bot -> send_pgroup($msg);
                else if (!empty($msg))
                        $this -> bot -> send_tell($where, $msg);
}
}
}

/*
This gets called if a buddy logs on/off
*/

function buddy($name, $msg)
{
if ($this -> bot -> is_member($name) != 1)
{
if (isset($this -> query[$name]))
{
if ($msg == 1)
{
$msg =  $name . " is <font color=#00ff00>online</font>";
}
else
$msg = $name . " is <font color=#ff0000>offline</font>";
if (!empty($msg) && ($this -> query[$name] == "gc"))
$this -> bot -> send_gc($msg);
else if (!empty($msg) && ($this -> query[$name] == "pgroup"))
$this -> bot -> send_pgroup($msg);
else if (!empty($msg))
$this -> bot -> send_tell($this -> query[$name], $msg);
unset($this -> query[$name]);
}
}
}
}

?>
Title: Re: Modified is to accept multiple usernames
Post by: Malosar on December 05, 2006, 04:09:34 pm
Here is an updated version of the Is module supporting multiple names and main/alts checking. 0.2.x version, add table prefix for 0.3.x I guess.

edit: Fixed main/alts offline issue.
Title: Re: Modified is to accept multiple usernames
Post by: pusikas on April 16, 2007, 01:46:59 pm
Questions, because I do not fully understand how the !is command works:

If the toon is on the bot's buddylist already, you check his status with buddy_online? And if he is not, you use buddy_add and wait for the logon event? When does this new buddy get removed? During the next roster update? Is there a problem if I do too many !is in short succession? Can I get over the limit of 1K buddies this way? Why isn't the buddy removed from the list after the logon event has been catched?
Title: Re: Modified is to accept multiple usernames
Post by: jjones666 on April 16, 2007, 02:30:31 pm
You need the queue the check as if you use add_buddy then buddy_online without the queue on the command, 99% of the time it won't work as it takes AO a few seconds to add the buddy to server (by which time script would be finished).  I really don't like this way of doing it, but I think this is AO issue rather than Bebot.

The excess buddies would be removed at bot restart or roster update (6 hours?), whichever is sooner.  I don't think you would ever reach 1000 friends, unless the org roster wasn't in a tidy condition, but yeah its perfectly possible.

-jj-
Title: Re: Modified is to accept multiple usernames
Post by: Alreadythere on April 16, 2007, 02:47:59 pm
The excess buddies get removed with the buddy event I believe, as only members/guests are kept on buddy list.
Title: Re: Modified is to accept multiple usernames
Post by: Malosar on April 16, 2007, 03:04:34 pm
With the way the !is is coded atm, the excess buddies get removed on roster update or bot restart.

[2007-04-16 12:57:50]   [BUDDY] [DEL]   Sheena
[2007-04-16 12:57:50]   [BUDDY] [DEL]   Vimsemp
[2007-04-16 12:57:50]   [BUDDY] [DEL]   Kylu
[2007-04-16 12:57:50]   [BUDDY] [DEL]   Shootroxj00
[2007-04-16 12:57:50]   [ROSTER]        [UPDATE]        Roster update complete. Added 1 members, removed 4.
Title: Re: Modified is to accept multiple usernames
Post by: pusikas on April 16, 2007, 03:20:58 pm
The excess buddies would be removed at bot restart or roster update (6 hours?), whichever is sooner.  I don't think you would ever reach 1000 friends, unless the org roster wasn't in a tidy condition, but yeah its perfectly possible.

I recently kicked like 120 peeps, because we were getting awfully close to 1K...  ;D Yeah, guess that was not a tidy condition.
SimplePortal 2.3.7 © 2008-2024, SimplePortal