BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Anarchy Online Archive => 0.4.x Custom/Unofficial Modules => Topic started by: Temar on February 02, 2008, 12:56:57 am
-
This Module will Load the 0.5.0 Modules Making the Apropiate Changes,
Should work with all modules made for Current SVN
This module can be Placed were you want
The 0.5.0 Modules Must be placed in /custom/050/ Folder
What this Module will do is:
- Change all $this -> bot -> core(...) calls to Correct 0.4 calls
- Remove the prefix as 0.5 module dont get the prefix inside the message
Change Log
- 23/06/08 [0.4] - Now Replaces core("time")
- 23/06/08 [0.4] - Now Supports the function get_timer from timer module
- 23/06/08 [0.4] - Return Function of Extended Modules Fixed
- 23/06/08 [0.4] - Register Modules Added
- 23/06/08 [0.4] - Error Class Added
- 24/06/08 [0.5] - Now Supports the function list_timed_events which was added to 0.4 just after 0.4.3 release
- 25/06/08 [0.6] - Added Support for New DB Functions
- 15/07/08 [0.7] - Fixed Issue with Stopping other normal Modules loading
- 25/09/08 [0.8] -
- 20/10/08 [0.9] - Fixed Register_event function
-
heh
thanks
-
Updated to Support Latest SVN modules
-
Interesting error with the latest version of this module.
Fatal error: Call to a member function in_chat() on a non-object in C:\ucom2\core\Security.php on line 1447
Still trying to track this one down but it is right now eluding my limited knowledge.
-
i dont see how this module an cause that prob,
altho the old version did a Chat redirect
im asuming you got a 0.4 bot and useing 0.5 Seurity.php ?
if you read it says you need to put the 0.5 modules in a certain folder, since security.php is a core you can make sure it load with core files by putting this support module in a core folder
-
I havent replace the security module, but I will see if that is the culprit. I did at one time try and use the AccessControlGUI from version 5 but that was deleted (I did have it in the 050 folder). Not sure if that would have modified anything.
The problem ended up being the OnlineDB.php file not being in the right spot.
-
Another bug I thought I would mention is once the module is activated all other modules in the same file location are no longer loaded. I have tested this in both the ./modules folder and ./custom/modules folder.
Any other info I can provide to help this get resolved?
-
since this module has to load the files it self, it cannot load from offical directories as those get loaded
put the 0.5 modules in custom/050/
-
I think that I may have mislead you, all the version 5 modules load properly. It is the older custom 4 modules that are now refusing to load. For example I have the new twitter module loaded in the custom module folder yet when I have the 0.5.0 support module in the same folder it will not load.
c:\mybot\custom\modules\0.5.0_Support.php <- Loads
c:\mybot\custom\modules\twitter.php <- Does not load
c:\mybot\custom\modules\homer.php <- Does not load
c:\mybot\custom\050\onlineorg.php <- Loads
If I disable the module for 0.5.0 support the other modules in the same folder will load
c:\mybot\custom\modules\_0.5.0_Support.php <- Disabled
c:\mybot\custom\modules\twitter.php <- Loads
c:\mybot\custom\modules\homer.php <- Loads
c:\mybot\custom\050\onlineorg.php <- Does not load (for obvious reasons)
Now this is where it gets funky. If I move the twitter.php and homer.php plugin to the main module folder they will load
c:\mybot\custom\modules\0.5.0_Support.php <- Loads
c:\mybot\modules\twitter.php <- Loads
c:\mybot\modules\homer.php <- Loads
c:\mybot\custom\050\onlineorg.php <- Loads
To double back and test completely, I placed the 0.5.0 support module in the main module folder to see what happens.
c:\mybot\modules\0.5.0_Support.php <- Loads
c:\mybot\custom\modules\twitter.php <- Loads
c:\mybot\custom\modules\homer.php <- Loads
c:\mybot\custom\050\onlineorg.php <- Loads
c:\mybot\modules\About.php <- Does not load
So the module is loading all 0.5.0 modules properly it is the other 0.4.0 modules that are now not loading when the support module is in use.
-
ah i realised why,
when support module loads and loads its 050 modules and i used same values as wat loaded support modules
problem is they are still in use as other modules in same folder as support module still need to be loaded
Posted a fix :D
-
Seems to still be doing the same thing. To bypass it I have moved all the other modules back to the main module folder and they load great as long as they dont share the same folder as the 050 support module.
-
Updating with Lots of Aditional Support for 0.5 modules (see Change Log on 1st post)
-
Ok, with the latest updates I am still encountering a problem with the SWStimer.php module. The message below is the error that is last sent before the crash.
Fatal error: Call to undefined method Timer_Core::list_timed_events() in C:\<mybot>\custom\modules\0.5.0_Support.php(60) : eval()'d code on line 124
Let me know if you need any more logs.
-
the function list_timed_events was added to timer core just after 0.4.3 was released, i hd the SVN version of 0.4 so didnt notice
i have Added the function to support module as its a simple function simply get latest version of this
-
I havent replace the security module, but I will see if that is the culprit. I did at one time try and use the AccessControlGUI from version 5 but that was deleted (I did have it in the 050 folder). Not sure if that would have modified anything.
The problem ended up being the OnlineDB.php file not being in the right spot.
omg many thx for that help :)
-
I'm having a problem with the automember module:
Parse error: parse error, unexpected T_VARIABLE, expecting ';' in ...\custom\modules\0.5.0_Support.php(67) : eval()'d cod on line 321
Using Bebot 4.3, any idea what the problem is?
-
its an error in the automember module
Line 314: unset($this -> invites[$name])
add a ; so its
unset($this -> invites[$name]);
unable to update attached file as adding/deleting attachments are currently broke
-
this update will work
* Removed (old)
-
Ok i have Fixed the Register_event function
<?php
// Version 0.9
define("SAME", 1);
define("TELL", 2);
define("GC", 4);
define("PG", 8);
define("RELAY", 16);
define("IRC", 32);
define("ALL", 255);
class BasePassiveModule
{
protected $bot; // A reference to the bot
public $module_name; //Name of the module extending this class.
function __construct (&$bot, $module_name)
{
//Save reference to bot
$this -> bot = &$bot;
$this -> module_name = $module_name;
$this -> link_name = NULL;
$this -> error = new BotError($bot, $module_name);
}
protected function register_event($event, $target=false)
{
$event = strtolower($event);
$events = array('connect', 'disconnect', 'pgjoin', 'pgleave', 'buddy', 'privgroup', 'gmsg', 'cron', 'timer', 'logon_notify', 'pginvite', 'extpgjoin', 'extpgleave', 'tells', 'extprivgroup');
if(in_array($event, $events))
{
if($event == 'gmsg')
{
if ($target)
{
$this -> bot -> commands[$event][$target][get_class($module)] = &$module;
return false;
}
else
{
return "No channel specified for gmsg. Not registering.";
}
}
elseif($event == 'cron')
{
$time = strtotime($target, 0);
if($time > 0)
{
if (!isset($this -> cron_job_active[$time]))
{
$this -> cron_job_active[$time] = false;
}
if (!isset($this -> cron_job_timer[$time]))
{
$this -> cron_job_timer[$time] = max(time(), $this -> startup_time);
}
$this -> cron_times[$time] = $time;
$this -> cron[$time][get_class($module)] = &$module;
return false;
}
else
{
return "Cron time '$target' is invalid. Not registering.";
}
}
elseif ($event == 'timer')
{
if ($target)
{
$this -> bot -> timer -> register_callback($target, &$module);
return false;
}
else
{
return "No name for the timer callback given! Not registering.";
}
}
elseif ($event == 'logon_notify')
{
$this -> bot -> logon_notify -> register(&$module);
return false;
}
else
{
$this -> bot -> commands[$event][get_class($module)] = &$module;
return false;
}
}
else
{
return "Event '$event' is invalid. Not registering.";
}
return false;
}
/* protected function register_module($name)
{
$this -> bot -> register_module(&$this, strtolower($name));
// TODO: Use $module_name in general as $name? May require a bit of code editing - though that has to happen anyways...
// TODO: Everytime a line like $bot -> var = &$class gets replaced with this function do global search and replace!
} */
protected function output($name, $msg, $channel=false)
{
if($channel!==false)
{
if($channel & SAME)
{
if($channel & $this->source)
{
$channel -= SAME;
}
else
{
$channel += $this->source;
}
}
}
else
{
$channel += $this->source;
}
if ($channel & TELL)
$this->bot->send_tell($name, $msg);
if ($channel & GC)
$this->bot->send_gc($msg);
if($channel & PG)
$this->bot->send_pgroup($msg);
if($channel & RELAY)
$this->bot->relay->relay_to_pgroup($name, $msg);
if($channel & IRC)
$this->bot->irc->send_irc($this->module_name, $name, $msg);
}
public function __call($name, $args)
{
$args=implode(', ', $args);
$msg = "Undefined function $name($args)!";
$this->error->set($msg);
return $this->error->message();
}
}
$support_05 = new Support_05($bot);
$bot -> support_05 = &$support_05;
class Support_05
{
var $bot;
function __construct(&$bot)
{
$this -> bot = &$bot;
$this -> update_table($this -> bot -> db -> master_tablename, "schemaversion", "add", "ALTER TABLE ".$this -> bot -> db -> master_tablename." ADD COLUMN schemaversion INT(3) NOT NULL DEFAULT 1", FALSE);
}
function get_timer($id)
{
$ret = $this -> bot -> db -> select("SELECT * FROM #___timer WHERE id = " . $id, MYSQL_ASSOC);
if (empty($ret))
{
return NULL;
}
else
{
return $ret[0];
}
}
function list_timed_events($owner)
{
return $this -> bot -> db -> select("SELECT id, name FROM #___timer WHERE channel = 'internal' AND owner = '"
. $owner . "'", MYSQL_ASSOC);
}
function get_version($table)
{
$version = $this -> bot -> db -> select("SELECT schemaversion, use_prefix FROM " . $this -> bot -> db -> master_tablename . " WHERE internal_name = '" . $table . "'");
if(!empty($version))
{
if($version[0][1] == "false")
{
$version2 = $this -> bot -> db -> select("SELECT schemaversion FROM table_versions WHERE internal_name = '" . $table . "'");
if(!empty($version2))
{
Return($version2[0][0]);
}
}
Return($version[0][0]);
}
else
{
Return(1);
}
}
function set_version($table, $version)
{
if(!is_numeric($version))
{
$this -> bot -> log("DB", "ERROR", "Trying to set version: " . $version . " for table " . $table . "!");
}
else
{
$this -> bot -> db -> query("UPDATE " . $this -> bot -> db -> master_tablename . " SET schemaversion = ".$version." WHERE internal_name = '" . $table . "'");
$usep = $this -> bot -> db -> select("SELECT use_prefix FROM " . $this -> bot -> db -> master_tablename . " WHERE internal_name = '" . $table . "'");
if($usep[0][0] == "false")
{
$this -> bot -> db -> query("INSERT INTO table_versions (internal_name, schemaversion) VALUES ('".$table."', ".$version.") ON DUPLICATE KEY UPDATE schemaversion = VALUES(schemaversion)");
}
}
}
function update_table($table, $column, $action, $query, $prefix = TRUE)
{
if($prefix)
$sql = "#___";
$fields = $this -> bot -> db -> select("EXPLAIN " . $sql . $table, MYSQL_ASSOC);
if (!empty($fields))
{
foreach ($fields AS $field)
{
$columns[$field['Field']] = TRUE;
}
}
Switch(strtolower($action))
{
case 'add': // make sure it doesnt exist
$do = TRUE;
if(is_array($column))
{
foreach($column as $c)
{
if(isset($columns[$c]))
$do = FALSE;
}
}
else
{
if(isset($columns[$column]))
$do = FALSE;
}
if($do)
{
$this -> bot -> db -> query($query);
}
Break;
case 'drop': // Make sure it does exist
case 'alter':
case 'modify':
$do = TRUE;
if(is_array($column))
{
foreach($column as $c)
{
if(!isset($columns[$c]))
$do = FALSE;
}
}
else
{
if(!isset($columns[$column]))
$do = FALSE;
}
if($do)
{
$this -> bot -> db -> query($query);
}
Break;
case 'change':
if(isset($columns[$column[0]]) && !isset($columns[$column[1]]))
{
$this -> bot -> db -> query($query);
}
Break;
Default:
echo "Unknown MYSQL UPDATE Action '".$action."'";
$this -> bot -> db -> query($query);
}
}
}
abstract class BaseActiveModule extends BasePassiveModule
{
public $help; //A window containing help text for this module
protected $source;
function __construct (&$bot, $module_name)
{
//Save reference to bot
parent::__construct(&$bot, $module_name);
}
// Prototype for the command_handler
abstract protected function command_handler($name, $msg, $origin);
// Interface to register command. Now with checks for duplicate command definitions.
// $channel is the channel the command should be registered for. "all" can be used to register a command for gc, pgmsg and tell at once.
// $command is the command to register.
// $access is the minimum access level required to use the command on default.
// $subcommands is an array with keys of subcommands and entries of access levels to define access
// rights for possible subcommands. If $subcommands is NULL it will be ignored.
protected function register_command($channel, $command, $access = "OWNER", $subcommands = NULL)
{
$levels=array('ANONYMOUS', 'GUEST', 'MEMBER', 'LEADER', 'ADMIN', 'SUPERADMIN', 'OWNER');
$channels = array('gc', 'pgmsg', 'tell', 'extpgmsg', 'all');
$allchannels = array ('gc', 'pgmsg', 'tell');
if((in_array($channel, $channels))&&(in_array($access, $levels)))
{
if($channel == "all")
{
$this -> bot -> commands["gc"][$command] = &$this;
$this -> bot -> commands["pgmsg"][$command] = &$this;
$this -> bot -> commands["tell"][$command] = &$this;
}
else
{
$this -> bot -> commands[$channel][$command] = &$this;
}
$this -> bot -> accesscontrol -> create($channel, $command, $access);
if ($subcommands != NULL)
{
foreach ($subcommands AS $subcommand => $subacl)
{
$this -> bot -> accesscontrol -> create_subcommand($channel, $command, $subcommand, $subacl);
}
}
}
else
{
echo "Illegal channel or access level when registering command '$command'\n";
}
}
// Registers a command alias for an already defined command.
protected function register_alias($command, $alias)
{
//$this -> bot -> commandalias -> register($command, $alias);
}
// This function aids in parsing the command.
protected function parse_com($command, $pattern = array('com', 'sub', 'args'))
{
//preg_match for items and insert a replacement.
$search_pattern='|<a href="itemref://([0-9]+)/([0-9]+)/([0-9]{1,3})">([^<]+)</a>|';
$item_count = preg_match_all($search_pattern, $command, $items, PREG_SET_ORDER);
for($cnt = 0; $cnt < $item_count; $cnt++)
{
$command = preg_replace($search_pattern, "##item_$cnt##", $command, 1);
}
//Split the command
$num_pieces=count($pattern);
$num_com=count(explode(' ', $command));
$pieces = explode(' ', $command, $num_pieces);
$com = array_combine(array_slice($pattern, 0, $num_com), $pieces);
//Replace any item references with the original item strings.
foreach($com as &$com_item)
{
for($cnt = 0; $cnt < $item_count; $cnt++)
{
$com_item=str_replace("##item_$cnt##", $items[$cnt][0], $com_item);
}
}
unset($com_item);
return ($com);
}
/************************************************************************
Default to replying in the same channel as the command has been recieved
*************************************************************************/
public function reply($name, $msg)
{
if ($msg != false)
{
if($msg instanceof BotError)
{
//We got an error. Return the error message.
$this->reply($name, $msg->message());
}
else
{
$this -> output($name, "##normal##$msg##end##", SAME);
}
}
}
public function tell($name, $msg)
{
$this->source=TELL;
$this->error->reset();
$reply = $this -> command_handler($name, $msg, "tell");
if(($reply !== false) && ($reply !==''))
{
$this->reply($name, $reply);
}
}
public function gc($name, $msg)
{
$this->source=GC;
$this->error->reset();
$reply = $this -> command_handler($name, $msg, "gc");
if(($reply !== false) && ($reply !==''))
{
$this->reply($name, $reply);
}
}
public function pgmsg($name, $msg)
{
$this->source=PG;
$this->error->reset();
$reply = $this -> command_handler($name, $msg, "pgmsg");
if(($reply !== false) && ($reply !==''))
{
$this->reply($name, $reply);
}
}
}
class BotError
{
private $bot;
protected $status;
private $is_fatal;
private $description;
private $source;
function __construct(&$bot, $module)
{
$this-> status=false;
$this->is_fatal=false;
$this->description='';
$this->source=$module;
$this->bot=$bot;
}
function status()
{
return $this->status;
}
function reset()
{
$this->status=false;
$this->is_fatal=false;
$this->description='';
}
function set($description, $log=true, $fatal=false)
{
$this->description = $description;
$this->is_error=true;
$this->is_fatal = $fatal;
if($log)
{
$this -> bot -> log('ERROR', $this->source, $description);
}
if($fatal)
{
$this -> bot -> log('FATAL', $this->source, $description);
exit(1);
}
}
function get()
{
return $this->description;
}
function message()
{
return "##error##Error: ##end##The module ##highlight##{$this->source}##end## returned the error ##error##{$this->description}##end##";
}
}
if (is_dir("./custom/050"))
{
$bot -> log("050-CUSTOM", "DIR", "Loading Version 0.5.0 Modules in directory custom/050/");
$folder05 = dir("./custom/050/");
while ($mod050 = $folder05 -> read())
{
if (!is_dir($mod050) && !preg_match("/^_/", $mod050) && preg_match("/\.php$/i", $mod050)
&& $value != "FALSE")
{
// get contents of a file into a string
$filename = "./custom/050/".$mod050;
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$contents = str_replace('$this->bot->core->db', '$this -> bot -> core -> db', $contents);
$contents = str_replace('$this->bot->core->timer', '$this -> bot -> core -> timer', $contents);
$contents = str_replace('$this->bot->core', '$this -> bot -> core', $contents);
$contents = str_replace("<?php", "", $contents);
$contents = str_replace("<?", "", $contents);
$contents = str_replace("?>", "", $contents);
$contents = str_replace("function command_handler", 'function command_handler($name, $msg, $type)
{
$msg = substr($msg, 1);
Return $this -> command_handler2($name, $msg, $type);
}
function command_handler2', $contents);
$contents = str_replace('$this -> bot -> core("access_control")', '$this -> bot -> accesscontrol', $contents);
$contents = str_replace('$this -> bot -> core("security")', '$this -> bot -> security', $contents);
$contents = str_replace('$this -> bot -> core("settings")', '$this -> bot -> settings', $contents);
$contents = str_replace('$this -> bot -> core("chat")', '$this -> bot -> chat', $contents);
$contents = str_replace('$this -> bot -> core("help")', '$this -> bot -> help', $contents);
$contents = str_replace('$this -> bot -> core("ini")', '$this -> bot -> ini', $contents);
$contents = str_replace('$this -> bot -> core("chat_queue")', '$this -> bot -> queue', $contents);
$contents = str_replace('$this -> bot -> core("colors")', '$this -> bot -> colors', $contents);
$contents = str_replace('$this -> bot -> core("command_alias")', '$this -> bot -> commandalias', $contents);
$contents = str_replace('$this -> bot -> core("notify")', '$this -> bot -> notify', $contents);
$contents = str_replace('$this -> bot -> core("alts")', '$this -> bot -> alts', $contents);
$contents = str_replace('$this -> bot -> core("logon_notifies")', '$this -> bot -> logon_notify', $contents);
$contents = str_replace('$this -> bot -> core("timer")', '$this -> bot -> timer', $contents);
$contents = str_replace('$this -> bot -> core("user")', '$this -> bot -> user', $contents);
$contents = str_replace('$this -> bot -> core("whois")', '$this -> bot -> whois', $contents);
$contents = str_replace('$this -> bot -> core("shortcuts")', '$this -> bot -> shortcuts', $contents);
$contents = str_replace('$this -> bot -> core("tools")', '$this -> bot', $contents);
$contents = str_replace('$this -> bot -> core("time")', '$this -> bot -> time', $contents);
$contents = str_replace('$this -> bot -> timer -> get_timer', '$this -> bot -> support_05 -> get_timer', $contents);
$contents = str_replace('$this -> bot -> timer -> list_timed_events', '$this -> bot -> support_05 -> list_timed_events', $contents);
$contents = str_replace('$this -> bot -> db -> get_version', '$this -> bot -> support_05 -> get_version', $contents);
$contents = str_replace('$this -> bot -> db -> set_version', '$this -> bot -> support_05 -> set_version', $contents);
$contents = str_replace('$this -> bot -> db -> update_table', '$this -> bot -> support_05 -> update_table', $contents);
$bot -> log("050-CUSTOM", "LOAD", $mod050);
eval($contents);
}
}
echo "\n";
}
?>
-
The latest version now gives the following error when it is in use.
Fatal error: Call to a member function connect() on a non-object in C:\<botdir>\Sources\Bot.php on line 236
Any ideas?
-
Any thoughts on this, I am still having issues with the 0.9 version of the 0.5.0 module regarding the above error.
-
any1 know link to download this?
-
the module is posted inside my post, just above