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)