BeBot - An Anarchy Online and Age Of Conan chat automaton
Development => Coding and development discussion => Topic started by: clashbot on July 06, 2009, 06:07:37 am
-
Hi my org was recently invited to an alliance, and they are all using 0.4.3 bebot. Naturally, I am running the latest and greatest, and working on converting them (heh heh). In the mean time they have a custom script that they use to pool the online lists into a separate db, and unfortunately it is still using a lot of the depreciated commands that are for 0.4.3. Can I have someone take a look at it and tell me what needs to be changed for it to work on 0.6.3? code is as follows:
<?php
$Allup = new Allup($bot);
$commands["buddy"][] = &$Allup;
$commands["connect"][] = &$Allup;
$commands["gc"]["aonline"] = &$Allup;
$commands["pgmsg"]["aonline"] = &$Allup;
$commands["tell"]["aonline"] = &$Allup;
$commands["gc"]["all"] = &$Allup;
$commands["pgmsg"]["all"] = &$Allup;
$commands["tell"]["all"] = &$Allup;
class Allup
{
var $bot;
var $start;
function Allup (&$bot)
{
$this -> bot = &$bot;
$this -> bot -> accesscontrol -> create("gc", "aonline", "GUEST");
$this -> bot -> accesscontrol -> create("pgmsg", "aonline", "GUEST");
$this -> bot -> accesscontrol -> create("tell", "aonline", "GUEST");
$this -> bot -> accesscontrol -> create("gc", "all", "GUEST");
$this -> bot -> accesscontrol -> create("pgmsg", "all", "GUEST");
$this -> bot -> accesscontrol -> create("tell", "all", "GUEST");
$this -> bot -> settings -> create("Allup", "Enable_send", TRUE, "Should the bot send online list to the alliance database?");
$this -> bot -> settings -> create("Allup", "Enable_all", TRUE, "Should this script be called using the 'online' command?");
$this -> bot -> settings -> create("Allup", "Enable_aonline", TRUE, "Should this script be called using the 'aonline' command?");
$this -> bot -> settings -> create("Allup", "Alliance_address", "hidden database address", "The Internet address for the alliance files.");
$this -> bot -> settings -> create("Allup", "Alliance_password", "hidden database password", "The password for accessing the alliance remote files.");
}
function buddy($name, $msg)
{
if (($this -> start < time()) && ($this -> bot -> settings -> get("Allup", "Enable_send")))
{
if ($this -> bot -> notify -> check($name))
{
$online = $this -> bot -> db -> select("SELECT t1.nickname, level, org_rank, org_name, profession FROM "
. "#___online AS t1 LEFT JOIN #___whois AS t2 ON t1.nickname = t2.nickname WHERE status_gc=1 "
. "ORDER BY profession ASC, t1.nickname ASC");
foreach ($online as $player)
{
$alname .= "|" . $player[0];
$allevel .= "|" . $player[1];
$alprof .= "|" . $player[4];
$alorg .= "|" . $this -> bot -> guildname;
$alrank .= "|" . $player[2];
}
$query = str_replace(" ", "%20", $this -> bot -> settings -> get("Allup", "Alliance_address") . "alliance.php?names="
. substr($alname, 1) . "&levels="
. substr($allevel, 1) . "&profs="
. substr($alprof, 1) . "&orgs="
. substr($alorg, 1) . "&ranks="
. substr($alrank, 1) . "&pwd="
. $this -> bot -> settings -> get("Allup", "Alliance_password"));
file($query);
}
}
}
function connect()
{
$this -> start = time() + 3 * $this -> bot -> crondelay;
}
function tell($source, $msg)
{
$this -> handler ($source, $msg, 1);
}
function pgmsg($source, $msg)
{
$this -> handler ($source, $msg, 2);
}
function gc($source, $msg)
{
$this -> handler ($source, $msg, 3);
}
function handler($source, $msg, $type)
{
$vars = explode(' ', strtolower($msg));
if (!empty($this -> bot -> commpre))
{
$vars[0] = substr($vars[0], 1);
}
$command = $vars[0];
switch($command)
{
case 'aonline':
if ($this -> bot -> settings -> get("Allup", "Enable_aonline"))
{
$the_list = file($this -> bot -> settings -> get("Allup", "Alliance_address") . "online.php");
$inside = implode("", $the_list);
$blob = trim($the_list[0]) . " :: " . $this -> bot -> make_blob("click to view", $inside);
$this -> bot -> send_output($source, $blob, $type);
}
break;
case 'all':
if ($this -> bot -> settings -> get("Allup", "Enable_all"))
{
$the_list = file($this -> bot -> settings -> get("Allup", "Alliance_address") . "online.php");
$inside = implode("", $the_list);
$blob = trim($the_list[0]) . " :: " . $this -> bot -> make_blob("click to view", $inside);
$this -> bot -> send_output($source, $blob, $type);
}
break;
default:
$this -> bot -> send_output($source, "Broken plugin, recieved unhandled command: $command", $type);
}
}
}
?>
-
Have you tried this module with the 0.4.0 support module?
http://bebot.link/0-5-x-customunofficial-modules/0-4_support-for-latest-0-5/
It may work since it can translate old bebot code to work with 0.5.0 and 0.6.2 (in theory)
-
yes I have (as I do use a few of the 0.4.x social modules). It defaults to the broken plugin.
-
ok, I attempted this myself, but messed up somewhere. Looks to be somewhere in the command handler, as it is passing off the user as the $source
Here is the updated code:
<?php
$allup = new allup($bot);
class allup extends BaseActiveModule
{
var $bot;
var $start;
function __construct(&$bot)
{
parent::__construct(&$bot, get_class($this));
$this -> register_command("all", "aonline", "GUEST");
$this -> register_command("all", "all", "GUEST");
$this -> bot -> core("settings") -> create("allup", "Enable_send", TRUE, "Should the bot send online list to the alliance database?");
$this -> bot -> core("settings") -> create("allup", "Enable_all", TRUE, "Should this script be called using the 'all' command?");
$this -> bot -> core("settings") -> create("allup", "Enable_aonline", TRUE, "Should this script be called using the 'aonline' command?");
$this -> bot -> core("settings") -> create("allup", "Alliance_address", "***********", "The internet address for the alliance files.");
$this -> bot -> core("settings") -> create("allup", "Alliance_password", "***********", "The password for accessing the alliance remote files.");
}
function buddy($name, $msg)
{
if (($this -> start < time()) && ($this -> bot -> core("settings") -> get("allup", "Enable_send")))
{
if ($this -> bot -> core("notify") -> check($name))
{
$online = $this -> bot -> db -> select("SELECT t1.nickname, level, org_rank, org_name, profession FROM "
. "#___online AS t1 LEFT JOIN #___whois AS t2 ON t1.nickname = t2.nickname WHERE status_gc=1 "
. "ORDER BY profession ASC, t1.nickname ASC");
foreach ($online as $player)
{
$alname .= "|" . $player[0];
$allevel .= "|" . $player[1];
$alprof .= "|" . $player[4];
$alorg .= "|" . $this -> bot -> guildname;
$alrank .= "|" . $player[2];
}
}
}
}
function connect()
{
$this -> start = time() + 3 * $this -> bot -> crondelay;
}
function tell($source, $msg)
{
$this -> handler ($source, $msg, 1);
}
function pgmsg($source, $msg)
{
$this -> handler ($source, $msg, 2);
}
function gc($source, $msg)
{
$this -> handler ($source, $msg, 3);
}
function command_handler($source, $msg, $type)
{
$vars = explode(' ', strtolower($msg));
if (!empty($this -> bot -> commpre))
{
$vars[0] = substr($vars[0], 1);
}
$command = $vars[0];
switch($command)
{
case 'aonline':
if ($this -> bot -> core("settings") -> get("Allup", "Enable_aonline"))
{
$the_list = file($this -> bot -> core("settings") -> get("Allup", "Alliance_address") . "online.php");
$inside = implode("", $the_list);
$blob = trim($the_list[0]) . " :: " . $this -> bot -> core("tools") -> make_blob("click to view", $inside);
$this -> bot -> core("tools") -> send_output($source, $blob, $type);
}
break;
case 'all':
if ($this -> bot -> core("settings") -> get("Allup", "Enable_all"))
{
$the_list = file($this -> bot -> settings -> get("Allup", "Alliance_address") . "online.php");
$inside = implode("", $the_list);
$blob = trim($the_list[0]) . " :: " . $this -> bot -> core("tools") -> make_blob("click to view", $inside);
$this -> bot -> core("tools") -> send_output($source, $blob, $type);
}
break;
default:
$this -> bot -> send_output($source, "Broken plugin, recieved unhandled command: $command", $type);
}
}
}
?>
-
Remove the if (!empty(compre)) part including the substring in there, the command prefix is removed before handing over commands to the modules now. And remove the var $bot definition, it's done in BaseActiveModule. Otherwise looks ok.
-
ok, running the command I get: undefined function handler(lillitheve, aonline, 1)! on the console
somehow it is passing the character as $source
-
Sorry - either change handler() to command_handler() in the tell(), gc() and pgmsg() functions, or simply remove those three functions.
-
new errors:
using !all gets me: call to member function get() on a non-object line 85
using aonline gets me:
[error] [tools] undefined function send_output(lilltheve, 16 alliance members online :: [link]click to view[/linl],1)!