From 46dd4398271d3594d3d06429fa25eb3e3ace7187 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 6 Mar 2023 00:58:39 +0800 Subject: [PATCH] fix BotContext hasReplied bug --- src/ZM/Context/BotContext.php | 15 ++++++++++----- src/ZM/Framework.php | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ZM/Context/BotContext.php b/src/ZM/Context/BotContext.php index de855ea3..2e497ba6 100644 --- a/src/ZM/Context/BotContext.php +++ b/src/ZM/Context/BotContext.php @@ -30,9 +30,6 @@ class BotContext implements ContextInterface /** @var array 如果是 BotCommand 匹配的上下文,这里会存放匹配到的参数 */ private array $params = []; - /** @var bool 用于标记当前上下文会话是否已经调用过 reply() 方法 */ - private bool $replied = false; - public function __construct(string $bot_id, string $platform) { $this->self = ['user_id' => $bot_id, 'platform' => $platform]; @@ -69,7 +66,7 @@ class BotContext implements ContextInterface throw new OneBot12Exception('bot()->reply() can only be used in message event.'); } $msg = (is_string($message) ? [new MessageSegment('text', ['text' => $message])] : ($message instanceof MessageSegment ? [$message] : $message)); - $this->replied = true; + container()->set('replied', true); // 判断规则 $this->matchReplyMode($reply_mode, $msg, $event); return $this->sendMessage($msg, $event->detail_type, $event->jsonSerialize()); @@ -148,7 +145,15 @@ class BotContext implements ContextInterface */ public function hasReplied(): bool { - return $this->replied; + return container()->has('replied') && container()->get('replied') === true; + } + + /** + * 重置当前上下文为没有被回复过 + */ + public function flushReply(): void + { + container()->set('replied', false); } /** diff --git a/src/ZM/Framework.php b/src/ZM/Framework.php index d97bd5cf..ed2711cf 100644 --- a/src/ZM/Framework.php +++ b/src/ZM/Framework.php @@ -47,7 +47,7 @@ class Framework public const VERSION_ID = 702; /** @var string 版本名称 */ - public const VERSION = '3.1.0'; + public const VERSION = '3.1.1'; /** @var array 传入的参数 */ protected array $argv;