From afbd2774285d593a25dbd94e312e2fbb22aadada Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Tue, 13 Aug 2024 21:54:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D1=85=20=D1=81=D0=BE=D0=BE?= =?UTF-8?q?=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BE=D0=B1=20=D1=83?= =?UTF-8?q?=D1=81=D0=BF=D0=B5=D1=85=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ocab_modules/standard/welcome/main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ocab_modules/ocab_modules/standard/welcome/main.py b/src/ocab_modules/ocab_modules/standard/welcome/main.py index 258b529..92210b1 100644 --- a/src/ocab_modules/ocab_modules/standard/welcome/main.py +++ b/src/ocab_modules/ocab_modules/standard/welcome/main.py @@ -5,6 +5,7 @@ from typing import TYPE_CHECKING from aiogram import Bot, Router, types from aiogram.enums import ChatMemberStatus, ParseMode +from aiogram.exceptions import TelegramBadRequest from aiogram.filters import JOIN_TRANSITION, LEAVE_TRANSITION, ChatMemberUpdatedFilter from aiogram.types import ChatMemberUpdated, PollAnswer @@ -43,6 +44,7 @@ class TaskManager: for cls in all_tasks: type_name = cls.type_name() if self.config.get(f"welcome::tasks::{type_name}::enabled"): + log(f"Task {cls.type_name()} enabled") self.available_tasks.append(cls) self.max_attempts = self.config.get("welcome::max_attempts") @@ -65,6 +67,7 @@ class TaskManager: verification_tasks = MultiKeyDict() +last_success = {} if TYPE_CHECKING: from ocab_modules.standard.config import IConfig @@ -117,8 +120,15 @@ async def success_end(task: BaseTask): await asyncio.sleep(3) + if task.from_chat_id in last_success: + message_id = last_success.pop(task.from_chat_id) + try: + await task.bot.delete_message(task.from_chat_id, message_id) + except TelegramBadRequest: + pass + if config.get("welcome::show_success_message"): - await task.bot.send_message( + message = await task.bot.send_message( task.from_chat_id, Template(config.get("welcome::success_message")).substitute( mention=user_mention(task.from_user) @@ -126,6 +136,8 @@ async def success_end(task: BaseTask): parse_mode=ParseMode.HTML, ) + last_success[task.from_chat_id] = message.message_id + async def handle_poll_verification(answer: PollAnswer, bot: Bot): key = key_from_poll(answer.poll_id)