Commit c1a96fa
Changed files (2)
src
preview
src/preview/twitter.py
@@ -34,9 +34,9 @@ async def preview_twitter(
Args:
client (Client): The Pyrogram client.
message (Message): The trigger message object.
+ url (str, optional): The twitter link.
+ db_key (str, optional): The cache key.
platform (str): The domain of the link: twitter, x, fxtwitter, fixupx
- handle (str): The twitter handle.
- post_id (str): The twitter post id.
twitter_extractor (str): The extractor to use: fxtwitter or tikhub. Defaults to "tikhub".
fallback (bool, optional): Fallback to other bots. Defaults to True.
src/preview/weibo.py
@@ -23,25 +23,24 @@ from utils import https_url, rand_string, soup_to_text, split_parts, ts_to_dt
@cache.memoize(ttl=10)
-async def preview_weibo(client: Client, message: Message, url: str, post_id: str = "", *, fetch_weibo_comments: bool = True, fallback: bool = True, **kwargs):
+async def preview_weibo(client: Client, message: Message, url: str, db_key: str = "", post_id: str = "", *, fetch_weibo_comments: bool = True, fallback: bool = True, **kwargs):
"""Preview weibo link in the message.
Args:
client (Client): The Pyrogram client.
message (Message): The trigger message object.
url (str, optional): Weibo link.
+ db_key (str, optional): The cache key.
post_id (str, optional): Weibo post ID
fetch_weibo_comments (bool, optional): Fetch weibo comments. Defaults to True.
fallback (bool, optional): Fallback to other bots. Defaults to True.
"""
if post_id.startswith("weibovideo"): # disable comments for weibo video
fetch_weibo_comments = False
- else:
- url = f"https://m.weibo.cn/detail/{post_id}"
if kwargs.get("show_progress") and "progress" not in kwargs:
res = await send2tg(client, message, texts=f"🔗正在解析微博链接\n{url}", **kwargs)
kwargs["progress"] = res[0]
- if kv := await get_db(url):
+ if kv := await get_db(db_key):
logger.debug(f"Weibo preview {DB.ENGINE} cache hit for key={url}")
if await copy_messages_from_db(client, message, key=url, kv=kv, **kwargs):
return
@@ -108,7 +107,7 @@ async def preview_weibo(client: Client, message: Message, url: str, post_id: str
comments = await parse_weibo_comments(post_id) if fetch_weibo_comments else []
sent_messages = await send2tg(client, message, texts=emojify(msg.strip()), media=media, comments=comments, **kwargs)
await modify_progress(del_status=True, **kwargs)
- await save_messages(messages=sent_messages, key=url)
+ await save_messages(messages=sent_messages, key=db_key)
@cache.memoize(ttl=30)