announce-msg-fix

This commit is contained in:
Untone 2024-09-26 19:59:24 +03:00
parent 74c3e249b8
commit 6c64554b7e

View File

@ -7,8 +7,6 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
announces = {}
def get_newcomer_message(msg): def get_newcomer_message(msg):
lang = msg["from"].get("language_code", "ru") lang = msg["from"].get("language_code", "ru")
r = "хочет присоединиться к нам здесь" if lang == "ru" else " wants to join us here" r = "хочет присоединиться к нам здесь" if lang == "ru" else " wants to join us here"
@ -39,8 +37,8 @@ async def show_announce(msg):
caption=newcomer_message, caption=newcomer_message,
reply_to=mid reply_to=mid
) )
logger.debug(r) announce_msg_id = r.get("message_id")
announces[from_id] = r.get("message_id") await redis.set(f"announce:{chat_id}:{from_id}", announce_message_id)
async def edit_announce(msg): async def edit_announce(msg):
@ -48,7 +46,8 @@ async def edit_announce(msg):
chat_id = str(msg["chat"]["id"]) chat_id = str(msg["chat"]["id"])
from_id = str(msg["from"]["id"]) from_id = str(msg["from"]["id"])
mid = msg.get("message_id", "") mid = msg.get("message_id", "")
caption = get_newcomer_message(msg) + msg.get("text") caption = get_newcomer_message(msg) + msg.get("text").replace("/message ", "")
announce_message_id = announces.get(from_id) announce_message_id = await redis.get(f"announce:{chat_id}:{from_id}")
r = await telegram_api("editMessageCaption", chat_id=chat_id, message_id=announce_message_id, caption=caption) if announce_message_id:
announces[from_id] = r.get("message_id") r = await telegram_api("editMessageCaption", chat_id=chat_id, message_id=int(announce_message_id), caption=caption)
await redis.set(f"announce:{chat_id}:{from_id}", r.get("message_id"))