hyperboria/nexus/bot/handlers/close.py
the-superpirate 681817ceae No description
GitOrigin-RevId: 83514338be1d662518bab9fe5ab6eefef98f229f
2021-04-09 13:29:10 +03:00

32 lines
1.0 KiB
Python

import asyncio
from library.telegram.base import RequestContext
from telethon import events
from .base import BaseCallbackQueryHandler
class CloseHandler(BaseCallbackQueryHandler):
filter = events.CallbackQuery(pattern='^/close(?:_([A-Za-z0-9]+))?(?:_([0-9]+))?$')
async def handler(self, event, request_context: RequestContext):
session_id = event.pattern_match.group(1)
if session_id:
session_id = session_id.decode()
request_context.add_default_fields(mode='close')
target_events = [event.answer()]
message = await event.get_message()
if message:
request_context.statbox(
action='close',
message_id=message.id,
session_id=session_id,
)
reply_message = await message.get_reply_message()
if reply_message:
target_events.append(reply_message.delete())
target_events.append(message.delete())
await asyncio.gather(*target_events)