mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-02 16:02:53 +01:00
681817ceae
GitOrigin-RevId: 83514338be1d662518bab9fe5ab6eefef98f229f
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
import asyncio
|
|
|
|
from library.telegram.base import RequestContext
|
|
from nexus.bot.exceptions import UnknownFileFormatError
|
|
from nexus.translations import t
|
|
from nexus.views.telegram.common import close_button
|
|
from telethon import events
|
|
|
|
from .base import BaseHandler
|
|
|
|
|
|
class SubmitHandler(BaseHandler):
|
|
filter = events.NewMessage(func=lambda e: e.document, incoming=True)
|
|
is_group_handler = False
|
|
writing_handler = True
|
|
|
|
async def handler(self, event: events.ChatAction, request_context: RequestContext):
|
|
session_id = self.generate_session_id()
|
|
|
|
request_context.add_default_fields(session_id=session_id)
|
|
request_context.statbox(action='show', mode='submit')
|
|
|
|
if event.document.mime_type != 'application/pdf':
|
|
request_context.error_log(UnknownFileFormatError(format=event.document.mime_type))
|
|
return await asyncio.gather(
|
|
event.reply(
|
|
t('UNKNOWN_FILE_FORMAT_ERROR', language=request_context.chat.language),
|
|
buttons=[close_button()],
|
|
),
|
|
event.delete(),
|
|
)
|
|
|
|
return await asyncio.gather(
|
|
self.application.hub_client.submit(
|
|
telegram_document=bytes(event.document),
|
|
telegram_file_id=event.file.id,
|
|
chat=request_context.chat,
|
|
request_id=request_context.request_id,
|
|
session_id=session_id,
|
|
),
|
|
event.delete(),
|
|
)
|