From 3c91dbc5da7e3f961babbd2766ea9405fd57ce19 Mon Sep 17 00:00:00 2001 From: xrogaan Date: Sat, 22 Dec 2007 03:18:22 +0000 Subject: [PATCH] 14 "nothing, realy. Need some time to improve the plugin system." --- main.php | 3 ++- plugins/jet-plugin.inc.php | 24 ++++++++++++++++++------ plugins/sample-plugin.inc.php | 1 + sources/IRCMain-class.inc.php | 1 + sources/functions.inc.php | 5 +++-- sources/irc-class.inc.php | 9 ++++++--- sources/main-class.inc.php | 19 +++++++++++-------- sources/plugin-class.inc.php | 12 +++++++++++- 8 files changed, 53 insertions(+), 21 deletions(-) diff --git a/main.php b/main.php index 170b5a3..3dfa26d 100755 --- a/main.php +++ b/main.php @@ -1,8 +1,9 @@ +#!/usr/bin/php IRCConn = bot::GetInstance(); $this->formater = text_format::GetInstance(); - } - - public function commands_list() { - $commands = array( + $this->commands = array( 'string2dice' => array( // !sample method1 'accepted_args' => 1, 'help' => 'some help for this method1', @@ -25,7 +23,21 @@ class jet implements plugin { 'type' => 'private' ) ); - return $commands; + } + + public function commands_list() { + return $this->commands; + } + + public function error($msg,$command) { + switch ($this->commands[$command]) { + case 'private': + $this->IRCConn->privmsg($this->message['from'],$msg); + break; + + default: + break; + } } public function current_message ($message) { @@ -136,7 +148,7 @@ class jet implements plugin { if ($rand) $result = $result/2; - $this->IRCConn->privmsg($this->message['to'],$result); + $this->IRCConn->privmsg($this->message['from'],$result); return $result; } diff --git a/plugins/sample-plugin.inc.php b/plugins/sample-plugin.inc.php index 6e577a0..61b70bf 100644 --- a/plugins/sample-plugin.inc.php +++ b/plugins/sample-plugin.inc.php @@ -41,6 +41,7 @@ class sample implements plugin { */ $this->message = $message; } + public function error($msg,$command) {} function method1 () { $this->IRCConn->privmsg(bot::$channel,'This is the method1'); diff --git a/sources/IRCMain-class.inc.php b/sources/IRCMain-class.inc.php index 84dfa70..8e71076 100644 --- a/sources/IRCMain-class.inc.php +++ b/sources/IRCMain-class.inc.php @@ -325,6 +325,7 @@ interface plugin { public function __construct($main); public function commands_list(); public function current_message($message); + } ?> \ No newline at end of file diff --git a/sources/functions.inc.php b/sources/functions.inc.php index c9b804f..c0377b0 100644 --- a/sources/functions.inc.php +++ b/sources/functions.inc.php @@ -39,13 +39,13 @@ function backtrace($backtrace) { if (isset($t['type'])) { $err_backtrace.= 'Type : '.$t['type']."\n"; } - if (isset($t['args']) && !empty($t['args']) && $t['function'] != 'myErrorHandler') { + /*if (isset($t['args']) && !empty($t['args']) && $t['function'] != 'myErrorHandler') { $err_backtrace.= '--== Args ==--'."\n"; ob_start(); var_dump($t['args']); $err_backtrace.= "\t".str_replace("\n","\n\t",ob_get_contents()); ob_end_clean(); - } + }*/ $err_backtrace.= "\n\n- - - - - - - - - - - - -\n\r"; } return $err_backtrace; @@ -62,6 +62,7 @@ class myRuntimeException extends Exception { * @access protected */ protected $_context = array(); + public $_level; /** * Construit un objet RuntimeException diff --git a/sources/irc-class.inc.php b/sources/irc-class.inc.php index ca0155f..11ad51b 100644 --- a/sources/irc-class.inc.php +++ b/sources/irc-class.inc.php @@ -55,11 +55,12 @@ class irc { } } + // : PRIVMSG : if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.bot::$myBotName.'|'.bot::$channel.") :(.*)\r`",$this->msg,$T)) { $this->msg_info = array ( 'type' => 'PRIVMSG', - 'from' => $T[1], - 'to' => $T[2], + 'from' => $T[1], // owner + 'to' => $T[2], // message for bot or channel 'message' => $T[3] ); } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.bot::$myBotName." :(.*)\r`",$this->msg,$T)) { @@ -78,7 +79,9 @@ class irc { * @return array */ public function get_msg_info() { - return $this->msg_info; + $temp = $this->msg_info; + $this->msg_info = array('type'=>false); + return $temp; } } diff --git a/sources/main-class.inc.php b/sources/main-class.inc.php index 855dbd0..afb2fdd 100644 --- a/sources/main-class.inc.php +++ b/sources/main-class.inc.php @@ -175,18 +175,21 @@ final class bot { break; case 'NOTICE': break; - default: - echo "Gee... I don't know what {$msg_info['type']} means..."; - var_dump($msg_info); - break; } } } catch (myRuntimeException $e) { - /*echo $e;*///* - echo $e->getMessage(); - echo backtrace($e->getTrace()); // */ - throw new Exception('Error occured',0); + $x = $e->getMessage(); + echo $x; + $x.= backtrace($e->getTrace()); + file_put_contents('errorlog',$x); + //if ($e->_level < 2 || ($e->_level >= 256 && $e->_level < 1024)) { + echo 'Error level : '.$e->_level."\n\n"; + throw new Exception('Error occured',0); + /*} else { + echo 'Error level : '.$e->_level."\n\n\n\n"; + throw new Exception("Error occured. Please see errorlog for details.",1); + }*/ } catch (Exception $e) { throw $e; } diff --git a/sources/plugin-class.inc.php b/sources/plugin-class.inc.php index 5d6045a..efa6040 100644 --- a/sources/plugin-class.inc.php +++ b/sources/plugin-class.inc.php @@ -6,6 +6,7 @@ interface plugin { public function __construct($main); public function commands_list(); public function current_message($message); + public function error($msg,$command); } class plugins { @@ -62,12 +63,21 @@ class plugins { else $the_args = $all_args; + echo "accepted_args : $accepted_args, args : ".count($all_args)."\n\n\n"; + + if (count($all_args)<$accepted_args) { + print_r($msg_info); + return; + $this->ircmain->privmsg(); + } + // echo "Args :\n"; // print_r($the_args); // echo "\n"; if ($plugin == 'core') { - call_user_func_array(array($this->ircmain,$method_name),$the_args); + print_r($method_name); + call_user_func_array(array(self::ircmain,$method_name),$the_args); } else { $this->plugin_list[$plugin]->current_message($msg_info); call_user_func_array(array($this->plugin_list[$plugin],$method_name),$the_args); -- 2.11.4.GIT