From eb062d5412206abf2ac92cfbca1096d85f2234cb Mon Sep 17 00:00:00 2001 From: dennydai Date: Wed, 9 Mar 2016 16:54:41 +0800 Subject: [PATCH] performance improved --- QUERY_BOT.php | 27 ++++++++++++++------------- VAR_BOT.php | 27 ++++++++++++++------------- index.php | 27 ++++++++++++++------------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/QUERY_BOT.php b/QUERY_BOT.php index 4e095ec..9bcee2c 100644 --- a/QUERY_BOT.php +++ b/QUERY_BOT.php @@ -14,19 +14,20 @@ foreach ($load_plugins as $key => $value) { unset($load_plugins[$key]); } } -foreach ($TAGs as $TAG) { - 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; - } +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'; diff --git a/VAR_BOT.php b/VAR_BOT.php index c5598ca..03ed90c 100644 --- a/VAR_BOT.php +++ b/VAR_BOT.php @@ -14,19 +14,20 @@ foreach ($load_plugins as $key => $value) { unset($load_plugins[$key]); } } -foreach ($TAGs as $TAG) { - 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; - } +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'; diff --git a/index.php b/index.php index 7879976..4345ffa 100644 --- a/index.php +++ b/index.php @@ -14,19 +14,20 @@ foreach ($load_plugins as $key => $value) { unset($load_plugins[$key]); } } -foreach ($TAGs as $TAG) { - 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; - } +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';