Commit 5615c38
src/messages/main.py
@@ -231,8 +231,12 @@ async def preview_social_media(
if equal_prefix(this_texts, prefix=[PREFIX.SOCIAL_MEDIA, "/help", "/retry"]):
# without reply, send docs if message only contains prefix command
if not message.reply_to_message:
- help_msg = social_media_help(info["cid"], info["ctype"], PREFIX.SOCIAL_MEDIA)
- return await send2tg(client, message, texts=help_msg, **kwargs)
+ await delete_message(message)
+ docs = social_media_help(info["cid"], info["ctype"], PREFIX.SOCIAL_MEDIA)
+ helps = await send2tg(client, message, texts=docs, **kwargs)
+ await asyncio.sleep(30)
+ return await delete_message(helps)
+
# with reply, treat the reply_msg as the trigger to preview social media link
message = message.reply_to_message
info = parse_msg(message, silent=True, use_cache=False) # parse again
src/messages/utils.py
@@ -227,11 +227,16 @@ async def set_reaction(client: Client, message: Message, reaction: str | list[st
await client.set_reaction(message.chat.id, message.id)
-async def delete_message(message: Message | None):
- if not isinstance(message, Message):
+async def delete_message(message: Message | list[Message | None] | None):
+ if not message:
return
- with contextlib.suppress(Exception):
- await message.delete()
+ if not isinstance(message, list):
+ message = [message]
+ for msg in message:
+ if not isinstance(msg, Message):
+ continue
+ with contextlib.suppress(Exception):
+ await msg.delete()
def remove_img_tag(markdown: str) -> tuple[str, list[str]]: