fix message convert bug

This commit is contained in:
crazywhalecc 2023-02-11 12:27:59 +08:00 committed by Jerry
parent e5463fc15a
commit dcce05c019
3 changed files with 7 additions and 7 deletions

View File

@ -52,6 +52,7 @@ class AnnotationHandler
*/
public static function interrupt(mixed $return_var = null)
{
logger()->debug('阻断事件!');
throw new InterruptException($return_var);
}

View File

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

View File

@ -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()];
}
/**