Changed the way exceptions are handled

This commit is contained in:
Profitroll
2023-02-17 16:45:51 +01:00
parent 663a7b0db8
commit 07203a9db9
4 changed files with 46 additions and 3 deletions

View File

@@ -1,10 +1,12 @@
from datetime import datetime, timezone
from os import makedirs, path, sep
from traceback import format_exc
from uuid import uuid4
from pyrogram import filters
from pyrogram.client import Client
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
from classes.exceptions import SubmissionDuplicatesError
from modules.app import app
from modules.database import col_banned, col_submitted
@@ -141,6 +143,30 @@ async def get_submission(_: Client, msg: Message):
if msg.from_user.phone_number is not None:
caption += f" ({msg.from_user.phone_number})"
if msg.from_user.id == configGet("admin") and configGet("admins", "submission", "require_confirmation") is False:
try:
await app.submit_photo(str(inserted.inserted_id))
await msg.copy(configGet("admin"), caption=caption)
return
except SubmissionDuplicatesError as exp:
await msg.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n".join(exp.duplicates)))
return
except Exception as exp:
await msg.reply_text(format_exc())
return
elif msg.from_user.id != configGet("admin") and configGet("users", "submission", "require_confirmation") is False:
try:
await app.submit_photo(str(inserted.inserted_id))
await msg.copy(configGet("admin"), caption=caption)
return
except SubmissionDuplicatesError as exp:
await msg.reply_text(locale("sub_media_duplicates_list", "message", locale=user_locale).format("\n".join(exp.duplicates)))
return
except Exception as exp:
await app.send_message(configGet("admin"), f"User {msg.from_user.id} could not submit photo without additional confirmation due to:\n```\n{format_exc()}\n```")
await msg.reply_text("Could not upload this image. Admins are advised.")
return
if msg.from_user.id != configGet("admin"):
buttons += [
[