fix pic merge

This commit is contained in:
felinae98 2021-09-28 11:48:31 +08:00
parent 5d1108d635
commit 103ea69a3f
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610
3 changed files with 16 additions and 1 deletions

View File

@ -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'])

View File

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

View File

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