mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
Merge pull request #223 from zhamao-robot/fix-ob12-cmd-bug
修复有关 BotCommand 的 Bug
This commit is contained in:
@@ -94,15 +94,6 @@ class AnnotationHandler
|
|||||||
foreach ((AnnotationMap::$_list[$this->annotation_class] ?? []) as $v) {
|
foreach ((AnnotationMap::$_list[$this->annotation_class] ?? []) as $v) {
|
||||||
// 调用单个注解
|
// 调用单个注解
|
||||||
$this->handle($v, $this->rule_callback, ...$params);
|
$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) {
|
} catch (InterruptException $e) {
|
||||||
// InterruptException 用于中断,这里必须 catch,并标记状态
|
// InterruptException 用于中断,这里必须 catch,并标记状态
|
||||||
@@ -140,6 +131,15 @@ class AnnotationHandler
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->return_val = middleware()->process($callback, ...$args);
|
$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) {
|
} catch (InterruptException $e) {
|
||||||
// 这里直接抛出这个异常的目的就是给上层handleAll()捕获
|
// 这里直接抛出这个异常的目的就是给上层handleAll()捕获
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Framework
|
|||||||
public const VERSION_ID = 654;
|
public const VERSION_ID = 654;
|
||||||
|
|
||||||
/** @var string 版本名称 */
|
/** @var string 版本名称 */
|
||||||
public const VERSION = '3.0.0-beta3';
|
public const VERSION = '3.0.0-beta4';
|
||||||
|
|
||||||
/** @var array 传入的参数 */
|
/** @var array 传入的参数 */
|
||||||
protected array $argv;
|
protected array $argv;
|
||||||
|
|||||||
@@ -365,12 +365,12 @@ class OneBot12Adapter extends ZMPlugin
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 测试 match
|
// 测试 match
|
||||||
if ($v->match !== '' && $v->match === $head) {
|
if ($v->match !== '' && ($v->prefix . $v->match) === $head) {
|
||||||
array_shift($cmd_explode);
|
array_shift($cmd_explode);
|
||||||
return [$v, $cmd_explode, $full_str];
|
return [$v, $cmd_explode, $full_str];
|
||||||
}
|
}
|
||||||
// 测试 alias
|
// 测试 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);
|
array_shift($cmd_explode);
|
||||||
return [$v, $cmd_explode, $full_str];
|
return [$v, $cmd_explode, $full_str];
|
||||||
}
|
}
|
||||||
@@ -610,7 +610,7 @@ class OneBot12Adapter extends ZMPlugin
|
|||||||
{
|
{
|
||||||
$handler = new AnnotationHandler(BotCommand::class);
|
$handler = new AnnotationHandler(BotCommand::class);
|
||||||
$handler->setReturnCallback(function ($result) use ($ctx) {
|
$handler->setReturnCallback(function ($result) use ($ctx) {
|
||||||
if (is_string($result)) {
|
if (is_string($result) || $result instanceof MessageSegment) {
|
||||||
$ctx->reply($result);
|
$ctx->reply($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user