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