mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-11-19 01:39:26 +01:00
681817ceae
GitOrigin-RevId: 83514338be1d662518bab9fe5ab6eefef98f229f
32 lines
1.0 KiB
Python
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)
|