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

Source for file calc.module.php

Documentation is available at calc.module.php

  1. <?php
  2. /**
  3.  * phpIcqBot Calc Module
  4.  * 
  5.  * Module is used for calculating simple math expressions.
  6.  * Examples:
  7.  * - !calc 2+2
  8.  * - !calc abs(sqrt(4*25)/10-20)
  9.  *
  10.  * @author Jector <no.one.on@gmail.com>
  11.  * @version 0.2
  12.  * @package phpIcqBot
  13.  * @todo add more functions
  14.  */
  15.  
  16.  
  17. {
  18.     /**
  19.      * Contains available functions for calculating (sqrt, abs, etc) ...
  20.      *
  21.      * @var string 
  22.      */
  23.     private $funcs;
  24.     
  25.     public function init()
  26.     {
  27.         $this->commands->addCommand($this'calc'array('calculate'));
  28.         $this->funcs implode('|',array('abs','sqrt','pow','round','ceil','floor','rand','sin','cos','tan','asin','acos','atan','rad2deg','pi','log10','log','log2','exp','decoct','dechex','decbin','bindec','octdec'));
  29.     }
  30.     
  31.     public function deinit()
  32.     {
  33.         
  34.     }
  35.     
  36.     /**
  37.      * Calculating function
  38.      *
  39.      * @param integer $uin 
  40.      * @param string $params calculatin string
  41.      */
  42.     public function Command_Calc($uin$params)
  43.     {
  44.         $params trim($params);
  45.         if (preg_match("/^([0-9\s\-\+\(\)\*\/%\.,]+|{$this->funcs})+$/i",$params))
  46.         {
  47.             $err=@eval('$ret = '.$params.';');
  48.             if ($err === FALSE)
  49.                 $ret = 'Calculating error. Check your expression.';
  50.         }
  51.         else
  52.             $ret = 'Invalid chars in input calc string. Check your expression';
  53.         $this->commands->sendMsg($uinstrtr($params"\r\n","  ").' = '.$ret);
  54.     }

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