Commit 84ee13d
src/messages/sender.py
@@ -133,15 +133,14 @@ 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:
- sent_messages.append(await client.send_message(target_chat, texts, reply_parameters=reply_parameters))
+ sent_messages.append(await client.send_message(target_chat, better_blockquote(msg), reply_parameters=reply_parameters))
except FloodWait as e:
logger.warning(e)
await asyncio.sleep(e.value) # type: ignore
- sent_messages.append(await client.send_message(target_chat, texts, reply_parameters=reply_parameters))
+ sent_messages.append(await client.send_message(target_chat, better_blockquote(msg), reply_parameters=reply_parameters))
except Exception as e:
logger.warning(f"send_texts: {e}")
await asyncio.sleep(cooldown)
src/messages/utils.py
@@ -181,11 +181,12 @@ async def smart_split(text: str, chars_per_string: int = TEXT_LENGTH, mode: Pars
def blockquote(s: str) -> str:
"""Block quote texts."""
- s = s.removeprefix(BLOCKQUOTE_EXPANDABLE_DELIM).removesuffix(SPOILER_DELIM)
+ s = s.removeprefix(BLOCKQUOTE_EXPANDABLE_DELIM).removesuffix(SPOILER_DELIM).strip()
if not s:
return s
- return "\n" + BLOCKQUOTE_EXPANDABLE_DELIM + s.replace("\n", f"\n{BLOCKQUOTE_DELIM}") + SPOILER_DELIM
+ s = "\n" + BLOCKQUOTE_EXPANDABLE_DELIM + s.replace("\n", f"\n{BLOCKQUOTE_DELIM}")
+ return s.rstrip() + SPOILER_DELIM
def quote(s: str) -> str:
@@ -198,9 +199,11 @@ 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}")
+ s = str(s).rstrip().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
+ if s.endswith(SPOILER_DELIM) and BLOCKQUOTE_EXPANDABLE_DELIM not in s:
+ return BLOCKQUOTE_EXPANDABLE_DELIM + s
return s