Source for file main.module.php
Documentation is available at main.module.php
* Main (Admin) Module is used for controlling bot.
* Now available commands:
* - !mod - for controlling modules
* - !roles - for controlling users
* - !stop - the exit command for bot
* - !restart - restart command (tries to load new modules)
* @author Jector <no.one.on@gmail.com>
* Standart initialization function
$this->commands->addCommand($this, 'about');
$this->commands->addCommand($this, 'restart');
$this->commands->addCommand($this, 'exit', array('die','bye','quit','stop','выход'));
$this->commands->addCommand($this, 'help', array('h'));
$this->commands->addCommand($this, 'roles');
$this->commands->addCommand($this, 'mod', array('module','modules'));
* Standart deinitialization function
* Returns information about phpIcqBot like version, author, etc
$this->commands->sendMsg($uin, VER. "\r\nAuthor: NoOne <jector@inbox.ru>\r\nSpecial thanks for hosting: schAlexey");
* Terminate working of phpIcqBot.
* It's not really stop it here, but just set WORKING flag to false.
$this->commands->sendMsg($uin, 'Access denied.');
$this->logs->write('EXIT command from '. $uin);
$this->icqbot->working = false;
* Do restart of phpIcqBot.
* It's not really restart it here, but just set RESTART flag to true.
$this->commands->sendMsg($uin, 'Access denied.');
$this->logs->write('RESTART command from '. $uin);
$this->commands->sendMsg($uin, "Restarting...");
* Supports help system of phpIcqBot.
* @todo A lot of changes will be here
* @todo do some thing, if no params specified
list ($cmd, $params) = explode(' ', $params, 2);
if (!isset ($this->conf->commands[$cmd]))
return $this->commands->sendMsg($uin, 'Command "'. $cmd. '" doesn\'t exist');
$command = $this->conf->commands[$cmd];
return $this->commands->sendMsg($uin, 'Command "'. $cmd. '" doesn\'t have help');
$this->commands->sendMsg($uin, 'Command "'. $cmd. "\":\r\n". $help);
* Command, which controls phpIcqBot modules
* - !mod cmdlist <modulename|modulenum>
* - !mod info <modulename|modulenum>
* @todo params for load/unload modules
list ($cmd, $params) = explode(' ', $params, 2);
$msg = 'Please, specify module\'s name of number from !mod list';
$params= 'IcqBot_Module_'. $params;
foreach ($this->conf->modules as $modname=> $mod)
if (($i++ == $params) || ($modname == $params))
$msg.= "Filename: modules/". str_replace("IcqBot_Module_","",$modname). ".module.php\r\n";
$msg.= "Commands: ". $mod['Commands']. "\r\nAliases: ". $mod['Aliases'];
$msg = 'Module "'. $params. '" not found';
$msg = 'Please, specify module\'s name of number from !mod list';
$params= 'IcqBot_Module_'. $params;
foreach ($this->conf->modules as $modname=> $mod)
if (($i++ == $params) || ($modname == $params))
$msg = 'Module "'. $params. '" not found';
foreach($this->conf->commands as $cmdname=> $command)
$msg = 'Commands of module "'. $modname. '":'. "\r\n";
foreach ($cmds as $cmdname)
if (isset ($aliases[$cmdname]))
sort($aliases[$cmdname],SORT_STRING);
$msg.= ' (aliases: '. implode(', ',$aliases[$cmdname]). ')';
unset ($aliases[$cmdname]);
* @todo Parenless aliases in !mod cmslist
$modulesList = glob('./modules/*.module.php');
foreach ($included_files as $n=> $f)
if (($params == '') || ($params == 'list'))
foreach ($modulesList as $moduleName)
if (!preg_match('/([a-z0-9_]+)\.module\.php$/i',$moduleName,$m))
$msg .= $mod_name. "\r\n";
$msg = 'There are no available modules to load. All of them are already loaded.';
$msg = 'Modules available for loading:'. "\r\n" . $msg;
elseif ($params == 'all')
foreach ($modulesList as $moduleName)
$result = $this->icqbot->loadModule($moduleName, $included_files);
$msg .= $moduleName. " loaded\r\n";
elseif ($result === false)
$msg .= "Wrong filename: $moduleName\r\n";
$msg .= $moduleName. ' - '. $result. "\r\n";
$msg .= 'Modules loaded: '. $cnt;
$msg = 'There are no available modules to load. All of them are already loaded.';
if (strpos($params, '.php')> 0)
elseif (preg_match("/^IcqBot_Module_([A-Za-z0-9_]+)$/", $params, $m))
$result = $this->icqbot->loadModule($moduleName,$included_files);
$msg = $moduleName. " loaded\r\n";
elseif ($result === false)
$msg = "Wrong filename: $moduleName\r\n";
$msg = $moduleName. ' - '. $result. "\r\n";
if (($params == '') || ($params == 'list'))
foreach ($this->conf->modules as $mod_name=> $mod)
$msg .= $mod_name. "\r\n";
$msg = 'Available modules to unload: '. "\r\n". $msg;
$msg = 'There are no available modules to unload.';
elseif ($params == 'all')
foreach ($keys as $mod_name)
if ($cmd != 'unloadforce')
$msg.= $mod_name. ": cannot be unloaded. Use \"unloadforce\" instead.\r\n";
$this->logs->write('Unloading '. $mod_name);
$this->conf->modules[$mod_name]['iface']->deinit();
$this->commands->removeAll($this->conf->modules[$mod_name]['iface']);
unset ($this->conf->modules[$mod_name]['iface']);
unset ($this->conf->modules[$mod_name]);
$msg .= $mod_name. ": unloaded\r\n";
$msg = 'There are no available modules to unload.';
$msg = 'Unloaded modules:'. "\r\n" . $msg;
if (preg_match('/([a-z0-9_]+)\.module\.php$/i',$params,$m))
elseif (preg_match("/^IcqBot_Module_([A-Za-z0-9_]+)$/", $params, $m))
$msg = "Module $mod_name doesn't exists.";
$msg = "Module $mod_name isn't loaded.";
if ($cmd != 'unloadforce')
$msg = $mod_name. ": cannot be unloaded. Use \"unloadforce\" instead.\r\n";
$this->logs->write('Unloading '. $mod_name);
$this->conf->modules[$mod_name]['iface']->deinit();
$this->commands->removeAll($this->conf->modules[$mod_name]['iface']);
unset ($this->conf->modules[$mod_name]['iface']);
unset ($this->conf->modules[$mod_name]);
$msg = $mod_name. ": unloaded\r\n";
foreach ($this->conf->modules as $modname=> $mod)
$msg.= ($i++ ). '. '. str_replace('IcqBot_Module_','',$modname). "\r\n";
* Command, which rules users ACL.
* - !roles list <icqnumber>
* - !roles add <icqnumber> <role1> [role2 [role3 ... ] ]
* - !roles remove <icqnumber> <role1> [role2 [role3 ... ] ]
* @todo Roles and ACL system should be more powerfull
/** @var $user IcqBot_Users **/
return $this->commands->sendMsg($uin, 'Please, specify params. See help for more info.');
list ($cmd, $params) = explode(' ', $params, 2);
$msg = 'Not an icq number given';
$msg = 'Roles for '. $params. ':'. "\r\n". implode("\n",$roles);
/** @var $user IcqBot_Users **/
$user->addRoles($params);
/** @var $user IcqBot_Users **/
$user->removeRoles($params);
return $this->commands->sendMsg($uin, $msg);
* @deprecated will be deprecated
return "Returns modules list.";
elseif ($params == 'info')
return "Returns information about module <module_name>. Also you can specify module's number from '". CMD_PREF. "mod list' command\r\nFor example:\r\n". CMD_PREF. "mod info main\r\n". CMD_PREF. "mod info 1";
elseif ($params == 'cmdlist')
return "Returns all command of module <module_name>. Also you can specify module's number from '". CMD_PREF. "mod list' command\r\nFor example:\r\n". CMD_PREF. "mod cmdlist main\r\n". CMD_PREF. "mod cmdlist 1";
$hlp = "Modules controlling command. Syntax:\r\n";
$hlp.= CMD_PREF. "mod [list]\r\n". CMD_PREF. "mod <info|cmdlist> <module_name|module_num>\r\n";
$hlp.= "For additional info, use ". CMD_PREF. "help mod <command>";
|