fix input bug and catch exceptions up/download.
This commit is contained in:
@@ -105,7 +105,7 @@ async def fed_ban(bot: bot, message: Message):
|
||||
chat_id=chat_id, text=fban_cmd, disable_web_page_preview=True
|
||||
)
|
||||
response: Message | None = await cmd.get_response(filters=FILTERS, timeout=8)
|
||||
if not response or not (await FBAN_REGEX(bot, response)):
|
||||
if not response or not (await FBAN_REGEX(bot, response)): # NOQA
|
||||
failed.append(fed["name"])
|
||||
elif "Would you like to update this reason" in response.text:
|
||||
await response.click("Update reason")
|
||||
@@ -113,7 +113,7 @@ async def fed_ban(bot: bot, message: Message):
|
||||
if not total:
|
||||
await progress.edit("You Don't have any feds connected!")
|
||||
return
|
||||
resp_str = f"❯❯❯ <b>FBanned</b> {user.mention}\n<b>ID</b>: {user.id}\n<b>Reason</b>: {reason}\n<b>Initiated in</b>:{message.chat.title or 'PM'}"
|
||||
resp_str = f"❯❯❯ <b>FBanned</b> {user.mention}\n<b>ID</b>: {user.id}\n<b>Reason</b>: {reason}\n<b>Initiated in</b>: {message.chat.title or 'PM'}"
|
||||
if failed:
|
||||
resp_str += f"\n<b>Failed</b> in: {len(failed)}/{total}\n• " + "\n• ".join(
|
||||
failed
|
||||
|
||||
@@ -19,15 +19,16 @@ async def down_load(bot: BOT, message: Message):
|
||||
dl_path = os.path.join("downloads", str(time.time()))
|
||||
await response.edit("Input verified....Starting Download...")
|
||||
if message.replied and message.replied.media:
|
||||
downloaded_file: DownloadedFile = await telegram_download(
|
||||
download_coro = telegram_download(
|
||||
message=message.replied, response=response, path=dl_path
|
||||
)
|
||||
else:
|
||||
dl_obj: Download = await Download.setup(
|
||||
url=message.input, path=dl_path, message_to_edit=response
|
||||
)
|
||||
downloaded_file: DownloadedFile = await dl_obj.download()
|
||||
|
||||
download_coro = dl_obj.download()
|
||||
try:
|
||||
downloaded_file: DownloadedFile = await download_coro
|
||||
await response.edit(
|
||||
f"<b>Download Completed</b>"
|
||||
f"\n<pre language=bash>"
|
||||
@@ -37,6 +38,13 @@ async def down_load(bot: BOT, message: Message):
|
||||
)
|
||||
return downloaded_file
|
||||
|
||||
except asyncio.exceptions.CancelledError:
|
||||
await response.edit("Cancelled....")
|
||||
except TimeoutError:
|
||||
await response.edit("Download Timeout...")
|
||||
except Exception as e:
|
||||
await response.edit(str(e))
|
||||
|
||||
|
||||
async def telegram_download(
|
||||
message: Message, response: Message, path: str
|
||||
@@ -54,6 +62,6 @@ async def telegram_download(
|
||||
media_obj.name,
|
||||
media_obj.full_path)
|
||||
await message.download(
|
||||
file_name=media_obj.full_path, progress=progress, progress_args=progress_args
|
||||
file_name=media_obj.full_path, progress=progress, progress_args=progress_args,
|
||||
)
|
||||
return media_obj
|
||||
|
||||
@@ -91,11 +91,18 @@ async def upload(bot: BOT, message: Message):
|
||||
return
|
||||
elif input.startswith("http") and not file_check(input):
|
||||
dl_obj: Download = await Download.setup(
|
||||
url=message.input,
|
||||
url=input,
|
||||
path=os.path.join("downloads", str(time.time())),
|
||||
message_to_edit=response,
|
||||
)
|
||||
try:
|
||||
file: DownloadedFile = await dl_obj.download()
|
||||
except asyncio.exceptions.CancelledError:
|
||||
await response.edit("Cancelled...")
|
||||
return
|
||||
except TimeoutError:
|
||||
await response.edit("Download Timeout...")
|
||||
return
|
||||
elif file_check(input):
|
||||
file = DownloadedFile(
|
||||
name=input,
|
||||
@@ -107,16 +114,25 @@ async def upload(bot: BOT, message: Message):
|
||||
await response.edit("invalid `cmd` | `url` | `file path`!!!")
|
||||
return
|
||||
await response.edit("uploading....")
|
||||
progress_args = (response, "Uploading...", file.name, file.full_path)
|
||||
progress_args = (
|
||||
response,
|
||||
"Uploading...",
|
||||
file.name,
|
||||
file.full_path,
|
||||
)
|
||||
if "-d" in message.flags:
|
||||
media: dict = {
|
||||
"method": bot.send_document,
|
||||
"kwargs": {"document": file.full_path, "force_document": True},
|
||||
"kwargs": {
|
||||
"document": file.full_path,
|
||||
"force_document": True,
|
||||
},
|
||||
}
|
||||
else:
|
||||
media: dict = await FILE_TYPE_MAP[file.type](
|
||||
file, has_spoiler="-s" in message.flags
|
||||
)
|
||||
try:
|
||||
await media["method"](
|
||||
chat_id=message.chat.id,
|
||||
reply_to_message_id=message.reply_id,
|
||||
@@ -125,3 +141,5 @@ async def upload(bot: BOT, message: Message):
|
||||
**media["kwargs"]
|
||||
)
|
||||
await response.delete()
|
||||
except asyncio.exceptions.CancelledError:
|
||||
await response.edit("Cancelled....")
|
||||
|
||||
Reference in New Issue
Block a user