mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
fix message convert bug
This commit is contained in:
parent
e5463fc15a
commit
dcce05c019
@ -52,6 +52,7 @@ class AnnotationHandler
|
||||
*/
|
||||
public static function interrupt(mixed $return_var = null)
|
||||
{
|
||||
logger()->debug('阻断事件!');
|
||||
throw new InterruptException($return_var);
|
||||
}
|
||||
|
||||
|
||||
@ -72,9 +72,11 @@ trait BotActionTrait
|
||||
|
||||
// 调用机器人连接发送 Action,首先试试看是不是 WebSocket
|
||||
if ($this->base_event instanceof WebSocketMessageEvent) {
|
||||
logger()->debug('使用传入的 base_event 发送消息');
|
||||
$result = $this->base_event->send(json_encode($a->jsonSerialize()));
|
||||
}
|
||||
if (!isset($result) && container()->has('ws.message.event')) {
|
||||
logger()->debug('使用容器的 Event 发送消息');
|
||||
$result = container()->get('ws.message.event')->send(json_encode($a->jsonSerialize()));
|
||||
}
|
||||
// 如果是 HTTP WebHook 的形式,那么直接调用 Response
|
||||
|
||||
@ -61,23 +61,20 @@ class MessageUtil
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public static function convertToArr(MessageSegment|\Stringable|array|string $message)
|
||||
public static function convertToArr(MessageSegment|\Stringable|array|string $message): array
|
||||
{
|
||||
if (is_array($message)) {
|
||||
foreach ($message as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
$message[$k] = new MessageSegment('text', ['text' => $v]);
|
||||
$message[$k] = segment('text', ['text' => $v])->jsonSerialize();
|
||||
}
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
if ($message instanceof MessageSegment) {
|
||||
return [$message];
|
||||
return [$message->jsonSerialize()];
|
||||
}
|
||||
if ($message instanceof \Stringable) {
|
||||
return new MessageSegment('text', ['text' => $message->__toString()]);
|
||||
}
|
||||
return new MessageSegment('text', ['text' => $message]);
|
||||
return [segment('text', ['text' => $message])->jsonSerialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user