2023-07-30 13:00:24 +05:30
|
|
|
import asyncio
|
2023-07-09 22:11:45 +05:30
|
|
|
import traceback
|
2023-07-30 13:00:24 +05:30
|
|
|
|
2023-07-09 22:11:45 +05:30
|
|
|
from app import Config, bot
|
|
|
|
from app.core import filters
|
|
|
|
from app.core.MediaHandler import ExtractAndSendMedia
|
|
|
|
from app.core.message import Message
|
|
|
|
|
|
|
|
|
|
|
|
@bot.add_cmd(cmd="dl")
|
|
|
|
async def dl(bot, message):
|
2023-07-30 13:00:24 +05:30
|
|
|
reply = await bot.send_message(
|
|
|
|
chat_id=message.chat.id, text="`trying to download...`"
|
|
|
|
)
|
2023-07-31 15:53:06 +05:30
|
|
|
coro = ExtractAndSendMedia.process(message)
|
2023-08-03 09:30:19 +05:30
|
|
|
task = asyncio.Task(coro, name=message.task_id)
|
2023-07-30 13:00:24 +05:30
|
|
|
media = await task
|
2023-07-09 22:11:45 +05:30
|
|
|
if media.exceptions:
|
|
|
|
exceptions = "\n".join(media.exceptions)
|
2023-07-30 13:00:24 +05:30
|
|
|
await bot.log(
|
2023-07-31 15:53:06 +05:30
|
|
|
traceback=exceptions,
|
2023-07-30 13:00:24 +05:30
|
|
|
func="DL",
|
|
|
|
chat=message.chat.title or message.chat.first_name,
|
|
|
|
name="traceback.txt",
|
|
|
|
)
|
2023-07-09 22:11:45 +05:30
|
|
|
return await reply.edit(f"Media Download Failed.")
|
|
|
|
if media.media_objects:
|
|
|
|
await message.delete()
|
|
|
|
await reply.delete()
|
|
|
|
|
|
|
|
|
|
|
|
@bot.on_message(filters.user_filter)
|
|
|
|
@bot.on_edited_message(filters.user_filter)
|
|
|
|
async def cmd_dispatcher(bot, message):
|
2023-08-03 09:30:19 +05:30
|
|
|
message = Message.parse_message(message)
|
|
|
|
func = Config.CMD_DICT[message.cmd]
|
|
|
|
coro = func(bot, message)
|
2023-07-09 22:11:45 +05:30
|
|
|
try:
|
2023-08-03 09:30:19 +05:30
|
|
|
task = asyncio.Task(coro, name=message.task_id)
|
2023-07-30 13:00:24 +05:30
|
|
|
await task
|
|
|
|
except asyncio.exceptions.CancelledError:
|
2023-07-31 15:53:06 +05:30
|
|
|
await bot.log(text=f"<b>#Cancelled</b>:\n<code>{message.text}</code>")
|
2023-07-09 22:11:45 +05:30
|
|
|
except BaseException:
|
2023-07-30 13:00:24 +05:30
|
|
|
await bot.log(
|
2023-07-31 15:53:06 +05:30
|
|
|
traceback=str(traceback.format_exc()),
|
2023-07-30 13:00:24 +05:30
|
|
|
chat=message.chat.title or message.chat.first_name,
|
|
|
|
func=func.__name__,
|
|
|
|
name="traceback.txt",
|
|
|
|
)
|
2023-07-09 22:11:45 +05:30
|
|
|
|
|
|
|
|
|
|
|
@bot.on_message(filters.chat_filter)
|
|
|
|
async def dl_dispatcher(bot, message):
|
2023-08-03 09:30:19 +05:30
|
|
|
message = Message.parse_message(message)
|
|
|
|
coro = dl(bot, message)
|
2023-07-09 22:11:45 +05:30
|
|
|
try:
|
2023-08-03 09:30:19 +05:30
|
|
|
task = asyncio.Task(coro, name=message.task_id)
|
2023-07-30 13:00:24 +05:30
|
|
|
await task
|
|
|
|
except asyncio.exceptions.CancelledError:
|
2023-07-31 15:53:06 +05:30
|
|
|
await bot.log(text=f"<b>#Cancelled</b>:\n<code>{message.text}</code>")
|
2023-07-09 22:11:45 +05:30
|
|
|
except BaseException:
|
2023-07-30 13:00:24 +05:30
|
|
|
await bot.log(
|
2023-07-31 15:53:06 +05:30
|
|
|
traceback=str(traceback.format_exc()),
|
2023-07-30 13:00:24 +05:30
|
|
|
chat=message.chat.title or message.chat.first_name,
|
|
|
|
func=dl.__name__,
|
|
|
|
name="traceback.txt",
|
|
|
|
)
|