a2c71a49f2
- Consolidated and simplified code formatting by removing unnecessary line breaks and improving readability in various functions. - Updated the handling of backup file sending in backup.py for better clarity. - Streamlined error handling and logging messages in several handlers to enhance consistency. - Adjusted the Makefile to exclude specific files during Ruff checks and formatting. - Made minor adjustments to function signatures and parameter handling for improved clarity and consistency. This commit enhances code maintainability and readability without altering functionality.
27 lines
984 B
Python
27 lines
984 B
Python
from collections.abc import Awaitable, Callable
|
|
from typing import Any
|
|
|
|
from aiogram import BaseMiddleware
|
|
from aiogram.types import CallbackQuery, Message, TelegramObject
|
|
|
|
|
|
class DeleteMessageMiddleware(BaseMiddleware):
|
|
async def __call__(
|
|
self,
|
|
handler: Callable[[TelegramObject, dict[str, Any]], Awaitable[Any]],
|
|
event: TelegramObject,
|
|
data: dict[str, Any],
|
|
) -> Any:
|
|
if isinstance(event, (Message, CallbackQuery)):
|
|
if isinstance(event, Message):
|
|
if not event.text or not event.text.startswith("/start"):
|
|
try:
|
|
await event.bot.delete_message(event.chat.id, event.message_id - 1)
|
|
except Exception:
|
|
pass
|
|
await event.delete()
|
|
elif isinstance(event, CallbackQuery):
|
|
await event.answer()
|
|
await event.message.delete()
|
|
return await handler(event, data)
|