From 1f47f997ba65500bc32ef23d1668881728c50316 Mon Sep 17 00:00:00 2001 From: dennydai Date: Thu, 16 Jun 2016 17:20:20 +0800 Subject: [PATCH] add Usage support & add no argu func support --- QUERY_BOT.php | 49 +++++++++++++++++++++++++----------------------- VAR_BOT.php | 49 +++++++++++++++++++++++++----------------------- plugins/help.php | 24 +++++++++--------------- 3 files changed, 61 insertions(+), 61 deletions(-) diff --git a/QUERY_BOT.php b/QUERY_BOT.php index 9bcee2c..48d5cec 100644 --- a/QUERY_BOT.php +++ b/QUERY_BOT.php @@ -2,40 +2,43 @@ //init $Pre_Type = $_SERVER['QUERY_STRING']; require_once('config.php'); -$plugins = array(); require(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'Base.php'); require_once(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'init.php'); //load plugins $load_plugins = glob(PATH.'plugins'.DIRECTORY_SEPARATOR.'*.php'); -foreach ($load_plugins as $key => $value) { - if ($value == PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php') { - unset($load_plugins[$key]); + +foreach ($TAGs as $TAG) { + foreach ($load_plugins as $value) { + $plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4); + eval(file($value)[1]); + $plugin_sendto = $from; + if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) { + $plugin_text = $matches[2]; + require_once $value; + break; + }elseif (($TAG.$plugin_name == $text or $TAG.$plugin_name.'@'.BOT_NAME == $text) and ($plugins[$plugin_name]["needArgu"] == false)) { + require_once $value; + break; + }elseif ($TAG.$plugin_name == $text or $TAG.$plugin_name.'@'.BOT_NAME == $text) { + if ($plugins[$plugin_name]["usage"]!=null) { + $BOT->msg($plugin_sendto, "Usage:\n".$plugins[$plugin_name]["usage"]); + }else{ + $BOT->msg($plugin_sendto, "Missing argument(s)"); + } + break; + } } } -if (in_array(substr($text, 0, 1),$TAGs)) { - $TAG = substr($text, 0, 1); -} -foreach ($load_plugins as $value) { - $plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4); - if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) { - $plugin_text = $matches[2]; - $plugin_sendto = $from; - require_once $value; - break; - }elseif ($TAG.$plugin_name == $text or $TAG.$plugin_name.'@'.BOT_NAME == $text) { - $plugin_sendto = $from; - $BOT->msg($plugin_sendto, "Missing argument(s)"); - break; - } -} -require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php'; //function -function PluginSet($desc){ +function PluginSet($desc,$usage=null,$needArgu=True,$visible=True){ global $plugins,$plugin_name,$TAG; - $plugins[] .= $TAG.$plugin_name." ".$desc; + $plugins[$plugin_name]["desc"] = '/'.$plugin_name." ".$desc; + $plugins[$plugin_name]["usage"] = $usage; + $plugins[$plugin_name]["needArgu"] = $needArgu; + $plugins[$plugin_name]["visible"] = $visible; } ?> \ No newline at end of file diff --git a/VAR_BOT.php b/VAR_BOT.php index 03ed90c..425bbd3 100644 --- a/VAR_BOT.php +++ b/VAR_BOT.php @@ -2,40 +2,43 @@ //init $Pre_Type = substr(substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/')+1), 0, -4); require_once('config.php'); -$plugins = array(); require(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'Base.php'); require_once(PATH.'classes'.DIRECTORY_SEPARATOR.TYPE.DIRECTORY_SEPARATOR.'init.php'); //load plugins $load_plugins = glob(PATH.'plugins'.DIRECTORY_SEPARATOR.'*.php'); -foreach ($load_plugins as $key => $value) { - if ($value == PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php') { - unset($load_plugins[$key]); + +foreach ($TAGs as $TAG) { + foreach ($load_plugins as $value) { + $plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4); + eval(file($value)[1]); + $plugin_sendto = $from; + if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) { + $plugin_text = $matches[2]; + require_once $value; + break; + }elseif (($TAG.$plugin_name == $text or $TAG.$plugin_name.'@'.BOT_NAME == $text) and ($plugins[$plugin_name]["needArgu"] == false)) { + require_once $value; + break; + }elseif ($TAG.$plugin_name == $text or $TAG.$plugin_name.'@'.BOT_NAME == $text) { + if ($plugins[$plugin_name]["usage"]!=null) { + $BOT->msg($plugin_sendto, "Usage:\n".$plugins[$plugin_name]["usage"]); + }else{ + $BOT->msg($plugin_sendto, "Missing argument(s)"); + } + break; + } } } -if (in_array(substr($text, 0, 1),$TAGs)) { - $TAG = substr($text, 0, 1); -} -foreach ($load_plugins as $value) { - $plugin_name = substr($value, strlen(PATH.'plugins'.DIRECTORY_SEPARATOR), -4); - if (preg_match("/^(".preg_quote($TAG, '/').$plugin_name."|".preg_quote($TAG, '/').$plugin_name.preg_quote('@').BOT_NAME.") (.*)$/", $text, $matches)) { - $plugin_text = $matches[2]; - $plugin_sendto = $from; - require_once $value; - break; - }elseif ($TAG.$plugin_name == $text or $TAG.$plugin_name.'@'.BOT_NAME == $text) { - $plugin_sendto = $from; - $BOT->msg($plugin_sendto, "Missing argument(s)"); - break; - } -} -require_once PATH.'plugins'.DIRECTORY_SEPARATOR.'help.php'; //function -function PluginSet($desc){ +function PluginSet($desc,$usage=null,$needArgu=True,$visible=True){ global $plugins,$plugin_name,$TAG; - $plugins[] .= $TAG.$plugin_name." ".$desc; + $plugins[$plugin_name]["desc"] = '/'.$plugin_name." ".$desc; + $plugins[$plugin_name]["usage"] = $usage; + $plugins[$plugin_name]["needArgu"] = $needArgu; + $plugins[$plugin_name]["visible"] = $visible; } ?> \ No newline at end of file diff --git a/plugins/help.php b/plugins/help.php index 11a9d01..3f6b79b 100644 --- a/plugins/help.php +++ b/plugins/help.php @@ -1,16 +1,10 @@ msg($from, $plugin_list); - } -} \ No newline at end of file +PluginSet("Show help",null,false); +$plugin_list = HELP_BEGIN."\n"; +foreach ($plugins as $value) { + if ($value['visible'] == True) { + $plugin_list .= "\n".$value['desc']; + } +} +$plugin_list .= "\n\n".HELP_END; +$BOT->msg($from, $plugin_list); \ No newline at end of file