BeBot - An Anarchy Online and Age Of Conan chat automaton
Development => Module Requests => Topic started by: Zakus on March 14, 2006, 10:56:09 pm
-
Description:
A module that returns character history retrieved from auno.org in a robust format (similar in functionality to the IGN 'aunobio.php' plugin.
Commands:
!history (Can be used in tells, privategroup and guildchat)
Returns a single page of the parsed results of a lookup to auno.org, including Date, Level, AI Level, Faction, Guild (and rank)
I really found the way that the IGN bot returned info via their !history command to be nicely formatted and useful.
The one by Foxferal, while useful, was lacking in formatting.
My PHP kung fu is nearly non-existant but If nobody picks this up I'll be forced to do something ugly and probably poorly working.
Thanks in advance!
-Zakus
-
I've made some progress, but what I would like to do is call the 'whois' function from the whois module, and take apart what results.
If I can ask this in a way to not make php developers want to kill me:
It looks like I want to do something like:
$this -> whois -> whois($word2);
I could be competely off my rocker, but does that look like I'm headed in the correct direction?
-Z
-
I believe it would be more like $this -> bot -> whois -> whois($name)
But I don't know how you set it up as, nor what you changed etc :P But generally that's what I used when calling external functions.
-
I'd be scary if I knew what I was doing.
Thanks for the referral, I'm going to keep hammering on this.
I actually fixed a problem with the logic that was used in the old IGN plugin. Go me.
-
If you're talking about Alreadythere's whois cache module use this:
$who = $this -> bot -> whois -> lookup($name);
You can find the lookup() function in the WhoisCache.php file to see what it will return and then format as you please.
-
That may be exactly what I was looking for.
Thanks much.
-Z
-
Well, that wasn't the module I was using afterall, but it gave me some examples to play with tomorrow.
In case anyone cares, here is what I'm messing with at this point:
--Edited to reflect new changes 03/15/2006--
<?php
/*
* History.php - Online plugin to display user history
*
* 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.
*
* History.php written by Foxferal (RK1), concept borrowed from IGN Networks
* Hacked to look more like the IGN aunobio module, using ugly code theft, by Zakus - RK1 03/15/2006
*/
$history = new History($bot);
$commands["tell"]["history"] = &$history;
$commands["pgmsg"]["history"] = &$history;
$commands["gc"]["history"] = &$history;
/*
The Class itself...
*/
class History
{
var $fname;
var $lname;
var $orgname;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function History (&$bot)
{
$this -> bot = &$bot;
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_tell($name, $this -> player_history($info[1]));
else
$this -> bot -> send_tell($name, "Player <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_pgroup($this -> player_history($info[1]));
else
$this -> bot -> send_pgroup("Player <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_gc($this -> player_history($info[1]));
else
$this -> bot -> send_gc("Player <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
/*
Get info on player
*/
function player_history($name)
{
$reply = (" No data found for (ucword2) ");
$newurl = "http://auno.org/ao/char.php?output=xml&dimension=" . $this -> bot -> dimension . "&name=".$name;
$data = file_get_contents($newurl);
if (!stristr($data,"no character found") && !empty($data)) {
preg_match_all('|<entry date="(.*)" level="(.*)" ailevel="(.*)" faction="(.*)" guild="(.*)" rank="(.*)" />|Ui', $data, $matches);
$who = $this -> bot -> whois -> lookup($name);
$blob .= "<font color=CCInfoHeadline>Character History For: \n</font>";
$blob .= "<font color=CCInfoHeadline>::: ".$who['firstname']." \"$name\" ".$who['lastname']." :::</font>\n\n";
$blob .= ":: Level/AL: <font color=CCCCTextColor>".$who['level']." / <font color=#33FF33>".$who['at_name']."(".$who['at'].")</font></font>\n";
$blob .= ":: Breed: <font color=CCCCTextColor>".$who['breed']."</font>\n";
$blob .= ":: Gender: <font color=CCCCTextColor>".$who['gender']."</font>\n";
$blob .= ":: Profession: <font color=CCCCTextColor>".$who['profession']."</font>\n";
$blob .= ":: Current Org: <font color=CCCCTextColor>".$who['org']."</font>\n";
$blob .= ":: Org Rank: <font color=CCCCTextColor>".$who['rank']."</font>\n\n";
$blob .= "<font color=CCInfoHeader>Date Level AI Faction Org. and (Rank)</font>\n";
$blob .= "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n";
for($i = 0; $i < count($matches[0]); $i++) {
if(strlen($matches[2][$i])==1){$matches[2][$i]="00".$matches[2][$i];}
if(strlen($matches[2][$i])==2){$matches[2][$i]="0".$matches[2][$i];}
if(strlen($matches[3][$i])==1){$matches[3][$i]="0".$matches[3][$i];}
if(empty($matches[3][$i])){$matches[3][$i]=" ";}
if($matches[4][$i]=="Omni"){$matches[4][$i] .=" ";}
if($matches[4][$i]=="Clan"){$matches[4][$i] .=" ";}
$blob .= "<font color=#ffffff>".$matches[1][$i]."</font> | ";
$blob .= "<font color=CCInfoHeader>".$matches[2][$i]."</font> | ";
$blob .= "<font color=CCInfoText>".$matches[3][$i]."</font> | ";
$blob .= "<font color=#ffffff>".$matches[4][$i]."</font> | ";
if(!empty($matches[5][$i]))
{
$blob .= "<font color=CCInfoHeadline>".$matches[5][$i]." (".$matches[6][$i].")</font>\n";
}
else {$blob .= "Not in Guild\n";}
}
return "History for ".$name." :: " . $this -> bot -> make_blob("click to view", $blob);
}
else
{
return "No name specified.";
}
}
}
?>
-
I don't recall what IGN's History format looks like exactly. But if it looks like what I did with the alts.php for Bebot that would be nifty. You can find an example of what it looks like here:
http://bebot.link/index.php/topic,204.msg1641.html#msg1641
And the code for formating it that way is here:
http://bebot.link/index.php/topic,288.msg1761.html#msg1761
You could use the whois info for the header area then call the History to parse under that.
-
Foxferals History module based on IGN (I dislike the layout)
<?php
/*
* History.php - Online plugin to display user history
*
* 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.
*
* History.php written by Foxferal (RK1), concept borrowed from IGN Networks
*/
$history = new History($bot);
$commands["tell"]["history"] = &$history;
$commands["pgmsg"]["history"] = &$history;
$commands["gc"]["history"] = &$history;
/*
The Class itself...
*/
class History
{
var $bot;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function History (&$bot)
{
$this -> bot = &$bot;
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_tell($name, $this -> player_history($info[1]));
else
$this -> bot -> send_tell($name, "Player <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_pgroup($this -> player_history($info[1]));
else
$this -> bot -> send_pgroup("Player <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_gc($this -> player_history($info[1]));
else
$this -> bot -> send_gc("Player <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
/*
Get info on player
*/
function player_history($name)
{
if($name != "")
{
$result="";
$file = file("http://auno.org/ao/char.php?dimension=" . $this -> bot -> dimension . "&t=auno-print&name=".$name." ");
if(!$file) return "Database is currently not reachable.";
while (list ($radnr, $rad) = each ($file))
{
$result .= $rad;
}
if(!stristr($result,"no character found"))
{
$result = preg_grep('#^<td>200#', explode("\n", $result));
$ymera .= "<font color='CCInfoHeadline'>History for ".$name."<br>";
foreach ($result as $line)
{
$result = str_replace("</td>","",$line);
$result = str_replace("</tr>","<td>",$result);
$result = split("<td>",$result);
if(empty($result[4]))
{
$result[4]="- Not in guild";
}
$ymera .= "<font color='CCInfoHeader'> Date: </font><font color='CCInfoText'>".$result[1] ."</font><font color='CCInfoHeader'> Level: </font><font color='CCInfoText'>".$result[2] ."<br><font color='CCInfoText'>".$result[5]." ".$result[4]." (".$result[3].").</font>\n";
}
$ymera .="<br><font color=CCInfoHeadline>Plugin by Foxferal\n\n";
}
else
{
$ymera = "Character not found";
}
return "History for ".$name." :: " . $this -> bot -> make_blob("click to view", $ymera);
}
else
{
return "No name specified.";
}
}
}
?>
-
My version (layout looks very like IGN, simply because it has the best overview):
<?php
/*
* History.php - Online plugin to display user history
*
* 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.
*
* History.php written by Foxferal (RK1), concept borrowed from IGN Networks
*/
$history = new History($bot);
$commands["tell"]["history"] = &$history;
$commands["gc"]["history"] = &$history;
class History
{
var $bot;
function History (&$bot)
{
$this -> bot = &$bot;
}
function tell($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_tell($name, $this -> player_history($info[1]));
else
$this -> bot -> send_tell($name, "Character <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
function gc($name, $msg)
{
preg_match("/^" . $this -> bot -> commpre . "history (.+)$/i", $msg, $info);
$info[1] = ucfirst(strtolower($info[1]));
if ($this -> bot -> aoc -> get_uid($info[1]))
$this -> bot -> send_gc($this -> player_history($info[1]));
else
$this -> bot -> send_gc("Character <font color=#ffff00>" . $info[1] . "</font> does not exist.");
}
function player_history($name)
{
if($name != "")
{
$result = "";
$file = file("http://auno.org/ao/char.php?dimension=" . $this -> bot -> dimension . "&t=auno-print&name=" . $name . " ");
if (!$file)
return "Database is currently not reachable.";
while (list ($radnr, $rad) = each ($file))
$result .= $rad;
if(!stristr($result, "no character found"))
{
$result = preg_grep('#^<td>200#', explode("\n", $result));
$ymera .= "<font color='CCInfoHeadline'>History for " . $name . "<br><br>";
foreach ($result as $line)
{
$result = str_replace("</td>", "", $line);
$result = str_replace("</tr>", "<td>", $result);
$result = split("<td>", $result);
if (empty($result[5]))
$result[5] = "-";
else
$result[5] = $result[5] . "</font><font color='CCInfoText'> (" . $result[6] . ")";
$ymera .= sprintf("<font color='CCCCTextColor'>%s</font> | <font color='CCInfoText'>%03d</font> | <font color='CCCCTextColor'>%02d</font> | <font color='CCInfoText'>%s</font> | <font color='CCCCTextColor'>%s</font><br>", $result[1], $result[2], $result[3], $result[4], $result[5]);
}
}
else
$ymera = "Character not found";
return "History for " . $name . " :: " . $this -> bot -> make_blob("click to view", $ymera);
}
else
return "No name specified.";
}
}
?>
-
I updated the code listing above.
I'd like input about it if possible.
Additionally, I'm trying to understand how 'make_blob' works, because sometimes the character history goes for more than 1 page, and I'd like to have the header row repeat on subsequent pages.
Any help / suggestions would be appreciated.
-Z
-
I would suggest looking at the Rights Management core module in 0.3.x as it uses an internal counter to detect if the blob if about to be split into multiple.
Its not perfect though as it assumes the default blob size which is subject to change :\
-
Maybe I'll hold off on that header then.. sounds a bit over my head.
The world can live without the header on subsequent pages.
Choose the hill I want to die on... you know? :p
-
Moved discussion to here (http://bebot.link/index.php/topic,618.msg.) and closed this topic.
-jj-