mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-13 13:17:48 +01:00
e877f3e724
- feat(idm): Added monitoring - feat(nexus): Refactor GRPC base client - fix(nexus): Logging fixes - feat(hub): Extend logging - feat(hub): Extend logging 2 internal commit(s) GitOrigin-RevId: 01de4153dd9c0edc2e5954563733085249a4551c
44 lines
1.5 KiB
Python
44 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.statbox(action='unknown_file_format')
|
|
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(),
|
|
)
|