From d675c970b13c2434d781ab0f108910debdec5015 Mon Sep 17 00:00:00 2001 From: xrogaan Date: Sat, 28 Jun 2008 07:59:06 +0200 Subject: [PATCH] renaming plugins --- plugins/fortunes-plugin.inc.php | 84 ------------------ plugins/jet-plugin.inc.php | 187 ---------------------------------------- plugins/quizz-plugin.inc.php | 24 ------ plugins/sample-plugin.inc.php | 101 ---------------------- plugins/sample.php | 7 +- sources/Plugins.php | 30 +++++-- sources/Plugins/Abstract.php | 16 +++- 7 files changed, 37 insertions(+), 412 deletions(-) delete mode 100644 plugins/fortunes-plugin.inc.php delete mode 100644 plugins/jet-plugin.inc.php delete mode 100644 plugins/quizz-plugin.inc.php delete mode 100644 plugins/sample-plugin.inc.php diff --git a/plugins/fortunes-plugin.inc.php b/plugins/fortunes-plugin.inc.php deleted file mode 100644 index 7c756ed..0000000 --- a/plugins/fortunes-plugin.inc.php +++ /dev/null @@ -1,84 +0,0 @@ -. - */ - -/* -CREATE TABLE IF NOT EXISTS `fortunes` ( - `id` int(11) NOT NULL auto_increment, - `pseudo` varchar(25) NOT NULL, - `ip` varchar(15) default NULL, - `email` varchar(25) NOT NULL, - `site` varchar(70) NOT NULL, - `fortunes` text NOT NULL, - `date` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -*/ - -class fortune { - private $IRCConn,$formater; - private $message; - private $commands; - - public function __construct() { - $this->IRCConn = bot::GetInstance(); - $this->formater = text_format::GetInstance(); - $this->commands = array( - 'random' => array( - 'accepted_args' => 0, - 'requier_args' => 0, - 'help' => 'Print out one random fortune', - 'type' => 'mixed', - ), - 'last' => array( - 'accepted_args' => 1, - 'requier_args' => 0, - 'help' => 'Print out the last fortune added. If an argument is passed, print the \'n\' last fortune added (max 10).', - 'type' => 'mixed', - ), - 'number' => array( - 'accepted_args' => 1, - 'requier_args' => 1, - 'help' => 'Print out the \'n\' fortune, where \'n\' is the id.', - 'type' => 'mixed', - ) - ); - } - - public function commands_list() { - return $this->commands; - } - - public function current_message ($message) { - /* gived by irc::parse_get - $message = array ( - 'type' => PRIVMSG|NOTICE, - 'from' => Nick (reply to), - 'to' => BotName / ChannelName, - 'message' => The message - ); - */ - $this->message = $message; - } - - public function random() {} - public function last($n=1) {} - public function number($n) {} -} - -?> \ No newline at end of file diff --git a/plugins/jet-plugin.inc.php b/plugins/jet-plugin.inc.php deleted file mode 100644 index 41f68f9..0000000 --- a/plugins/jet-plugin.inc.php +++ /dev/null @@ -1,187 +0,0 @@ -. - */ - - -class jet implements plugin { - private $IRCConn,$formater; - private $message; - private $commands; - - public function __construct($main) { - $this->IRCConn = bot::GetInstance(); - $this->formater = text_format::GetInstance(); - $this->commands = array( - 'string2dice' => array( // !jet string2dice - 'accepted_args' => 1, - 'requier_args' => 1, - 'help' => 'some help for this method1', - 'type' => 'private', - ), - 'caract' => array ( - 'accepted_args' => 3, - 'requier_args' => 1, - 'help' => "Jet basé sur une caractéristique.\n". - "Argument premier : Valeur de la caractéristique\n". - "Argument second : Base du jet, par défaut une base 20 (peut être mis a 100 pour calculer le poid transportable par exemple)\n". - "Argument troisième : ".$this->formater->bold('[1|0]')." Spécifie si le jet doit retourner quelque chose d'aléatoire, sinon", - 'type' => 'private' - ) - ); - } - - public function commands_list() { - return $this->commands; - } - - public function current_message ($message) { - /* gived by irc::parse_get - $message = array ( - 'type' => PRIVMSG|NOTICE, - 'from' => Nick (reply to), - 'to' => BotName / ChannelName, - 'message' => The message - ); - */ - $this->message = $message; - } - - public function string2dice ($str) { - $str = strtolower($str); - - $numbers = array(0,1,2,3,4,5,6,7,8,9); - $modifiers = array('+','-','*','/'); - - if ($str == '1d1') - return 1; - - $copy = $str; - $i = 0; - $len_copy = strlen($copy); - - $number_of_dice = ''; - $value_of_dice = ''; - $modifier = ''; - $modifier_nature = ''; - $step = 'first'; - while ($len_copy > $i) { - /** - * Si le caractère courant n'est pas un nombre, alors quelques vérifications. - * Nous vérifions la partie du dé que nous créons : première (avant le 'd'), deuxième (après le 'd') - * et si un modifieur existe ('+','-','*','/'). - */ - if ($copy[$i] == 'd' || in_array($copy[$i],$modifiers)) { - // Nombre de dés a lancer manquant - if ($i == 0) { - trigger_error('Wrong dice format : "'.$copy.'". Must be [Number]d[Value][Modifier][Number]',E_USER_WARNING); - return false; - } - - if ($copy[$i] == 'd') { - $step = 'second'; - } elseif (in_array($copy[$i],$modifiers)) { - // Valeur du dé manquant - if (empty($value_of_dice)) { - trigger_error('Wrong dice format : "'.$copy.'". Must be [Number]d[Value][Modifier][Number]',E_USER_WARNING); - return false; - } - $step = 'modifier'; - $modifier_nature = $copy[$i]; - } else { - trigger_error('Unknown caracter \'' . $copy[$i] . '\'.',E_USER_WARNING); - } - } else { - if ($step == 'first') { - $number_of_dice.= $copy[$i]; - } - - if ($step == 'second') { - $value_of_dice.= $copy[$i]; - } - - if ($step == 'modifier') { - $modifier.= $copy[$i]; - } - } - - $i++; - } - - $de = self::dice($number_of_dice,$value_of_dice); - if ($modifier_nature == '') { - $r = $de; - } else { - $r = eval('return abs(ceil($de'.$modifier_nature.'$modifier));'); - } - - if (bot::$myBotName == $this->message['to']) { - $replyto = $this->message['from']; - } else { - $replyto = $this->message['to']; - } - - $this->IRCConn->privmsg($replyto,$r); - } - - /** - * Jet basé sur une caractéristique. - * - * @param int Valeur de la caractéristique - * @param int Base du jet, par défaut une base 20 (peut être mis a 100 pour calculer le poid transportable par exemple) - * @param boolean Spécifie si le jet doit retourner quelque chose d'aléatoire, sinon - */ - public function caract($caract,$base=20,$rand=true) { - $caract = intval($caract); - $base = intval($base); - - $de = ($rand) ? self::dice(1,20) : 0 ; - $result = floor(($de+$caract) * $base / 20); - // (n / 20) * base => la base par défaut est 20 - - - if ($rand) - $result = $result/2; - - $this->IRCConn->privmsg($this->message['from'],$result); - return $result; - } - - /** - * Lance un dé - * @param int $number nombre de dé lancé. - * @param int $value valeur maximale du dé. - */ - private function dice($number,$value) { - $number = intval($number); - $value = intval($value); - - // Si la valeur du dé est a 0, on retourne tout de suite 0. - if ($value === 0) - return 0; - - $toreturn=0; - while ($number>0) { - $toreturn+= rand(1,$value); - $number-=1; - } - return $toreturn; - } - -} - -?> \ No newline at end of file diff --git a/plugins/quizz-plugin.inc.php b/plugins/quizz-plugin.inc.php deleted file mode 100644 index 95bdcd9..0000000 --- a/plugins/quizz-plugin.inc.php +++ /dev/null @@ -1,24 +0,0 @@ -. - * - * $Id$ - */ - -class quizz extends Plugins_Abstract { - -} diff --git a/plugins/sample-plugin.inc.php b/plugins/sample-plugin.inc.php deleted file mode 100644 index 4d30305..0000000 --- a/plugins/sample-plugin.inc.php +++ /dev/null @@ -1,101 +0,0 @@ -. - */ - -/** - * @see Plugins_Abstract - */ -require_once(BASE_DIR.'Plugins/Abstract.php'); - -class sample extends Plugins_Abstract { - protected $_ircmain; - - public function __construct($main) { - $this->_ircmain = bot::GetInstance(); - } - - public function commands_list() { - $commands = array( - 'method1' => array( // !sample method1 - 'requier_args' => 0, - 'accepted_args' => 0, - 'help' => 'some help for this method1', - 'type' => 'public', - ), - 'method2' => array( // !sample method2 arg - 'requier_args' => 1, - 'accepted_args' => 1, - // the \n chr in a double quote string create a new line (2 PRIVMSG) - 'help' => "some help for this method2\n".$this->formater->bold('one arg').' requier', - 'type' => 'public', - ), - 'method3' => array( // /msg BotName sample method3 arg - 'requier_args' => 0, - 'accepted_args' => 1, - 'help' => 'some help for this method3', - 'type' => 'mixed', - ), - ); - return $commands; - } - - public function current_message ($message) { - /* gived by irc::parse_get - $message = array ( - 'type' => PRIVMSG|NOTICE, - 'from' => Nick (reply to), - 'to' => BotName / ChannelName, - 'message' => The message - ); - */ - $this->message = $message; - } - - function method1 ($config = false) { - $this->IRCConn->privmsg(bot::$channel,'This is the method1'); - } - - function method2 ($query) { - $this->IRCConn->privmsg(bot::$channel,'This is the method2 : '.$query); - } - - function method3 ($query='') { - - if ($query=='') { - $query = 'no args given. All works !'; - } - - if (bot::$myBotName == $this->message['to']) { - $replyto = $this->message['from']; - } else { - $replyto = $this->message['to']; - } - - $this->IRCConn->privmsg($replyto,'This is the method3 : '.$query); - } - - /** - * Return plugin name - * - * @return string - */ - public function toString() { - return 'sample'; - } -} -?> \ No newline at end of file diff --git a/plugins/sample.php b/plugins/sample.php index ed41b98..4d30305 100644 --- a/plugins/sample.php +++ b/plugins/sample.php @@ -15,11 +15,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * - * @category IrBot - * @package IrBot_Plugins - * @copyright Copyright (c) 2008 Bellière Ludovic - * @license http://www.gnu.org/licenses/gpl-3.0.html */ /** @@ -30,7 +25,7 @@ require_once(BASE_DIR.'Plugins/Abstract.php'); class sample extends Plugins_Abstract { protected $_ircmain; - public function init() { + public function __construct($main) { $this->_ircmain = bot::GetInstance(); } diff --git a/sources/Plugins.php b/sources/Plugins.php index 7baae33..7ce1b67 100644 --- a/sources/Plugins.php +++ b/sources/Plugins.php @@ -25,7 +25,7 @@ interface plugin { public function current_message($message); } -class plugins { +class plugins extends RecursiveDirectoryIterator { const EVENT_PRIVMSG = "privmsg"; const EVENT_NOTICE = "notice"; @@ -37,19 +37,37 @@ class plugins { self::EVENT_PRIVMSG => true ); + protected $commands = array(); + public function __construct(IRCMain $ircmain) { $this->ircmain = $ircmain; - $this->text_format = $this->ircmain->formater; + parent::__construct(BASE_DIR.'plugins/'); + + while(self::valid()) { + if (self::isDot()) { + self::next(); + } + if (self::isFile()) { + if (self::isReadable()) { + $pluginFileName = self::getFilename(); + } + } + self::next(); + } + } - public function add_command(Plugins_Abstract $plugin,Plugins_Command_Abstract $method_to_add,$do_on) { + public function addPlugin(Plugins_Abstract $plugin) { + } + + public function add_command($plugin_name,Plugins_Command_Abstract $method_to_add,$do_on) { if (isset($this->commands[$plugin][$method_to_add])) { - echo debug() ? 'plugins_controller::add_command() -> ' . "$plugin -> $method_to_add\t\t\ALREADY LOADED\n" : ''; + echo debug() ? 'plugins::add_command() -> ' . "$plugin -> $method_to_add\t\t\ALREADY LOADED\n" : ''; return true; } if (!in_array($do_on,$this->accepted_event)) { - echo debug() ? 'plugins_controller::add_command() -> ' . "$plugin -> $method_to_add\t\t\tFAILED\n" : ''; + echo debug() ? 'plugins::add_command() -> ' . "$plugin -> $method_to_add\t\t\tFAILED\n" : ''; return false; } @@ -61,7 +79,7 @@ class plugins { 'do_on' => $do_on, ); - echo debug() ? 'plugins_controller::add_command() -> ' . "$plugin -> $method_to_add\t\t\LOADED\n" : ''; + echo debug() ? 'plugins::add_command() -> ' . "$plugin -> $method_to_add\t\t\LOADED\n" : ''; return true; } } diff --git a/sources/Plugins/Abstract.php b/sources/Plugins/Abstract.php index 74c64c7..43a3fa0 100644 --- a/sources/Plugins/Abstract.php +++ b/sources/Plugins/Abstract.php @@ -18,18 +18,26 @@ * */ -abstract class Plugins_Abstract { +abstract class Plugins_Abstract extends RecursiveDirectoryIterator { protected $ircmain, $textformat; private $message, $commands; + + protected $_commandsPath = 'plugins/%pluginName%/'; - public function __construct() { - $this->ircmain = bot::GetInstance(); - $this->textformat = text_format::GetInstance(); + public function __construct($path) { + parent::_construct(); } public function commands_list(){} public function set_cmessage($message){ $this->message = $message; } + + protected function setCommands($path = '') { + if (!empty($path)) { + $this->_commandsPath = $path; + } + + } } -- 2.11.4.GIT