Merge pull request #223 from zhamao-robot/fix-ob12-cmd-bug

修复有关 BotCommand 的 Bug
This commit is contained in:
Jerry 2022-12-31 20:29:16 +08:00 committed by GitHub
commit 3a78f5e2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 13 deletions

View File

@ -94,15 +94,6 @@ class AnnotationHandler
foreach ((AnnotationMap::$_list[$this->annotation_class] ?? []) as $v) {
// 调用单个注解
$this->handle($v, $this->rule_callback, ...$params);
// 执行完毕后检查状态如果状态是规则判断或中间件before不通过则重置状态后继续执行别的注解函数
if ($this->status == self::STATUS_BEFORE_FAILED || $this->status == self::STATUS_RULE_FAILED) {
$this->status = self::STATUS_NORMAL;
continue;
}
// 如果执行完毕,且设置了返回值后续逻辑的回调函数,那么就调用返回值回调的逻辑
if (is_callable($this->return_callback) && $this->status === self::STATUS_NORMAL) {
($this->return_callback)($this->return_val);
}
}
} catch (InterruptException $e) {
// InterruptException 用于中断,这里必须 catch并标记状态
@ -140,6 +131,15 @@ class AnnotationHandler
}
try {
$this->return_val = middleware()->process($callback, ...$args);
// 执行完毕后检查状态如果状态是规则判断或中间件before不通过则重置状态后继续执行别的注解函数
if ($this->status == self::STATUS_BEFORE_FAILED || $this->status == self::STATUS_RULE_FAILED) {
$this->status = self::STATUS_NORMAL;
return false;
}
// 如果执行完毕,且设置了返回值后续逻辑的回调函数,那么就调用返回值回调的逻辑
if (is_callable($this->return_callback) && $this->status === self::STATUS_NORMAL) {
($this->return_callback)($this->return_val);
}
} catch (InterruptException $e) {
// 这里直接抛出这个异常的目的就是给上层handleAll()捕获
throw $e;

View File

@ -46,7 +46,7 @@ class Framework
public const VERSION_ID = 654;
/** @var string 版本名称 */
public const VERSION = '3.0.0-beta3';
public const VERSION = '3.0.0-beta4';
/** @var array 传入的参数 */
protected array $argv;

View File

@ -365,12 +365,12 @@ class OneBot12Adapter extends ZMPlugin
continue;
}
// 测试 match
if ($v->match !== '' && $v->match === $head) {
if ($v->match !== '' && ($v->prefix . $v->match) === $head) {
array_shift($cmd_explode);
return [$v, $cmd_explode, $full_str];
}
// 测试 alias
if ($v->match !== '' && $v->alias !== [] && in_array($head, $v->alias, true)) {
if ($v->match !== '' && $v->alias !== [] && in_array($head, array_map(fn ($x) => $v->prefix . $x, $v->alias), true)) {
array_shift($cmd_explode);
return [$v, $cmd_explode, $full_str];
}
@ -610,7 +610,7 @@ class OneBot12Adapter extends ZMPlugin
{
$handler = new AnnotationHandler(BotCommand::class);
$handler->setReturnCallback(function ($result) use ($ctx) {
if (is_string($result)) {
if (is_string($result) || $result instanceof MessageSegment) {
$ctx->reply($result);
return;
}