From cebc6fb310abfadd4ac9545b88a43f18d2380e27 Mon Sep 17 00:00:00 2001 From: whale Date: Mon, 15 Jun 2020 19:50:07 +0800 Subject: [PATCH] update to 1.5.6 version add CQCommand filter add ZM_DEFAULT_FETCH_MODE --- composer.json | 2 +- config/global.php | 5 +++-- src/Framework/FrameworkLoader.php | 1 + src/ZM/Annotation/AnnotationParser.php | 3 ++- src/ZM/Annotation/CQ/CQCommand.php | 8 ++++++++ src/ZM/DB/DB.php | 5 +++-- src/ZM/DB/SelectBody.php | 10 ++++++---- src/ZM/Event/CQ/MessageEvent.php | 6 +++++- 8 files changed, 29 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 58d6a7e3..3fd6f450 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "High performance QQ robot and web server development framework", "minimum-stability": "stable", "license": "Apache-2.0", - "version": "1.5.5", + "version": "1.5.6", "authors": [ { "name": "whale", diff --git a/config/global.php b/config/global.php index 01a05507..0635ca42 100644 --- a/config/global.php +++ b/config/global.php @@ -43,11 +43,12 @@ $config['sql_config'] = [ PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false ], - 'sql_no_exception' => false + 'sql_no_exception' => false, + 'sql_default_fetch_mode' => PDO::FETCH_BOTH // added in 1.5.6 ]; /** CQHTTP连接约定的token */ -$config["access_token"] = ""; +$config["access_token"] = "0ACA097E-AA82-4577-8B17-4A8D454D171B"; /** HTTP服务器固定请求头的返回 */ $config['http_header'] = [ diff --git a/src/Framework/FrameworkLoader.php b/src/Framework/FrameworkLoader.php index f62adb41..10ebd4c2 100644 --- a/src/Framework/FrameworkLoader.php +++ b/src/Framework/FrameworkLoader.php @@ -151,6 +151,7 @@ class FrameworkLoader define("ZM_MATCH_NUMBER", 2); define("ZM_MATCH_SECOND", 3); define("ZM_BREAKPOINT", 'if(in_array("--debug-mode", \Framework\FrameworkLoader::$argv)) extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : @get_called_class()));'); + define("ZM_DEFAULT_FETCH_MODE", self::$settings->get("sql_config")["sql_default_fetch_mode"] ?? 4); } private function selfCheck() { diff --git a/src/ZM/Annotation/AnnotationParser.php b/src/ZM/Annotation/AnnotationParser.php index ca951cdd..58f8bc3b 100644 --- a/src/ZM/Annotation/AnnotationParser.php +++ b/src/ZM/Annotation/AnnotationParser.php @@ -110,7 +110,7 @@ class AnnotationParser foreach ($method_annotations as $vss) { if ($vss instanceof Rule) $vss = self::registerRuleEvent($vss, $vs, $reflection_class); else $vss = self::registerMethod($vss, $vs, $reflection_class); - + Console::debug("寻找 ".$vs->getName() ." -> ".get_class($vss)); if ($vss instanceof SwooleEventAt) ZMBuf::$events[SwooleEventAt::class][] = $vss; elseif ($vss instanceof SwooleEventAfter) ZMBuf::$events[SwooleEventAfter::class][] = $vss; elseif ($vss instanceof CQMessage) ZMBuf::$events[CQMessage::class][] = $vss; @@ -326,6 +326,7 @@ class AnnotationParser $class = getAllClasses(DataProvider::getWorkingDir() . "/src/Custom/Annotation/", "Custom\\Annotation"); foreach ($class as $v) { $s = DataProvider::getWorkingDir() . '/src/' . str_replace("\\", "/", $v) . ".php"; + Console::debug("Requiring custom annotation ".$s); require_once $s; } } diff --git a/src/ZM/Annotation/CQ/CQCommand.php b/src/ZM/Annotation/CQ/CQCommand.php index 2db1693e..4c78bcb2 100644 --- a/src/ZM/Annotation/CQ/CQCommand.php +++ b/src/ZM/Annotation/CQ/CQCommand.php @@ -21,6 +21,14 @@ class CQCommand extends AnnotationBase implements Level public $regexMatch = ""; /** @var string[] */ public $alias = []; + /** @var string */ + public $message_type = ""; + /** @var int */ + public $user_id = 0; + /** @var int */ + public $group_id = 0; + /** @var int */ + public $discuss_id = 0; /** @var int */ public $level = 20; diff --git a/src/ZM/DB/DB.php b/src/ZM/DB/DB.php index 67fc6253..a2da49a0 100644 --- a/src/ZM/DB/DB.php +++ b/src/ZM/DB/DB.php @@ -90,10 +90,11 @@ class DB /** * @param string $line * @param array $params + * @param int $fetch_mode * @return mixed * @throws DbException */ - public static function rawQuery(string $line, $params = []) { + public static function rawQuery(string $line, $params = [], $fetch_mode = ZM_DEFAULT_FETCH_MODE) { if (ZMBuf::get("sql_log") === true) { $starttime = microtime(true); } @@ -131,7 +132,7 @@ class DB "] " . $line . " " . json_encode($params, JSON_UNESCAPED_UNICODE) . "\n"; Coroutine::writeFile(CRASH_DIR . "sql.log", $log, FILE_APPEND); } - return $ps->fetchAll(); + return $ps->fetchAll($fetch_mode); } } catch (DbException $e) { if (ZMBuf::get("sql_log") === true) { diff --git a/src/ZM/DB/SelectBody.php b/src/ZM/DB/SelectBody.php index 553894c2..7d0f8995 100644 --- a/src/ZM/DB/SelectBody.php +++ b/src/ZM/DB/SelectBody.php @@ -41,10 +41,11 @@ class SelectBody } /** + * @param int $fetch_mode * @return null * @throws DbException */ - public function fetchAll() { + public function fetchAll($fetch_mode = ZM_DEFAULT_FETCH_MODE) { if ($this->table->isCacheEnabled()) { $rr = md5(implode(",", $this->select_thing) . serialize($this->where_thing)); if (array_key_exists($rr, $this->table->cache)) { @@ -52,7 +53,7 @@ class SelectBody return $this->table->cache[$rr]->getResult(); } } - $this->execute(); + $this->execute($fetch_mode); if ($this->table->isCacheEnabled() && !in_array($rr, $this->table->cache)) { $this->table->cache[$rr] = $this; } @@ -81,11 +82,12 @@ class SelectBody } /** + * @param int $fetch_mode * @throws DbException */ - public function execute() { + public function execute($fetch_mode = ZM_DEFAULT_FETCH_MODE) { $str = $this->queryPrepare(); - $this->result = DB::rawQuery($str[0], $str[1]); + $this->result = DB::rawQuery($str[0], $str[1], $fetch_mode); } public function getResult() { return $this->result; } diff --git a/src/ZM/Event/CQ/MessageEvent.php b/src/ZM/Event/CQ/MessageEvent.php index 8a4d486d..3ca2858a 100644 --- a/src/ZM/Event/CQ/MessageEvent.php +++ b/src/ZM/Event/CQ/MessageEvent.php @@ -101,7 +101,11 @@ class MessageEvent foreach (ZMBuf::$events[CQCommand::class] ?? [] as $v) { /** @var CQCommand $v */ if ($v->match == "" && $v->regexMatch == "") continue; - else { + elseif (($v->user_id == 0 || ($v->user_id != 0 && $v->user_id == context()->getData()["user_id"])) && + ($v->group_id == 0 || ($v->group_id != 0 && $v->group_id == (context()->getData()["group_id"] ?? 0))) && + ($v->discuss_id == 0 || ($v->discuss_id != 0 && $v->discuss_id == (context()->getData()["discuss_id"] ?? 0))) && + ($v->message_type == '' || ($v->message_type != '' && $v->message_type == context()->getData()["message_type"])) + ) { $c = $v->class; $class_construct = [ "data" => context()->getData(),