.upload ready and supports plugin upload now.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import glob
|
||||
import importlib
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
from functools import wraps
|
||||
@@ -58,16 +59,18 @@ class BOT(Client):
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def add_cmd(cmd: str):
|
||||
def add_cmd(cmd: str | list):
|
||||
def the_decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper():
|
||||
config_dict = Config.CMD_DICT
|
||||
if isinstance(cmd, list):
|
||||
for _cmd in cmd:
|
||||
config_dict[_cmd] = func
|
||||
Config.CMD_DICT[_cmd] = {
|
||||
"func": func,
|
||||
"path": inspect.stack()[1][1],
|
||||
}
|
||||
else:
|
||||
config_dict[cmd] = func
|
||||
Config.CMD_DICT[cmd] = {"func": func, "path": inspect.stack()[1][1]}
|
||||
|
||||
wrapper()
|
||||
return func
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.core import Message, filters
|
||||
@bot.on_edited_message(filters.owner_filter | filters.sudo_filter, group=1)
|
||||
async def cmd_dispatcher(bot, message) -> None:
|
||||
message = Message.parse_message(message)
|
||||
func = Config.CMD_DICT[message.cmd]
|
||||
func = Config.CMD_DICT[message.cmd]["func"]
|
||||
coro = func(bot, message)
|
||||
x = await run_coro(coro, message)
|
||||
if not x and message.is_from_owner:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from app import BOT, bot
|
||||
from app import BOT, bot, Config
|
||||
from app.core import Message
|
||||
from app.utils.downloader import Download, DownloadedFile
|
||||
from app.utils.helpers import progress
|
||||
@@ -20,7 +20,7 @@ async def video_upload(
|
||||
"thumb": thumb,
|
||||
"unsave": True,
|
||||
"animation": file.full_path,
|
||||
"duration": get_duration(file.path),
|
||||
"duration": get_duration(file.full_path),
|
||||
"has_spoiler": has_spoiler,
|
||||
},
|
||||
}
|
||||
@@ -29,7 +29,7 @@ async def video_upload(
|
||||
"kwargs": {
|
||||
"thumb": thumb,
|
||||
"video": file.full_path,
|
||||
"duration": get_duration(file.path),
|
||||
"duration": get_duration(file.full_path),
|
||||
"has_spoiler": has_spoiler,
|
||||
},
|
||||
}
|
||||
@@ -85,16 +85,17 @@ async def upload(bot: BOT, message: Message):
|
||||
await message.reply("give a file url | path to upload.")
|
||||
return
|
||||
response = await message.reply("checking input...")
|
||||
if input.startswith("http") and not file_check(input):
|
||||
try:
|
||||
dl_obj: Download = await Download.setup(
|
||||
url=message.input,
|
||||
path=os.path.join("downloads", str(time.time())),
|
||||
message_to_edit=response,
|
||||
)
|
||||
file: DownloadedFile = await dl_obj.download()
|
||||
except Download.DuplicateDownload:
|
||||
file: DownloadFile = dl_obj.return_file()
|
||||
if input in Config.CMD_DICT:
|
||||
await message.reply_document(document=Config.CMD_DICT[input]["path"])
|
||||
await response.delete()
|
||||
return
|
||||
elif input.startswith("http") and not file_check(input):
|
||||
dl_obj: Download = await Download.setup(
|
||||
url=message.input,
|
||||
path=os.path.join("downloads", str(time.time())),
|
||||
message_to_edit=response,
|
||||
)
|
||||
file: DownloadedFile = await dl_obj.download()
|
||||
elif file_check(input):
|
||||
file = DownloadedFile(
|
||||
name=input,
|
||||
@@ -103,7 +104,7 @@ async def upload(bot: BOT, message: Message):
|
||||
size=bytes_to_mb(os.path.getsize(input)),
|
||||
)
|
||||
else:
|
||||
await response.edit("invalid url | file path!!!")
|
||||
await response.edit("invalid `cmd` | `url` | `file path`!!!")
|
||||
return
|
||||
await response.edit("uploading....")
|
||||
progress_args = (response, "Uploading...", file.name, file.full_path)
|
||||
|
||||
Reference in New Issue
Block a user