mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-25 02:55:49 +01:00
ad8f0b2700
1 internal commit(s) GitOrigin-RevId: 8bba552568b30f42662051baa2cb2fb088361b96
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import asyncio
|
|
import re
|
|
|
|
from library.telegram.base import RequestContext
|
|
from telethon import events
|
|
|
|
from .base import BaseHandler
|
|
|
|
|
|
class RollHandler(BaseHandler):
|
|
filter = events.NewMessage(incoming=True, pattern=re.compile('^/roll(@[A-Za-z0-9_]+)?$', re.DOTALL))
|
|
is_group_handler = True
|
|
|
|
async def handler(self, event: events.ChatAction, request_context: RequestContext):
|
|
session_id = self.generate_session_id()
|
|
request_context.add_default_fields(mode='roll', session_id=session_id)
|
|
request_context.statbox(action='show')
|
|
|
|
roll_response_pb = await self.application.meta_api_client.roll(
|
|
language=request_context.chat.language,
|
|
session_id=session_id,
|
|
request_id=request_context.request_id,
|
|
user_id=str(request_context.chat.chat_id),
|
|
)
|
|
scitech_view = await self.resolve_scitech(
|
|
document_id=roll_response_pb.document_id,
|
|
position=0,
|
|
request_context=request_context,
|
|
session_id=session_id,
|
|
)
|
|
view, buttons = scitech_view.get_view(
|
|
language=request_context.chat.language,
|
|
session_id=session_id,
|
|
bot_external_name=self.application.config['telegram']['bot_external_name'],
|
|
)
|
|
actions = [
|
|
self.application.telegram_client.send_message(
|
|
request_context.chat.chat_id,
|
|
view,
|
|
buttons=buttons,
|
|
),
|
|
event.delete(),
|
|
]
|
|
return await asyncio.gather(*actions)
|