Improved logging

This commit is contained in:
Profitroll 2023-03-17 14:13:28 +01:00
parent 95351f247c
commit 717586a9f0
3 changed files with 39 additions and 1 deletions

View File

@ -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', 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}"}, 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: if resp.status != 200:
logWrite( logWrite(
f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status}' f'Could not get photos from album {configGet("album", "posting", "api")}: HTTP {resp.status}'

View File

@ -7,6 +7,7 @@ from classes.poster_client import PosterClient
from classes.user import PosterUser from classes.user import PosterUser
from modules.app import app from modules.app import app
from modules.logger import logWrite
from modules.utils import configGet, locale from modules.utils import configGet, locale
from modules.database import col_submitted from modules.database import col_submitted
from bson import ObjectId from bson import ObjectId
@ -38,6 +39,10 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
), ),
quote=True, quote=True,
) )
logWrite(
f"Submission with ID '{fullclb[2]}' could not be accepted because of the duplicates: {str(exp.duplicates)}",
debug=True,
)
return return
if submission[0] is not None: if submission[0] is not None:
@ -83,6 +88,11 @@ async def callback_query_yes(app: PosterClient, clb: CallbackQuery):
reply_markup=InlineKeyboardMarkup(edited_markup) reply_markup=InlineKeyboardMarkup(edited_markup)
) )
logWrite(
f"Submission with ID '{fullclb[2]}' accepted and uploaded with ID '{submission[1]}'",
debug=True,
)
# try: # try:
# if configGet("api_based", "mode") is True: # if configGet("api_based", "mode") is True:
# media = await app.download_media(submission, file_name=configGet("tmp", "locations")+sep) # 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( await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_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]*")) @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( await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_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]*")) @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( await clb.message.edit_reply_markup(
reply_markup=InlineKeyboardMarkup(edited_markup) reply_markup=InlineKeyboardMarkup(edited_markup)
) )
logWrite(
f"User {fullclb[2]} has been unblocked",
debug=True,
)

View File

@ -43,6 +43,10 @@ async def get_submission(app: PosterClient, msg: Message):
return return
if msg.document is not None: 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"): if msg.document.mime_type not in configGet("mime_types", "submission"):
await msg.reply_text( await msg.reply_text(
locale("mime_not_allowed", "message", locale=user_locale), locale("mime_not_allowed", "message", locale=user_locale),
@ -65,6 +69,10 @@ async def get_submission(app: PosterClient, msg: Message):
) # , msg.document.file_name ) # , msg.document.file_name
if msg.video is not None: 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"): if msg.video.file_size > configGet("file_size", "submission"):
await msg.reply_text( await msg.reply_text(
locale("document_too_large", "message", locale=user_locale).format( 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 contents = msg.video.file_id, SubmissionType.VIDEO # , msg.video.file_name
if msg.animation is not None: 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"): if msg.animation.file_size > configGet("file_size", "submission"):
await msg.reply_text( await msg.reply_text(
locale("document_too_large", "message", locale=user_locale).format( 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 ) # , msg.animation.file_name
if msg.photo is not None: 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" contents = msg.photo.file_id, SubmissionType.PHOTO # , "please_generate"
if save_tmp is not None: if save_tmp is not None: