yt-dlp-bot/bot/core/callbacks.py

28 lines
936 B
Python
Raw Normal View History

2022-02-04 06:21:27 +08:00
import logging
2022-06-11 04:35:48 +08:00
from pyrogram import Client
from pyrogram.enums import ParseMode
from pyrogram.types import Message
2022-02-04 06:21:27 +08:00
2022-06-11 04:35:48 +08:00
from core.service import URLService
from core.utils import bold
2022-02-04 06:21:27 +08:00
from yt_shared.emoji import SUCCESS_EMOJI
class TelegramCallback:
_MSG_SEND_OK = f'{SUCCESS_EMOJI} {bold("URL sent for download")}'
_MSG_SEND_FAIL = f'🛑 {bold("Failed to send URL for download")}'
def __init__(self) -> None:
self._log = logging.getLogger(self.__class__.__name__)
2022-06-11 04:35:48 +08:00
self._url_service = URLService()
2022-02-04 06:21:27 +08:00
2022-06-11 04:35:48 +08:00
async def on_message(self, client: Client, message: Message) -> None:
2022-02-04 06:21:27 +08:00
"""Receive video URL and send to the download worker."""
2022-06-11 04:35:48 +08:00
is_sent = await self._url_service.process_url(message.text, message.id)
2022-02-04 06:21:27 +08:00
await message.reply(
self._MSG_SEND_OK if is_sent else self._MSG_SEND_FAIL,
2022-06-11 04:35:48 +08:00
parse_mode=ParseMode.HTML,
reply_to_message_id=message.id,
)