diff --git a/src/plugins/nonebot_hk_reporter/platform/weibo.py b/src/plugins/nonebot_hk_reporter/platform/weibo.py index 227bf2a..e3a27c4 100644 --- a/src/plugins/nonebot_hk_reporter/platform/weibo.py +++ b/src/plugins/nonebot_hk_reporter/platform/weibo.py @@ -117,3 +117,4 @@ class Weibo(NewMessage, TargetMixin): detail_url = 'https://weibo.com/{}/{}'.format(info['user']['id'], info['bid']) # return parsed_text, detail_url, pic_urls return Post('weibo', text=parsed_text, url=detail_url, pics=pic_urls, target_name=info['user']['screen_name']) + diff --git a/src/plugins/nonebot_hk_reporter/post.py b/src/plugins/nonebot_hk_reporter/post.py index d101e7b..862c086 100644 --- a/src/plugins/nonebot_hk_reporter/post.py +++ b/src/plugins/nonebot_hk_reporter/post.py @@ -21,7 +21,7 @@ class Post: target_name: Optional[str] = None compress: bool = False override_use_pic: Optional[bool] = None - pics: list[Union[str,bytes]] = field(default_factory=list) + pics: Union[list[Union[str,bytes]], list[str], list[bytes]] = field(default_factory=list) extra_msg: list[Message] = field(default_factory=list) _message: Optional[list] = None @@ -66,6 +66,8 @@ class Post: x_coord.append(_tmp) y_coord = [0, first_image.size[1]] async def process_row(row: int) -> bool: + if len(self.pics) < (row + 1) * 3: + return False row_first_img = await self._pic_url_to_image(self.pics[row * 3]) if not self._check_image_square(row_first_img.size): return False diff --git a/tests/test_merge_pic.py b/tests/test_merge_pic.py index 10960b1..9aeb5ec 100644 --- a/tests/test_merge_pic.py +++ b/tests/test_merge_pic.py @@ -40,3 +40,15 @@ async def test_3_merge(plugin_module): post = plugin_module.post.Post('', '', '', pics=merge_source_9[0:3]+merge_source_9[9:]) await post._pic_merge() assert len(post.pics) == 5 + +@pytest.mark.asyncio +async def test_6_merge_only(plugin_module): + post = plugin_module.post.Post('', '', '', pics=merge_source_9[0:6]) + await post._pic_merge() + assert len(post.pics) == 1 + +@pytest.mark.asyncio +async def test_3_merge_only(plugin_module): + post = plugin_module.post.Post('', '', '', pics=merge_source_9[0:3]) + await post._pic_merge() + assert len(post.pics) == 1