phpDocumentor phpIcqBot
[ class tree: phpIcqBot ] [ index: phpIcqBot ] [ all elements ]

Source for file commands.class.php

Documentation is available at commands.class.php

  1. <?php
  2.  
  3. {
  4.  
  5.     /**
  6.      * IcqBot class
  7.      *
  8.      * @var IcqBot 
  9.      */
  10.     private $icqbot;
  11.  
  12.     /**
  13.      * IcqBot_Conf
  14.      *
  15.      * @var IcqBot_Conf 
  16.      */
  17.     private $conf;
  18.     
  19.     /**
  20.      * WebIcqPro class
  21.      *
  22.      * @var WebIcqPro 
  23.      */
  24.     private $proto;
  25.     
  26.     /**
  27.      * IcqBot_Logs class
  28.      *
  29.      * @var IcqBot_Logs 
  30.      */
  31.     private $logs;
  32.  
  33.     /**
  34.      * Storing class
  35.      *
  36.      * @var IcqBot_Store 
  37.      */
  38.     public $store;
  39.     
  40.     public function __construct(IcqBot &$icqbotIcqBot_Conf &$confWebIcqPro &$protoIcqBot_Logs &$logs)
  41.     {
  42.         $this->icqbot   &$icqbot;
  43.         $this->conf     &$conf;
  44.         $this->proto    &$proto;
  45.         $this->logs     &$logs;
  46.         $this->store    = $conf->store;
  47.     }
  48.     
  49.     /**
  50.      * Add command handler to module
  51.      *
  52.      * @param IcqBot_Module $module 
  53.      * @param string $command Command to handle
  54.      * @param array $aliases Aliases for this command
  55.      * @return array Commands and Aliases, whick handled
  56.      */
  57.     public function addCommand(IcqBot_Module &$module$command$aliases array())
  58.     {
  59.         $retcmds array();
  60.         $command ucfirst(strtolower($command));
  61.         
  62.         if (!is_callable(array($module,'Command_'.$command)))
  63.             return array();
  64.             
  65.         if (!isset($this->conf->commands[$command]))
  66.         {
  67.             $this->conf->commands[strtolower($command)array($module'Command_'.$command);
  68.             $retcmds[$command;
  69.             $this->conf->modules[get_class($module)]['Commands']++;
  70.         }
  71.  
  72.         if (!is_array($aliases))
  73.             $aliases array($aliases);
  74.             
  75.         foreach($aliases as $alias)
  76.         {
  77.             $alias ucfirst(strtolower($alias));
  78.             if (isset($this->conf->commands[$alias]))
  79.                 continue;
  80.             $this->conf->commands[strtolower($alias)array($module'Command_'.$command);
  81.             $this->conf->modules[get_class($module)]['Aliases']++;
  82.             $retcmds[$alias;
  83.         }
  84.         return $retcmds;
  85.     }
  86.  
  87.     public function removeCommand(IcqBot_Module &$module$command)
  88.     {
  89.         $command ucfirst(strtolower($command));
  90.         if (!array_key_exists($command,$this->conf->commands))
  91.             return false;
  92.         if ($this->conf->commands[$command][0!== $module)
  93.             return false;
  94.             
  95.         unset($this->conf->commands[$command]);
  96.         $this->conf->modules[get_class($module)]['Commands']--;
  97.         return true;
  98.     }
  99.  
  100.     public function removeAllCommands(IcqBot_Module &$module)
  101.     {
  102.         $removeCommands array();
  103.         foreach ($this->conf->commands as $k=>$v)
  104.             if ($v[0=== $module)
  105.                 $removeCommands[]=$k;
  106.         foreach ($removeCommands as $v)
  107.             unset($this->conf->commands[$v]);
  108.             
  109.         $this->conf->modules[get_class($module)]['Commands']=0;
  110.     }
  111.     
  112.     public function addEvent(IcqBot_Module $module$event)
  113.     {
  114.         if (!isset($this->conf->events[$event]))
  115.         {
  116.             $this->conf->events[$event]=array();
  117.         }
  118.         
  119.         if (!isset($this->conf->events[$event][get_class($module)]&& is_callable(array(&$module,'Event_'.$event)))
  120.         {
  121.             return ($this->conf->events[$event][get_class($module)$module);
  122.         }
  123.         return false;
  124.     }
  125.     
  126.     public function removeEvent(IcqBot_Module $module$event)
  127.     {
  128.         if (isset($this->conf->events[$event][get_class($module)]))
  129.         {
  130.             unset($this->conf->events[$event][get_class($module)]);
  131.             return true;
  132.         }
  133.         return false;
  134.     }
  135.     
  136.     public function removeAllEvents(IcqBot_Module $module)
  137.     {
  138.         $mod_name get_class($module);
  139.         foreach ($this->conf->events as $event => $mods)
  140.         {
  141.             if (key_exists($mod_name$mods))
  142.             {
  143.                 unset($this->conf->events[$event][$mod_name]);
  144.             }
  145.         }
  146.         return true;
  147.     }
  148.     
  149.     public function addTimer(IcqBot_Module $module$key$interval$callback)
  150.     {
  151.         if ($interval<1)
  152.         {
  153.             return false;
  154.         }
  155.         
  156.         if (!is_callable(array(&$module,"Timer_".$callback)))
  157.         {
  158.             return false;
  159.         }
  160.         
  161.         $this->conf->timer[get_class($module)][$keyarray('interval'=>$interval'callback'=>array(&$module,"Timer_".$callback));
  162.         $this->conf->cron[get_class($module).'@'.$keytime()+$interval;
  163.         return true;
  164.     }
  165.     
  166.     public function removeTimer(IcqBot_Module $module$key)
  167.     {
  168.         if (isset($this->conf->timer[get_class($module)][$key]))
  169.         {
  170.             unset($this->conf->timer[get_class($module)][$key]);
  171.             unset($this->conf->cron[get_class($module).'@'.$key]);
  172.             return true;
  173.         }
  174.         return false;
  175.     }
  176.     
  177.     public function removeAllTimers(IcqBot_Module $module)
  178.     {
  179.         $mod_name get_class($module);
  180.         if (key_exists($mod_name$this->conf->timer))
  181.         {
  182.             foreach ($this->conf->timer[$mod_nameas $key => $value)
  183.             {
  184.                 if (key_exists($mod_name.'@'.$key))
  185.                 {
  186.                     unset($this->conf->cron[$mod_name.'@'.$key]);
  187.                 }
  188.             }
  189.             unset($this->conf->timer[$mod_name]);
  190.         }
  191.         return true;
  192.     }
  193.     
  194.     public function removeAll(IcqBot_Module $module)
  195.     {
  196.         $this->removeAllCommands($module);
  197.         $this->removeAllEvents($module);
  198.         $this->removeAllTimers($module);
  199.         return true;
  200.     }
  201.     
  202.     public function setStatus($status)
  203.     {
  204.         $this->logs->write('Setting status: '.$status,LOGLEVEL_2);
  205.         $this->proto->setStatus($status);
  206.         $this->icqbot->status = $status;
  207.     }
  208.  
  209.     public function sendMsg($uin$msg)
  210.     {
  211.         $this->logs->write("MSG Queue To$uinMsg$msg",LOGLEVEL_3);
  212.         $this->conf->msg_queue[]=array($uin,$msg);
  213.         return true;
  214.     }
  215.  
  216.     public function activateOfflineMessages()
  217.     {
  218.         $this->logs->write('Activating offline messages',LOGLEVEL_2);
  219.         $this->proto->activateOfflineMessages($this->uin);
  220.     }
  221.  
  222. }

Documentation generated on Mon, 24 Dec 2007 09:34:27 +0500 by phpDocumentor 1.4.0