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