From 717586a9f07f4b481f18961c0f44af878f91a0c3 Mon Sep 17 00:00:00 2001 From: profitroll Date: Fri, 17 Mar 2023 14:13:28 +0100 Subject: [PATCH] Improved logging --- modules/api_client.py | 2 +- plugins/callbacks/submission.py | 22 ++++++++++++++++++++++ plugins/handlers/submission.py | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/modules/api_client.py b/modules/api_client.py index cd8af06..4a6720f 100644 --- a/modules/api_client.py +++ b/modules/api_client.py @@ -78,7 +78,7 @@ async def random_pic(token: Union[str, None] = None) -> Tuple[str, str]: f'{configGet("address", "posting", "api")}/albums/{configGet("album", "posting", "api")}/photos?q=&page_size={configGet("page_size", "posting")}&caption=queue', headers={"Authorization": f"Bearer {token}"}, ) - print(await resp.json(), flush=True) + logWrite("Random pic response: " + str(await resp.json()), debug=True) if resp.status != 200: logWrite( f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status}' diff --git a/plugins/callbacks/submission.py b/plugins/callbacks/submission.py index f182b76..7727f25 100644 --- a/plugins/callbacks/submission.py +++ b/plugins/callbacks/submission.py @@ -7,6 +7,7 @@ from classes.poster_client import PosterClient from classes.user import PosterUser from modules.app import app +from modules.logger import logWrite from modules.utils import configGet, locale from modules.database import col_submitted from bson import ObjectId @@ -38,6 +39,10 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery): ), quote=True, ) + logWrite( + f"Submission with ID '{fullclb[2]}' could not be accepted because of the duplicates: {str(exp.duplicates)}", + debug=True, + ) return if submission[0] is not None: @@ -83,6 +88,11 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery): reply_markup=InlineKeyboardMarkup(edited_markup) ) + logWrite( + f"Submission with ID '{fullclb[2]}' accepted and uploaded with ID '{submission[1]}'", + debug=True, + ) + # try: # if configGet("api_based", "mode") is True: # media = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep) @@ -173,6 +183,10 @@ async def callback_query_no(app: PosterClient, clb: CallbackQuery): await clb.message.edit_reply_markup( reply_markup=InlineKeyboardMarkup(edited_markup) ) + logWrite( + f"Submission with ID '{fullclb[2]}' rejected", + debug=True, + ) @app.on_callback_query(filters.regex("sub_block_[\s\S]*")) @@ -200,6 +214,10 @@ async def callback_query_block(app: PosterClient, clb: CallbackQuery): await clb.message.edit_reply_markup( reply_markup=InlineKeyboardMarkup(edited_markup) ) + logWrite( + f"User {fullclb[2]} has been blocked", + debug=True, + ) @app.on_callback_query(filters.regex("sub_unblock_[\s\S]*")) @@ -227,3 +245,7 @@ async def callback_query_unblock(app: PosterClient, clb: CallbackQuery): await clb.message.edit_reply_markup( reply_markup=InlineKeyboardMarkup(edited_markup) ) + logWrite( + f"User {fullclb[2]} has been unblocked", + debug=True, + ) diff --git a/plugins/handlers/submission.py b/plugins/handlers/submission.py index 112f767..fd06049 100644 --- a/plugins/handlers/submission.py +++ b/plugins/handlers/submission.py @@ -43,6 +43,10 @@ async def get_submission(app: PosterClient, msg: Message): return if msg.document is not None: + logWrite( + f"User {msg.from_user.id} is trying to submit a file of type '{msg.document.mime_type}' with name '{msg.document.file_name}' and size of {msg.document.file_size / 1024 / 1024} MB", + debug=True, + ) if msg.document.mime_type not in configGet("mime_types", "submission"): await msg.reply_text( locale("mime_not_allowed", "message", locale=user_locale), @@ -65,6 +69,10 @@ async def get_submission(app: PosterClient, msg: Message): ) # , msg.document.file_name if msg.video is not None: + logWrite( + f"User {msg.from_user.id} is trying to submit a video with name '{msg.video.file_name}' and size of {msg.video.file_size / 1024 / 1024} MB", + debug=True, + ) if msg.video.file_size > configGet("file_size", "submission"): await msg.reply_text( locale("document_too_large", "message", locale=user_locale).format( @@ -78,6 +86,10 @@ async def get_submission(app: PosterClient, msg: Message): contents = msg.video.file_id, SubmissionType.VIDEO # , msg.video.file_name if msg.animation is not None: + logWrite( + f"User {msg.from_user.id} is trying to submit an animation with name '{msg.animation.file_name}' and size of {msg.animation.file_size / 1024 / 1024} MB", + debug=True, + ) if msg.animation.file_size > configGet("file_size", "submission"): await msg.reply_text( locale("document_too_large", "message", locale=user_locale).format( @@ -94,6 +106,10 @@ async def get_submission(app: PosterClient, msg: Message): ) # , msg.animation.file_name if msg.photo is not None: + logWrite( + f"User {msg.from_user.id} is trying to submit a photo with ID '{msg.photo.file_id}' and size of {msg.photo.file_size / 1024 / 1024} MB", + debug=True, + ) contents = msg.photo.file_id, SubmissionType.PHOTO # , "please_generate" if save_tmp is not None: