Commit 1d8ce58
Changed files (4)
src
src/messages/preprocess.py
@@ -6,7 +6,7 @@ from loguru import logger
from pyrogram.types import InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo
from config import CAPTION_LENGTH
-from messages.utils import count_without_entities, smart_split
+from messages.utils import better_blockquote, count_without_entities, smart_split
from multimedia import fix_ctts_invalid, fix_video_rotation, generate_cover, is_valid_video_or_audio, parse_media_info, split_large_video, split_long_img, validate_img
@@ -152,6 +152,7 @@ async def warp_media_group(media: list[dict], caption: str = "", *, caption_abov
if await count_without_entities(caption) > CAPTION_LENGTH:
logger.warning(f"Caption too long, length: {len(caption)}, caption: {caption}")
caption = (await smart_split(caption, CAPTION_LENGTH))[0]
+ caption = better_blockquote(caption)
if len(media) > 10:
logger.warning(f"Too many media files, number of media: {len(media)}")
media = media[:10]
src/messages/progress.py
@@ -9,7 +9,7 @@ from pyrogram.errors import FloodWait, MessageNotModified
from pyrogram.types import Message
from config import TEXT_LENGTH, cache
-from messages.utils import delete_message, smart_split
+from messages.utils import better_blockquote, delete_message, smart_split
async def modify_progress(
@@ -51,7 +51,6 @@ async def modify_progress(
try:
if not text:
return
- text = str(text)
if text == message.text:
return
if cache.get("modify_progress"): # DO NOT update too frequently
@@ -63,6 +62,7 @@ async def modify_progress(
if len(text) > TEXT_LENGTH:
text = text[: 10 * TEXT_LENGTH] # trim the very long texts
text = (await smart_split(text))[0]
+ text = better_blockquote(text)
logger.trace(f"Progress: {text!r}")
await message.edit_text(text)
cache.set("modify_progress", "1", ttl=ttl)
src/messages/sender.py
@@ -13,7 +13,7 @@ from pyrogram.types import Message, ReplyParameters
from config import CAPTION_LENGTH, TID
from messages.preprocess import preprocess_media, warp_media_group
from messages.progress import modify_progress, telegram_uploading
-from messages.utils import delete_message, get_reply_to, smart_split, summay_media
+from messages.utils import better_blockquote, delete_message, get_reply_to, smart_split, summay_media
from utils import to_int
@@ -88,6 +88,7 @@ async def send2tg(
caption = (await smart_split(texts, CAPTION_LENGTH))[0]
remaining_texts = texts.removeprefix(caption)
+ caption = better_blockquote(caption)
if 1 < len(media) <= 10:
group = await warp_media_group(media, caption=caption, caption_above=caption_above)
sent_messages.extend(await send_media_group(client, target_chat, group, reply_parameters))
@@ -132,7 +133,7 @@ async def send_texts(
# we do not send comments-only texts
if (f"{BLOCKQUOTE_EXPANDABLE_DELIM}💬" in msg or f"{BLOCKQUOTE_DELIM}💬" in msg) and "💬**点此展开评论区**:" not in msg:
continue
-
+ texts = better_blockquote(texts)
if idx != 0:
reply_parameters = ReplyParameters()
try:
@@ -162,6 +163,7 @@ async def send_single_media(
logger.trace(f"Sending single media with {len(texts)} texts")
caption = (await smart_split(texts, CAPTION_LENGTH))[0]
remaining_texts = texts.removeprefix(caption)
+ caption = better_blockquote(caption)
message = None
try:
if media.get("photo"):
src/messages/utils.py
@@ -194,6 +194,16 @@ def quote(s: str) -> str:
return BLOCKQUOTE_DELIM + s.replace("\n", f"\n{BLOCKQUOTE_DELIM}")
+def better_blockquote(s: str) -> str:
+ """Better block quote texts."""
+ if not s:
+ return ""
+ s = str(s).replace(f"\n\n{BLOCKQUOTE_EXPANDABLE_DELIM}", f"\n{BLOCKQUOTE_EXPANDABLE_DELIM}")
+ if f"\n{BLOCKQUOTE_EXPANDABLE_DELIM}" in s and SPOILER_DELIM not in s:
+ return s + SPOILER_DELIM
+ return s
+
+
async def sent_from_me(client: Client, message: Message) -> bool:
"""Check if this clinet is a bot or not."""
try: