Last active
July 13, 2022 11:08
-
-
Save hikariatama/e340bd1b41d65715d3b0a198b0af47d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .. import loader, utils | |
import telethon | |
import asyncio | |
import logging | |
class MusicDL_Lib(loader.Library): | |
async def dl(self, full_name: str) -> bytes: | |
try: | |
q = await self._client.inline_query("@losslessrobot", full_name) | |
result = q.result.results[0] | |
if not getattr(getattr(result, "send_message", None), "reply_markup", None): | |
return await self._client.download_file(result.document, bytes) | |
m = await q[0].click("me") | |
dl_event = asyncio.Event() | |
dl_file = None | |
@self._client.on(telethon.events.MessageEdited(chats=utils.get_chat_id(m))) | |
async def handler(event: telethon.events.MessageEdited): | |
nonlocal dl_file | |
if ( | |
event.message.id == m.id | |
and not getattr(event.message, "reply_markup", None) | |
and event.message.document | |
): | |
dl_file = await self._client.download_file( | |
event.message.document, bytes | |
) | |
dl_event.set() | |
raise telethon.events.StopPropagation | |
await asyncio.wait_for(dl_event.wait(), timeout=40) | |
return dl_file | |
except Exception: | |
logging.exception("Can't download") | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment