mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-02 16:02:53 +01:00
681817ceae
GitOrigin-RevId: 83514338be1d662518bab9fe5ab6eefef98f229f
26 lines
920 B
Python
26 lines
920 B
Python
from library.telegram.base import RequestContext
|
|
from nexus.translations import t
|
|
from nexus.views.telegram.common import (
|
|
TooLongQueryError,
|
|
encode_query_to_deep_link,
|
|
)
|
|
from telethon import events
|
|
|
|
from .base import BaseHandler
|
|
|
|
|
|
class ShortlinkHandler(BaseHandler):
|
|
filter = events.NewMessage(incoming=True, pattern='^/shortlink\\s?(.*)?')
|
|
|
|
async def handler(self, event: events.ChatAction, request_context: RequestContext):
|
|
query = event.pattern_match.group(1)
|
|
request_context.statbox(action='start', mode='shortlink', query=query)
|
|
|
|
try:
|
|
bot_name = self.application.config["telegram"]["bot_external_name"]
|
|
text = encode_query_to_deep_link(query, bot_name)
|
|
except TooLongQueryError:
|
|
text = t('TOO_LONG_QUERY_FOR_SHORTLINK', language=request_context.chat.language),
|
|
|
|
return await event.reply(f'`{text}`', link_preview=False)
|