Source for file kernel.class.php
Documentation is available at kernel.class.php
define('VER', 'phpIcqBot v0.1 alpha');
define('ICQBOT_EVENT_RESTART','Restart');
define('ICQBOT_EVENT_CONNECT','Connect');
define('ICQBOT_EVENT_DISCONNECT','Disconnect');
define('ICQBOT_EVENT_COMMAND','Command');
require_once './libs/WebIcqPro.class.php';
require_once './kernel/commands.class.php';
require_once './kernel/logs.class.php';
require_once './kernel/modules.class.php';
require_once './kernel/store.class.php';
require_once './kernel/store/store.flatfile.class.php';
require_once './kernel/users.class.php';
* Shows if phpIcqBot is working
private $terminating = false;
* Variable, if need to do restart
private $restart = false;
* Current configuration (modules, commands, etc)
require_once('./config.inc.php');
require './kernel/install.class.php';
if ($this->terminating = $install->work())
require_once('./config.inc.php');
$this->terminating = true;
echo "Some pity error.. Check permissions to write config.inc.php file.";
//register_shutdown_function(array(&$this, "terminate"));
public function connect($uin = '', $pwd = '')
$result = $this->proto->connect($this->uin, $this->pwd);
$this->logs->write('ICQ ERROR: '. $this->proto->error);
exit($this->proto->error);
$this->logs->write('Connected.');
$this->logs->write('Starting working cycle...');
$this->logs->write('Working cycle finished.');
if (!isset ($msg['from']) || !isset ($msg['message']))
return $this->cmd($msg['from'], substr($msg['message'],1));
return $this->comm->sendMsg($msg['from'],"Unknown command. Send ". CMD_PREF. "help");
public function cmd($uin, $cmd)
if (strpos($cmd," ") !== false)
list ($cmd, $params) = explode(" ",$cmd,2);
$this->commandModules($uin, $cmd, trim($params));
$this->proto->sendMessage($msg[0],$msg[1]);
public function logout($break = false)
$this->logs->write('Logging out.'. ($break? ' Break called.': ''));
$this->proto->disconnect();
private function loadModules()
$modulesList = glob('./modules/*.module.php');
foreach ($included_files as $n=> $f)
if ($modulesList!== FALSE)
foreach ($modulesList as $module)
if ($this->loadModule($module, $included_files) === true)
public function loadModule($moduleName, &$included_files)
if (!preg_match('/([a-z0-9_]+)\.module\.php$/i',$moduleName,$m))
$this->logs->write("Loading module: ". $m[1]. ".module");
if (!in_array($m[1]. '.module.php', $included_files))
$this->logs->write('File "'. $moduleName. '" is not included. Including...');
$this->logs->write('ERROR: file "'. $moduleName. '" doesn\'t exists');
return 'ERROR: file "'. $moduleName. '" doesn\'t exists';
require './modules/'. $m[1]. '.module.php';
$this->logs->write('ERROR: class "'. $mod_name. '" not found in "'. $moduleName. '".');
return 'ERROR: class "'. $mod_name. '" not found in "'. $moduleName. '".';
$this->logs->write('ERROR: class "'. $mod_name. '" is not child of IcqBot_Module class.');
return 'ERROR: class "'. $mod_name. '" is not child of IcqBot_Module class.';
$this->logs->write('ERROR: module "'. $mod_name. '" is already loaded.');
return 'ERROR: module "'. $mod_name. '" is already loaded.';
/** @var $mod IcqBot_Module **/
$this->conf->modules[$mod_name] = array("iface" => ($mod = new $mod_name ($this->comm, $this->logs)), "Commands"=> 0, "Aliases"=> 0);
$mod->setIcqBot($this,$this->conf,$this->proto);
$this->logs->write('Module "'. $m[1]. '.module" loaded. Commands: '. $this->conf->modules[$mod_name]['Commands']. ' '.
'Aliases: '. $this->conf->modules[$mod_name]['Aliases']. ' ');
private function commandModules($uin, $cmd, $params)
$this->logs->write('Error occurs... TERMINATING...');
public function errHandler($errno, $errstr, $errfile, $errline)
$err = "PHP ERROR $errstr ($errno in $errfile on $errline line)";
private function do_restart()
$this->logs->write('Restarting...');
$this->logs->write('Restart complete...');
private function init($restart = false)
$this->proto = new WebIcqPro();
$this->proto->setOption('UserAgent', 'miranda');
$this->logs->write("IcqBot started.");
$this->logs->write("IcqBot restarted.");
$this->logs->write("Loading modules...");
$totalLoaded = $this->loadModules();
$this->logs->write('Total modules loaded: '. $totalLoaded);
private function deinit()
$this->logs->write('Unloading modules...');
foreach($this->conf->modules as $mod_name=> $module)
$this->conf->modules[$mod_name]['iface']->deinit();
unset ($this->conf->modules[$mod_name]['iface']);
unset ($this->conf->modules[$mod_name]);
unset ($this->conf->store);
$this->logs->write('Disconnecting...');
$this->proto->disconnect();
$this->logs->write('Unloading users...');
$this->logs->write('Unloading classes...');
$this->logs->write('Finished...');
foreach ($this->conf->cron as $mod=> $ctime)
list ($mod_name, $key) = explode('@',$mod,2);
$this->conf->cron[$mod]= $t+ $this->conf->timer[$mod_name][$key]['interval'];
* Array of loaded modules
|