BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: Akarah on December 04, 2005, 12:12:05 pm
-
yup i was really bored and wanted to whip up something trivial and simple, so here is yet another "core" change, not really a module. i added some graphic elements (icons, seperators) to the Online.php file, and also integrated Alreadythere's whois caching stuff (not that we ever have to whois members... but i guess it never hurts to be thorough ;) )
sample:
(http://ao.rockwood.us/bebot/online-example.jpg)
file:
http://ao.rockwood.us/bebot/Online.phps
rename to .php of course - depends on Alreadythere's WhoisCache module (unless the method is never called..)
cheers,
/Aka
-
hey wow that looks nice...
gonna try it out later
edit: do I have to install the whois cache? I tried it and its saying it cant call a function.
-
i played around with using the images shown during profession selection, but they weren't designed to be alphabetized, and i didn't want to mess up the script any more than i did (ksort() is great.. sorting by fc's order is probably NOT great ;) )
-
is there a version that doesnt use the whois cache? I really liked this... also does the privgroup online list looks like the guild online list?
-
is there a version that doesnt use the whois cache? I really liked this...
Just replace only the function online_list(), should do the trick I think.
Or use Akarah's file, and use the whois() function out of your old Online.php.
Not 100% sure which of those two things is the better way :)
-
yup the only changes affecting display are in online_list()
i didn't test the privgroup, but it uses the same function, so it should.
-
cool thanks :)
-
I like it, and the icons ara rather unintrusive too.
Now, one thing we need, a switch option to allow icons usage to be disabled or enabled.
-
i thought about that as i was falling asleep ;)
-
Oooh, nice one. :)
Copied the bits you added for the graphics into my copy since mines custom modified for formating. Org likes it alot :)
Might I suggest using the settings table if you implement a switch to turn those Icons on/off? Any thing that can be toggled on/off I been keeping in the settings table using that custom function floating around (get_setting) for bot.php
-
made some modifications so the AI level would show if you are not using the whois cache module
<?
/*
* Online.php - Online plugin to display online users
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
*
* Developed by Blondengy (RK1)
* Special thanks goes out to Khalem (RK1) for his support.
*
* File last changed at $LastChangedDate: 2004-12-29 01:41:32 +0100 (Wed, 29 Dec 2004) $
* Revision: $Id: Online.php 8 2004-12-29 00:41:32Z blondengy $
*/
$online = new Online($bot);
$commands["tell"]["online"] = &$online;
$commands["pgmsg"]["online"] = &$online;
$commands["gc"]["online"] = &$online;
$commands["pgjoin"][] = &$online;
$commands["pgleave"][] = &$online;
$commands["buddy"][] = &$online;
$commands["connect"][] = &$online;
$commands["disconnect"][] = &$online;
/*
The Class itself...
*/
class Online
{
var $bot;
var $guild;
var $pgroup;
var $connected;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function Online (&$bot)
{
$this -> bot = &$bot;
$this -> guild = array();
$this -> pgroup = array();
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
$disponline = (($this -> bot -> guildbot) ? "both": "pgroup");
$this -> bot -> send_tell($name, $this -> online_msg($msg, $disponline));
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
if ($this -> bot -> is_member($name))
{
$disponline = (($this -> bot -> guildbot) ? "both": "pgroup");
$this -> bot -> send_pgroup($this -> online_msg($msg, $disponline));
}
}
/*
Gets called on a GC message
*/
function gc($name, $msg)
{
$disponline = (($this -> bot -> guildbot) ? "both": "pgroup");
$this -> bot -> send_gc($this -> online_msg($msg, $disponline));
}
/*
This gets called if someone joins the privgroup
*/
function pgjoin($name)
{
$this -> pgroup[$name] = $this -> whois($name);
}
/*
This gets called if someone leaves the privgroup
*/
function pgleave($name)
{
if (isset($this -> pgroup[$name]))
unset($this -> pgroup[$name]);
}
/*
This gets called if a buddy logs on/off
*/
function buddy($name, $msg)
{
if ($this -> bot -> is_member($name))
{
if ($msg == 1)
$this -> guild[$name] = $this -> whois($name);
else if (isset($this -> guild[$name]))
unset($this -> guild[$name]);
}
}
/*
This gets called when bot disconnects
*/
function disconnect()
{
$this -> guild = array();
$this -> pgroup = array();
}
/*
This gets called when bot connects
*/
function connect()
{
$this -> connected = time() + 120;
}
/*
Makes the message.
*/
function online_msg($msg, $what)
{
preg_match("/^" . $this -> bot -> commpre . "online (.+)$/i", $msg, $info);
if ($info[1] == "all")
$info[1] = "";
$guild = $this -> online_list($this -> guild, $info[1]);
$pgroup = $this -> online_list($this -> pgroup, $info[1]);
$online = "";
$msg = "";
if (($what == "both") || ($what == "guild"))
{
$online .= "<font color=CCInfoHeadline>::: " . $guild[0] . " members online in Guild :::</font>\n" . $guild[1];
$online .= "\n<font color=CCCCTextColor>------------------------------\n";
$msg .= "<font color=#ffff00>" . $guild[0] . "</font> members online in Guild. ";
}
if (($what == "both") || ($what == "pgroup"))
{
$online .= "<font color=CCInfoHeadline>::: " . $pgroup[0] . " players in Privategroup :::</font>\n" . $pgroup[1];
$msg .= "<font color=#ffff00>" . $pgroup[0] . "</font> members in Privategroup. ";
}
$msg .= ":: " . $this -> bot -> make_blob("click to view", $online);
return $msg;
}
/*
Gets info on player
*/
function whois($name)
{
$second = (($this -> bot -> guildbot) ? "rank_name" : "guild");
$result = $this -> bot -> db -> select("SELECT nickname, level, $second, profession, id FROM members WHERE id = " . $this -> bot -> aoc -> get_uid($name));
if (empty($result))
{
$content = $this -> bot -> get_site("http://www.anarchy-online.com/character/bio/d/" . $this -> bot -> dimension . "/name/" . strtolower($name) . "/bio.xml");
$result[0] = $name;
$result[1] = $this -> bot -> xmlparse($content, "level");
$result[2] = $this -> bot -> xmlparse($content, "organization_name");
$result[3] = $this -> bot -> xmlparse($content, "profession");
$result[4] = $this -> bot -> aoc -> get_uid($name);
$result[5] = $this -> bot -> xmlparse($content, "defender_rank_id");
}
else
{
$result = $result[0];
$content = $this -> bot -> get_site("http://www.anarchy-online.com/character/bio/d/" . $this -> bot -> dimension . "/name/" . strtolower($name) . "/bio.xml");
$result[5] = $this -> bot -> xmlparse($content, "defender_rank_id");
}
if (empty($result[3]))
$result[3] = "Unknown";
if (empty($result[1]))
$result[1] = "?";
if (empty($result[2]))
$result[2] = "<i>soloer</i>";
if (empty($result[5]))
$result[5] = "?";
$result[6] = "none";
return $result;
}
/*
make the list of online players
*/
function online_list($online, $like)
{
$profgfx["Meta-Physicist"] = "16308";
$profgfx["Adventurer"] = "84203";
$profgfx["Engineer"] = "16252";
$profgfx["Soldier"] = "16237";
$profgfx["Keeper"] = "84197";
$profgfx["Shade"] = "39290";
$profgfx["Fixer"] = "16300";
$profgfx["Agent"] = "16186";
$profgfx["Trader"] = "117993";
$profgfx["Doctor"] = "44235";
$profgfx["Enforcer"] = "100998";
$profgfx["Bureaucrat"] = "16341";
$profgfx["Martial Artist"] = "16196";
$profgfx["Nano-Technician"] = "16283";
$prof_based = "";
$online_list = "";
$online_num = 0;
if (!empty($online))
{
foreach ($online as $player)
{
$prof_based[$player[3]][(sprintf("%03d", (220 - $player[1])) . $player[0])] = $player;
}
ksort($prof_based);
foreach ($prof_based as $key => $prof)
{
if (preg_match("/" . $like . "/i", $key))
{
$online_list .= "\n<img src=tdb://id:GFX_GUI_FRIENDLIST_SPLITTER>\n";
$online_list .= "<img src=rdb://" . $profgfx[$key] . ">";
$online_list .= " <font color=CCInfoHeader>" . $key . "</font>\n";
$online_list .= "<img src=tdb://id:GFX_GUI_FRIENDLIST_SPLITTER>\n";
ksort($prof);
foreach ($prof as $player)
{
$admin = "";
$online_num++;
$main = $this -> bot -> alts -> main($player[4]);
$alts = $this -> bot -> alts -> get_alts($main);
if ($this -> bot -> admin -> in_group($player[0], "superadmin"))
{
$admin = " :: <font color=#FF0000>Superadmin</font> ";
}
else if ($this -> bot -> admin -> in_group($player[0], "admin"))
{
$admin = " :: <font color=#FF0000>Admin</font> ";
}
else if ($this -> bot -> admin -> in_group($player[0], "raidleader"))
{
$admin = " :: <font color=#FF0000>Raidleader</font> ";
}
if (empty($alts))
{
$alts = "";
}
else if ($main == $this -> bot -> aoc -> get_uname($player[4]))
{
$alts = ":: <a href='chatcmd:///tell <botname> <pre>alts " . $player[0] . "'>Alts</a> ::";
}
else
{
$alts = ":: <a href='chatcmd:///tell <botname> <pre>alts " . $player[0] . "'>" . $main . "'s Alts</a> ";
}
if ($player[6] != "none")
{
$chatclient = "(" . $player[6] . ") ";
}
else
{
$chatclient = "";
}
$online_list .= "<font color=CCCCTextColor> - L " . $player[1] . " / AL " . $player[5] . " <font color=CCInfoText>" . $player[0] . "</font> (" . $player[2] . ") " . $admin . $chatclient . $alts . "</font>";
if($this -> bot -> commands["tell"]["afk"] -> afk[$player[0]])
{
$online_list .= ":: <font color=#FFFFFF>( AFK )</font>\n";
}
else
{
$online_list .= "\n";
}
}
}
}
}
return array($online_num, $online_list);
}
/*
Is called if user is using a chat client...
*/
function chatclient($name, $type)
{
if (isset($this -> guild[$name]))
{
$this -> guild[$name][5] = $type;
}
if (isset($this -> pgroup[$name]))
{
$this -> pgroup[$name][5] = $type;
}
}
}
?>
-
updated link in first post, Online.php now includes a way to change modes
/tell <bot> !online mode fancy to enable
/tell <bot> !online mode basic to disable
this doesn't really scale, and will need to be rewritten if i add more modes, since in a couple places i only do if (fancy) {} else {}
but i don't foresee adding any more modes to the one i use anyway ;p
-
made some modifications so the AI level would show if you are not using the whois cache module
...snip
Heheh, I did that long ago. Post on this forum down there somewhere from me in which also I fixed the displaying of AFK. :P
-
Added to SVN
-
Just minor update to this Module to Keep guest list players from showing in the Members area of the Online list after they are added to the Guest List.
In side this function: /*
This gets called if a buddy logs on/off
*/
function buddy($name, $msg)
{
if ($this -> bot -> is_member($name))
{
if ($msg == 1)
$this -> guild[$name] = $this -> whois($name);
else if (isset($this -> guild[$name]))
unset($this -> guild[$name]);
}
}
Change the if ($this -> bot -> is_member($name)) To read:if ($this -> bot -> is_member($name) == 1)
Discovered when fixing auto invites.
-
Found a bug where people that were removed from guild would show online, even after they logged off, fix shown below (including Xenixa's bugfix)
function buddy($name, $msg)
{
if ($msg == 1)
{
if ($this -> bot -> is_member($name) == 1)
{
if (!isset($this -> bot -> other_bots[$name]))
$this -> guild[$name] = $this -> whois($name);
}
}
else if (isset($this -> guild[$name]))
unset($this -> guild[$name]);
}
-
I actually just coded it in the bot to remove them from the bot's buddylist after someone gets kicked (mine's all auto, once kicked from org, removed from members list, and buddylist and a msg in org chat they were kicked)
But I guess mat's works just as good :P
-
Yeah, I did all that too, but they still show up on the online-list ;)
The problem was that the bot checks if you are a member, if so, it removes you from the online-list if you log off. If you are not a member, it notices that you log off, but because you aren't a member you won't be removed from the online-list.
If you keep your online-list in a DB, it's a lot easier, but BeBot keeps it in internal arrays in Online.php
-
Ah, good point.
I'll have to check it later, maybe I did something to the online list as well, not sure.
-
Ahh ok, I see what you did Mat. That one's been bothering me also(ex-Members getting stuck on online list until bot restart). You moved the online msg check to be first rather than be a sub-conditional check of a member. Heh makes perfect sense now.
Now I'm sitting here thinking "Why didn't I think of that?" :P
Good fix, should be added to SVN copy of Online.php *hint hint, wink wink, nudge nudge*.
-
Compiled with all the fixes and switched to using Glara's new module settings plugin (http://bebot.link/index.php/topic,607.0.html) for the display type switch. Also requires Alreadythere's persistant whois cache (http://bebot.link/index.php/topic,223.msg4523/topicseen.html#new).
http://www.jjones.co.uk/files/online.php
-jj-
p.s. moved to the unofficial 0.2.x modules forum as most of the fixes didn't make it to SVN yet.
-
Does not work for me. The bot always loads Online.php first and exits with an error because it doesn't know the $this -> bot -> set -> create part in line 53. Works for the other modules you posted. These are in the modules directory, and Glara's settings module is already loaded by the time they are loaded. Is there a way to influence the order in which the core modules are loaded?
Also, kinda unrelated, my "users" complained about the many "has joined the guest channel" and "has left the guest channel" messages we often get during raids and orgmeetings. Took me a while to pinpoint the Online.php. I would have somehow expected that code to be in PrivGroup.php or so. :) Anyways, I removed that for me, but maybe a setting to turn the guestchannel announcements on and off would be cool. If someone gives me a hint on how to make Online.php run with the new settings, I can try to code that myself, too.
-
Because files in the /core folder are loaded before the /modules folder and the /core folder is where ModuleSettings.php lives as well as Online.php some tweeking will be needed in Main.php to force ModuleSettings.php to be loaded before Online.php
Either that or MOVE Online.php to the /modules folder for the time being. :) It'll still load and work from there.
-
Here's another work around that leaves Online.php in the /core folder.
Requires editing of Main.php and moving a couple files. This follows the conventions used in v0.3
First, create a new folder under the root folder for the bot called \Sources. I'll use C:\Bebot as an example so path would be C:\Bebot\Sources
Next move(don't copy) the following files to the \Sources folder from the Root bot folder:
MySQL.php
AOChat.php
Bot.php
and move ModuleSettings.php from the \core folder to \Sources also.
Now inside main.php find:
/*
Load the 3 basic modules:
MySQL: Used to communicate with the MySQL database
AOChat: Interface to communicate with AO chat servers
Bot: The actual bot itself.
*/
require_once "MySQL.php";
require_once "AOChat.php";
require_once "Bot.php";
Replace with:
/*
Load the 3 basic modules + Settings module first:
MySQL: Used to communicate with the MySQL database
AOChat: Interface to communicate with AO chat servers
Bot: The actual bot itself.
ModuleSettings: Settings Control for Bot functions.
*/
require_once "./Sources/MySQL.php";
require_once "./Sources/AOChat.php";
require_once "./Sources/Bot.php";
require_once "./Sources/ModuleSettings.php";
Save main.php and restart bot. If you placed all the files in the right place the Settings Module should load before Online.php
-
Sorry, I was testing a different approach while you were posting yours. :) Am trying to get the bot to load the core and modules directories in alphbetical order. This is what I have come up with so far:
// Load up all core-modules
$folder = dir("./core/");
$modules = array();
while ($mod = $folder->read())
{
if (!is_dir($mod) && !preg_match("/^_/", $mod) && preg_match("/php$/i", $mod))
{
array_push($modules, $mod);
}
}
sort($modules);
foreach ($modules as $mod) {
require_once "core/" . $mod;
$bot -> log("CORE", "LOAD", $mod);
}
// Load up all modules
$modules = array();
$folder = dir("./modules/");
while ($mod = $folder->read())
{
if (!is_dir($mod) && !preg_match("/^_/", $mod) && preg_match("/php$/i", $mod) && (($guildbot && !preg_match("/_RAID/", $mod)) || (!$guildbot && !preg_match("/_GUILD/", $mod))))
{
array_push($modules, $mod);
}
}
sort($modules);
foreach ($modules as $mod) {
require_once "modules/" . $mod;
$bot -> log("MOD", "LOAD", $mod);
}
Since ModuleSettings.php comes before Online.php, this already solves my problem. But it would also make it possible to rename them to, say, 01ModuleSettings.php and 02Online.php. All this is ofc not a really nice way to deal with dependancies...
-
I'd personally go my way since that's the direction later versions will take. Not to mention less coding. :)
-
Ah, sources, core and modules is going to be standard? (we are thoroughly derailing this thread...)
My approach isn't really more code, I just posted a lot of context. And... as I said, none of these solutions are the perfect way to deal with dependancies. Would be cool to have something like the way that linux startup scripts in /etc/init.d work. Like, you can state for each module on which other modules it relies and the bot figures out in which order to load them itself. :)
-
OK, back to topic, I do not know if anyone else likes this, but I introduced a new setting to turn the guestchannel leave and join messages on and off.
The following belongs right below the almost identical code in function Online:
if (!isset($this -> bot -> settings['Online']['pgspam']))
{
$module = "Online";
$longdesc = "Show join/leave Privatgroup messages on GC";
$this -> bot -> set -> create ($module, "pgspam", TRUE, $longdesc, "On;Off", FALSE, $disporder=2);
unset($longdesc);
unset($module);
}
The following replaces the two functions with the same names:
/*
This gets called if someone joins the privgroup
*/
function pgjoin($name)
{
$this -> pgroup[$name] = $this -> whois($name);
if ($this -> bot -> settings['Online']['pgspam']) {
$this -> bot -> send_gc($name ." has joined the guest channel");
}
}
/*
This gets called if someone leaves the privgroup
*/
function pgleave($name)
{
if (isset($this -> pgroup[$name]))
unset($this -> pgroup[$name]);
if ($this -> bot -> settings['Online']['pgspam']) {
$this -> bot -> send_gc($name ." has left the guest channel");
}
}
-
Does not work for me. The bot always loads Online.php first and exits with an error because it doesn't know the $this -> bot -> set -> create part in line 53. Works for the other modules you posted. These are in the modules directory, and Glara's settings module is already loaded by the time they are loaded. Is there a way to influence the order in which the core modules are loaded?
Also, kinda unrelated, my "users" complained about the many "has joined the guest channel" and "has left the guest channel" messages we often get during raids and orgmeetings. Took me a while to pinpoint the Online.php. I would have somehow expected that code to be in PrivGroup.php or so. :) Anyways, I removed that for me, but maybe a setting to turn the guestchannel announcements on and off would be cool. If someone gives me a hint on how to make Online.php run with the new settings, I can try to code that myself, too.
Yeah actually, the privgroup notifications should really be in the privgroup.php file I guess, it wasn't in the standard one and because I already had it in the online.php, I didn't add it to my modified privgroup module (which is the one I use).
On the loading of modules, mine loads in alphabetical order. (Modulesettings then Online - obviously modulesettings should also be in the core directory).
The selector for displaying pgspam is a good idea :-)
-jj-
-
Compiled with all the fixes and switched to using Glara's new module settings plugin (http://bebot.link/index.php/topic,607.0.html) for the display type switch. Also requires Alreadythere's persistant whois cache (http://bebot.link/index.php/topic,223.msg4523/topicseen.html#new).
http://www.jjones.co.uk/files/online.php
-jj-
p.s. moved to the unofficial 0.2.x modules forum as most of the fixes didn't make it to SVN yet.
Applied setting to private group notifications as suggested by Pusikas. Same link applies.
-jj-
-
getting fatal error: Call to a member function lookup<> on a non-object in C/bebot/core/online.php on line 216
also using the new module settings as well.
-
It requires the WhoisCache module from:
http://bebot.link/index.php/topic,223.0.html
-
That worked .
Thanks.
-
Is there a way to make it so Online is called whenever someone in the org logs on?
-
Yes.
Add the following inside any module you what. I added mine to the NewNews.php
$commands["buddy"][] = &$CommandName;
$commands["connect"][] = &$CommandName;
function connect()
{
$this -> start = time() + $this -> bot -> crondelay;
}
function buddy($name, $msg)
{
if ($this -> bot -> is_member($name) == 1)
$member = TRUE;
else
$member = FALSE;
if ($this -> start < time()) // We have to be past the start time (prevents spam)
$time = TRUE;
else
$time = FALSE;
if ($msg == 1) // Has to be a sign on event, not a sign off event.
$signon = TRUE;
else
$signon = FALSE;
// If all the conditions above are true, send Online
if ($time AND $signon and $member)
$this -> bot -> commands["tell"]["online"] -> tell($name, $this -> bot -> commpre . "online");
}
-
:::::: nevermind I figured it out after a little investigation ::::::
My guild and I really like this mod.
But I was wondering where can i find the profgfx?
I'd like to make some changes to what gfx is shown in the gump.
Vert~
-
I was kinda annoyed that new toons usually show up with an error message in the !online-window, because their profession is unknown. I added a line like
$profgfx["Unknown"] = "0";
To show them at least with a question mark. Mebbe some other icon would be better (254463 looks really neat :D ), but that was my 2-minute fix after someone from org complained. :)
-
has anyone made a modified version of this to work with level? ie. !online 220 shows people that are online that can team with level 220. this would be very helpful when looking for team.
-
Since no one has what i need... i decided to make one. And once you look at the code you'll prolly know that i'm quite new to php, but it does what i want it to do.
This module requires:
- Wolfbiter's SQL based level (http://bebot.link/index.php/topic,580.0.html)
- Glara's new module settings plugin (http://bebot.link/index.php/topic,607.0.html)
- Alreadythere's persistant whois cache (http://bebot.link/index.php/topic,223.0.html)