Skip to content

Commit

Permalink
fix event segment (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxyw authored Jan 10, 2023
1 parent d394d29 commit 0a4bdf9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OneBot/V12/Object/OneBotEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
47 changes: 47 additions & 0 deletions tests/OneBot/V12/Object/OneBotEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Tests\OneBot\V12\Object;

use OneBot\V12\Object\MessageSegment;
use OneBot\V12\Object\OneBotEvent;
use PHPUnit\Framework\TestCase;

/**
* @internal
*/
class OneBotEventTest extends TestCase
{
public function testGetMessageSegments(): void
{
$event = new OneBotEvent([
'id' => '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]);
}
}

0 comments on commit 0a4bdf9

Please # to comment.