From 29a66ca0d3bad7dbec7507da0b380c58d488e779 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 25 Aug 2023 22:10:13 +0800 Subject: [PATCH] :bug: Fix bilibili dyn --- defs/bilibili.py | 7 +------ defs/friend_say.py | 2 +- defs/luxun.py | 2 +- modules/friend_say.py | 5 +++-- modules/ip.py | 6 ++++-- modules/twitter_api.py | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/defs/bilibili.py b/defs/bilibili.py index 89bc945..ad248de 100644 --- a/defs/bilibili.py +++ b/defs/bilibili.py @@ -421,15 +421,10 @@ async def get_dynamic_screenshot_pc(dynamic_id): # 动态被删除或者进审核了 if page.url == "https://www.bilibili.com/404": return None - card = await page.query_selector(".card") + card = await page.query_selector(".bili-dyn-item__main") assert card clip = await card.bounding_box() assert clip - bar = await page.query_selector(".bili-dyn-action__icon") - assert bar - bar_bound = await bar.bounding_box() - assert bar_bound - clip["height"] = bar_bound["y"] - clip["y"] return await page.screenshot(clip=clip, full_page=True) except Exception: print(f"截取动态时发生错误:{url}") diff --git a/defs/friend_say.py b/defs/friend_say.py index 3686a1a..d99f7e1 100644 --- a/defs/friend_say.py +++ b/defs/friend_say.py @@ -91,7 +91,7 @@ class ImageUtil: self.height = height else: self.mark_image = Image.open(background).resize( - (self.width, self.height), Image.ANTIALIAS + (self.width, self.height), Image.Resampling.LANCZOS ) if is_alpha: array = self.mark_image.load() diff --git a/defs/luxun.py b/defs/luxun.py index 44e69f9..63e395c 100644 --- a/defs/luxun.py +++ b/defs/luxun.py @@ -15,7 +15,7 @@ def process_pic(content) -> BytesIO: draw = ImageDraw.Draw(bk_img) current_h, pad = 300, 10 for line in para: - w, h = draw.textsize(line, font=font) + _, _, w, h = font.getbbox(line) draw.text(((MAX_W - w) / 2, current_h), line, font=font) current_h += h + pad draw.text((320, 400), "——鲁迅", font=font2, fill=(255, 255, 255)) diff --git a/modules/friend_say.py b/modules/friend_say.py index 4252b56..0c93253 100644 --- a/modules/friend_say.py +++ b/modules/friend_say.py @@ -1,3 +1,4 @@ +import aiofiles from io import BytesIO from os import sep, makedirs from os.path import exists @@ -27,8 +28,8 @@ async def friend_say(client: Client, message: Message): user_name = message.reply_to_message.from_user.first_name # Create image if avatar: - with open(avatar, "rb") as fh: - buf = BytesIO(fh.read()) + async with aiofiles.open(avatar, "rb") as fh: + buf = BytesIO(await fh.read()) ava = ImageUtil(100, 100, background=buf) else: ava = ImageUtil(100, 100, color=(0, 0, 0)) diff --git a/modules/ip.py b/modules/ip.py index eed71b5..9c3381a 100644 --- a/modules/ip.py +++ b/modules/ip.py @@ -77,6 +77,8 @@ async def ip_command(_: Client, message: Message): if rep_text == "" and text == "": await msg.edit("没有找到要查询的 ip/域名 ...") elif rep_text != "" and text != "": - await msg.edit(f"{rep_text}\n================\n{text}") + await msg.edit( + f"{rep_text}\n================\n{text}", disable_web_page_preview=True + ) else: - await msg.edit(f"{rep_text}{text}") + await msg.edit(f"{rep_text}{text}", disable_web_page_preview=True) diff --git a/modules/twitter_api.py b/modules/twitter_api.py index 0d041af..5460cfa 100644 --- a/modules/twitter_api.py +++ b/modules/twitter_api.py @@ -84,7 +84,7 @@ async def process_user(message: Message, username: str): ) -@Client.on_message(filters.incoming & filters.text & filters.regex(r"twitter.com/")) +# @Client.on_message(filters.incoming & filters.text & filters.regex(r"twitter.com/")) async def twitter_share(_: Client, message: Message): if not message.text: return