From 76dd43609337fc86577eceb1f85b4435e3175452 Mon Sep 17 00:00:00 2001 From: jerry Date: Wed, 18 Jul 2018 17:56:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cqbot/CQBot.php | 1 + src/cqbot/utils/CQUtil.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/cqbot/CQBot.php b/src/cqbot/CQBot.php index 1829e733..f99268be 100755 --- a/src/cqbot/CQBot.php +++ b/src/cqbot/CQBot.php @@ -24,6 +24,7 @@ class CQBot public function __construct(Framework $framework, $package) { $this->starttime = microtime(true); $this->framework = $framework; + if ($package === null) return; $this->data = $package; $this->current_id = $this->data["self_id"]; if ($package["post_type"] == "message") { diff --git a/src/cqbot/utils/CQUtil.php b/src/cqbot/utils/CQUtil.php index de06d4fb..1bb2ec8a 100755 --- a/src/cqbot/utils/CQUtil.php +++ b/src/cqbot/utils/CQUtil.php @@ -19,6 +19,11 @@ class CQUtil Buffer::set("time_send", false);//发送Timing数据到管理群 Buffer::set("cmd_prefix", DP::getJsonData("config.json")["cmd_prefix"] ?? "");//设置指令的前缀符号 Buffer::set("res_code", file_get_contents(WORKING_DIR . "src/cqbot/Framework.php")); + foreach (self::getMods() as $v) { + if (in_array("initValues", get_class_methods($v))) { + $v::initValues(); + } + } } public static function saveAllFiles() { @@ -644,4 +649,21 @@ class CQUtil $d = Buffer::get("groups"); return $d[$group_id] ?? null; } + + static function getCQ($msg) { + if (($start = mb_strpos($msg, '[')) === false) return null; + if (($end = mb_strpos($msg, ']')) === false) return null; + $msg = mb_substr($msg, $start + 1, $end - $start - 1); + if (mb_substr($msg, 0, 3) != "CQ:") return null; + $msg = mb_substr($msg, 3); + $msg2 = explode(",", $msg); + $type = array_shift($msg2); + $array = []; + foreach ($msg2 as $k => $v) { + $ss = explode("=", $v); + $sk = array_shift($ss); + $array[$sk] = implode("=", $ss); + } + return ["type" => $type, "params" => $array, "start" => $start, "end" => $end]; + } } \ No newline at end of file