diff --git a/src/OneBot/V12/Object/OneBotEvent.php b/src/OneBot/V12/Object/OneBotEvent.php index 4437a27..c2c9ddf 100644 --- a/src/OneBot/V12/Object/OneBotEvent.php +++ b/src/OneBot/V12/Object/OneBotEvent.php @@ -130,7 +130,7 @@ public function getMessage(bool $return_assoc_array = false): ?array } $this->message_segment_cache = []; foreach ($this->data['message'] as $segment) { - $this->message_segment_cache[] = new MessageSegment($segment['type'], $segment['data']); + $this->message_segment_cache[] = $segment instanceof MessageSegment ? $segment : new MessageSegment($segment['type'], $segment['data']); } return $this->message_segment_cache; } diff --git a/tests/OneBot/V12/Object/OneBotEventTest.php b/tests/OneBot/V12/Object/OneBotEventTest.php new file mode 100644 index 0000000..a2b8d2c --- /dev/null +++ b/tests/OneBot/V12/Object/OneBotEventTest.php @@ -0,0 +1,47 @@ + '123', + 'type' => 'message', + 'self' => [ + 'user_id' => '123', + 'platform' => 'test', + ], + 'detail_type' => 'group', + 'sub_type' => 'normal', + 'time' => 123, + 'alt_message' => '123', + 'group_id' => '123', + 'user_id' => '123', + 'guild_id' => '123', + 'channel_id' => '123', + 'operator_id' => '123', + 'message_id' => '123', + 'message' => [ + [ + 'type' => 'text', + 'data' => [ + 'text' => '123', + ], + ], + ], + ]); + $event->setMessage([ob_segment('mention', ['user_id' => '123456'])]); + $this->assertInstanceOf(MessageSegment::class, $event->getMessage()[0]); + } +}