mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-13 13:17:48 +01:00
9ce67ec590
- feat(idm): Rename IDM-2 to IDM - feat(idm): Open IDM 3 internal commit(s) GitOrigin-RevId: e302e9b5cda18cca1adc4ae8a3d906714d222106
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=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)
|