upload bug fixes and logs.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ down*
|
||||
__pycache__
|
||||
.idea/
|
||||
conf_backup/
|
||||
logs/
|
||||
|
||||
@@ -5,6 +5,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv("config.env")
|
||||
|
||||
from app.config import Config # NOQA
|
||||
from app.core import LOGGER # NOQA
|
||||
from app.core.db import DB # NOQA
|
||||
from app.core.client.client import BOT # NOQA
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from app.core.client import filters
|
||||
from app.core.logger import LOGGER
|
||||
from app.core.types.callback_query import CallbackQuery
|
||||
|
||||
from app.core.client.conversation import Conversation # NOQA
|
||||
|
||||
@@ -13,18 +13,18 @@ from pyrogram.types import Message as Msg
|
||||
from telegraph.aio import Telegraph
|
||||
|
||||
from app import DB, Config
|
||||
from app.core import Conversation, Message
|
||||
from app.core import Conversation, Message, logger
|
||||
from app.utils import aiohttp_tools, helpers
|
||||
|
||||
|
||||
def import_modules():
|
||||
for py_module in glob.glob(pathname="app/**/*.py", recursive=True):
|
||||
for py_module in glob.glob(pathname="app/**/[!^_]*.py", recursive=True):
|
||||
name = os.path.splitext(py_module)[0]
|
||||
py_name = name.replace("/", ".")
|
||||
try:
|
||||
importlib.import_module(py_name)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
except Exception as exc:
|
||||
logger.LOGGER.error(exc.with_exception())
|
||||
|
||||
|
||||
async def init_tasks():
|
||||
@@ -91,7 +91,7 @@ class BOT(Client):
|
||||
|
||||
async def boot(self) -> None:
|
||||
await super().start()
|
||||
print("started")
|
||||
logger.LOGGER.info("Started")
|
||||
await asyncio.gather(
|
||||
init_tasks(), self.edit_restart_msg(), self.log(text="<i>Started</i>")
|
||||
)
|
||||
@@ -124,12 +124,13 @@ class BOT(Client):
|
||||
if message:
|
||||
return (await message.copy(chat_id=Config.LOG_CHAT)) # fmt: skip
|
||||
if traceback:
|
||||
text = f"""
|
||||
#Traceback
|
||||
<b>Function:</b> {func}
|
||||
<b>Chat:</b> {chat}
|
||||
<b>Traceback:</b>
|
||||
<code>{traceback}</code>"""
|
||||
text = (
|
||||
"#Traceback"
|
||||
f"\n<b>Function:</b> {func}"
|
||||
f"\n<b>Chat:</b> {chat}"
|
||||
f"\n<b>Traceback:</b>"
|
||||
f"\n<code>{traceback}</code>"
|
||||
)
|
||||
return await self.send_message(
|
||||
chat_id=Config.LOG_CHAT,
|
||||
text=text,
|
||||
|
||||
24
app/core/logger.py
Normal file
24
app/core/logger.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
from logging import INFO, WARNING, basicConfig, getLogger, handlers
|
||||
|
||||
os.makedirs("logs", exist_ok=True)
|
||||
|
||||
LOGGER = getLogger("PLAIN_UB")
|
||||
|
||||
basicConfig(
|
||||
level=INFO,
|
||||
format="[%(asctime)s] [%(levelname)s] [%(name)s]: %(message)s",
|
||||
datefmt="%y-%m-%d %H:%M:%S",
|
||||
handlers={
|
||||
handlers.RotatingFileHandler(
|
||||
filename="logs/app_logs.txt",
|
||||
mode="a",
|
||||
maxBytes=5 * 1024 * 1024,
|
||||
backupCount=2,
|
||||
encoding=None,
|
||||
delay=0,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
getLogger("pyrogram").setLevel(WARNING)
|
||||
@@ -14,14 +14,14 @@ async def video_upload(
|
||||
file: DownloadedFile, has_spoiler: bool
|
||||
) -> dict[str, bot.send_video, bot.send_animation, dict]:
|
||||
thumb = await take_ss(file.full_path)
|
||||
if not check_audio(file.full_path):
|
||||
if not (await check_audio(file.full_path)): # fmt:skip
|
||||
return {
|
||||
"method": bot.send_animation,
|
||||
"kwargs": {
|
||||
"thumb": thumb,
|
||||
"unsave": True,
|
||||
"animation": file.full_path,
|
||||
"duration": get_duration(file.full_path),
|
||||
"duration": await get_duration(file.full_path),
|
||||
"has_spoiler": has_spoiler,
|
||||
},
|
||||
}
|
||||
@@ -30,7 +30,7 @@ async def video_upload(
|
||||
"kwargs": {
|
||||
"thumb": thumb,
|
||||
"video": file.full_path,
|
||||
"duration": get_duration(file.full_path),
|
||||
"duration": await get_duration(file.full_path),
|
||||
"has_spoiler": has_spoiler,
|
||||
},
|
||||
}
|
||||
@@ -52,7 +52,7 @@ async def audio_upload(
|
||||
"method": bot.send_audio,
|
||||
"kwargs": {
|
||||
"audio": file.full_path,
|
||||
"duration": get_duration(file=file.full_path),
|
||||
"duration": await get_duration(file=file.full_path),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -120,12 +120,7 @@ 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,
|
||||
|
||||
14
app/plugins/utils/logs.py
Normal file
14
app/plugins/utils/logs.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import aiofiles
|
||||
|
||||
from app import BOT, bot
|
||||
from app.core import Message
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="logs")
|
||||
async def read_logs(bot: BOT, message: Message):
|
||||
async with aiofiles.open("logs/app_logs.txt", "r") as aio_file:
|
||||
text = await aio_file.read()
|
||||
if len(text) < 4050:
|
||||
await message.reply(f"<pre language=bash>{text}</pre>")
|
||||
else:
|
||||
await message.reply_document(document="logs/app_logs.txt")
|
||||
Reference in New Issue
Block a user