From ae742c1568ff5b383888c3f6ce521490be8a9456 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 12 Feb 2023 00:19:53 +0800 Subject: [PATCH] fix multiple prompt timer bug --- docs/update/v3.md | 14 ++++++++++++++ src/ZM/Context/BotContext.php | 5 +++-- src/ZM/Framework.php | 2 +- src/ZM/Schedule/Timer.php | 5 +++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/update/v3.md b/docs/update/v3.md index 5259e5a1..9e14ec07 100644 --- a/docs/update/v3.md +++ b/docs/update/v3.md @@ -2,6 +2,20 @@ > 本页面由框架命令 `./zhamao generate:text update-log-md` 自动生成 +## v3.0.1 + +> 更新时间:2023-02-11 + +* 本次更新包含文档更新内容 1 个 +* 修复 Message 转换时的 Bug by [@crazywhalecc](https://github.com/crazywhalecc) in [PR#289](https://github.com/zhamao-robot/zhamao-framework/pull/289) +* 修复初始化命令兼容性问题 by [@sunxyw](https://github.com/sunxyw) in [PR#295](https://github.com/zhamao-robot/zhamao-framework/pull/295) +* 修复安装脚本不使用内置 Composer by [@sunxyw](https://github.com/sunxyw) in [PR#296](https://github.com/zhamao-robot/zhamao-framework/pull/296) +* 修复插件安装命令若干问题 by [@sunxyw](https://github.com/sunxyw) in [PR#297](https://github.com/zhamao-robot/zhamao-framework/pull/297) +* 修复排程任务不支持提醒 by [@sunxyw](https://github.com/sunxyw) in [PR#298](https://github.com/zhamao-robot/zhamao-framework/pull/298) +* **破坏性修改**:更改 prompt() 方法配置参数的特性 by [@crazywhalecc](https://github.com/crazywhalecc) in [PR#299](https://github.com/zhamao-robot/zhamao-framework/pull/299) + +**源码变更记录**: + ## v3.0.0 > 更新时间:2023-02-10 diff --git a/src/ZM/Context/BotContext.php b/src/ZM/Context/BotContext.php index d26a10b2..084c8276 100644 --- a/src/ZM/Context/BotContext.php +++ b/src/ZM/Context/BotContext.php @@ -16,6 +16,7 @@ use ZM\Context\Trait\BotActionTrait; use ZM\Exception\OneBot12Exception; use ZM\Exception\WaitTimeoutException; use ZM\Plugin\OneBot12Adapter; +use ZM\Schedule\Timer; use ZM\Utils\MessageUtil; class BotContext implements ContextInterface @@ -114,14 +115,14 @@ class BotContext implements ContextInterface } $cid = $co->getCid(); OneBot12Adapter::addContextPrompt($cid, $event); - $co->create(function () use ($cid, $timeout) { - Adaptive::sleep($timeout); + $timer_id = zm_timer_after($timeout * 1000, function () use ($cid) { if (OneBot12Adapter::isContextPromptExists($cid)) { Adaptive::getCoroutine()->resume($cid, ''); } }); $result = $co->suspend(); OneBot12Adapter::removeContextPrompt($cid); + Timer::del($timer_id); if ($result === '') { throw new WaitTimeoutException( $this, diff --git a/src/ZM/Framework.php b/src/ZM/Framework.php index 0aeb8c5f..c9fda26f 100644 --- a/src/ZM/Framework.php +++ b/src/ZM/Framework.php @@ -47,7 +47,7 @@ class Framework public const VERSION_ID = 689; /** @var string 版本名称 */ - public const VERSION = '3.0.1'; + public const VERSION = '3.0.2'; /** @var array 传入的参数 */ protected array $argv; diff --git a/src/ZM/Schedule/Timer.php b/src/ZM/Schedule/Timer.php index ab3c2c2f..d366ce72 100644 --- a/src/ZM/Schedule/Timer.php +++ b/src/ZM/Schedule/Timer.php @@ -19,6 +19,11 @@ class Timer return Framework::getInstance()->getDriver()->getEventLoop()->addTimer($ms, $callback); } + public static function del(int $timer_id): void + { + Framework::getInstance()->getDriver()->getEventLoop()->clearTimer($timer_id); + } + public static function registerTick(Tick $v): void { if ($v->class !== '' && $v->method !== '') {