fix multiple prompt timer bug

This commit is contained in:
crazywhalecc
2023-02-12 00:19:53 +08:00
committed by Jerry
parent b61421f2b6
commit ae742c1568
4 changed files with 23 additions and 3 deletions

View File

@@ -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,