mirror of
https://gitflic.ru/project/alt-gnome/karkas.git
synced 2024-12-24 00:33:06 +03:00
добавлено удаление старых сообщений об успехе
This commit is contained in:
parent
15cb6afb34
commit
afbd277428
@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
from aiogram import Bot, Router, types
|
from aiogram import Bot, Router, types
|
||||||
from aiogram.enums import ChatMemberStatus, ParseMode
|
from aiogram.enums import ChatMemberStatus, ParseMode
|
||||||
|
from aiogram.exceptions import TelegramBadRequest
|
||||||
from aiogram.filters import JOIN_TRANSITION, LEAVE_TRANSITION, ChatMemberUpdatedFilter
|
from aiogram.filters import JOIN_TRANSITION, LEAVE_TRANSITION, ChatMemberUpdatedFilter
|
||||||
from aiogram.types import ChatMemberUpdated, PollAnswer
|
from aiogram.types import ChatMemberUpdated, PollAnswer
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ class TaskManager:
|
|||||||
for cls in all_tasks:
|
for cls in all_tasks:
|
||||||
type_name = cls.type_name()
|
type_name = cls.type_name()
|
||||||
if self.config.get(f"welcome::tasks::{type_name}::enabled"):
|
if self.config.get(f"welcome::tasks::{type_name}::enabled"):
|
||||||
|
log(f"Task {cls.type_name()} enabled")
|
||||||
self.available_tasks.append(cls)
|
self.available_tasks.append(cls)
|
||||||
|
|
||||||
self.max_attempts = self.config.get("welcome::max_attempts")
|
self.max_attempts = self.config.get("welcome::max_attempts")
|
||||||
@ -65,6 +67,7 @@ class TaskManager:
|
|||||||
|
|
||||||
|
|
||||||
verification_tasks = MultiKeyDict()
|
verification_tasks = MultiKeyDict()
|
||||||
|
last_success = {}
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ocab_modules.standard.config import IConfig
|
from ocab_modules.standard.config import IConfig
|
||||||
@ -117,8 +120,15 @@ async def success_end(task: BaseTask):
|
|||||||
|
|
||||||
await asyncio.sleep(3)
|
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"):
|
if config.get("welcome::show_success_message"):
|
||||||
await task.bot.send_message(
|
message = await task.bot.send_message(
|
||||||
task.from_chat_id,
|
task.from_chat_id,
|
||||||
Template(config.get("welcome::success_message")).substitute(
|
Template(config.get("welcome::success_message")).substitute(
|
||||||
mention=user_mention(task.from_user)
|
mention=user_mention(task.from_user)
|
||||||
@ -126,6 +136,8 @@ async def success_end(task: BaseTask):
|
|||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
last_success[task.from_chat_id] = message.message_id
|
||||||
|
|
||||||
|
|
||||||
async def handle_poll_verification(answer: PollAnswer, bot: Bot):
|
async def handle_poll_verification(answer: PollAnswer, bot: Bot):
|
||||||
key = key_from_poll(answer.poll_id)
|
key = key_from_poll(answer.poll_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user