diff --git a/classes/errors/holo_user.py b/classes/errors/holo_user.py new file mode 100644 index 0000000..a4fbb6b --- /dev/null +++ b/classes/errors/holo_user.py @@ -0,0 +1,24 @@ +"""Exceptions that are meant to be used by HoloUser class +and other modules that handle those exceptions""" + +class UserNotFoundError(Exception): + """HoloUser could not find user with such an ID in database""" + def __init__(self, user, user_id): + self.user = user + self.user_id = user_id + super().__init__(f"User of type {type(self.user)} with id {self.user_id} was not found") + +class UserInvalidError(Exception): + """Provided to HoloUser object is not supported""" + def __init__(self, user): + self.user = user + super().__init__(f"Could not find HoloUser by using {type(self.user)} as an input type") + +class LabelTooLongError(Exception): + def __init__(self, label: str) -> None: + self.label = label + super().__init__(f"Could not set label to '{label}' because it is {len(label)} characters long (16 is maximum)") + +class LabelSettingError(Exception): + def __init__(self, exp: Exception, trace: str) -> None: + super().__init__(f"❌ **Could not set label**\n\nException: `{exp}`\n\n**Traceback:**\n```\n{trace}\n```") \ No newline at end of file diff --git a/classes/holo_user.py b/classes/holo_user.py index 8c9adc1..80e87bf 100644 --- a/classes/holo_user.py +++ b/classes/holo_user.py @@ -6,6 +6,7 @@ from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Phot from pyrogram.errors import bad_request_400 from dateutil.relativedelta import relativedelta from classes.errors.geo import PlaceNotFoundError +from classes.errors.holo_user import UserInvalidError, UserNotFoundError, LabelTooLongError, LabelSettingError from modules.database import col_tmp, col_users, col_applications, col_sponsorships, col_messages, col_spoilers from modules.logging import logWrite from modules.utils import configGet, find_location, locale, should_quote @@ -53,28 +54,6 @@ class DefaultSponsorshipTemp(dict): } } -class UserNotFoundError(Exception): - """HoloUser could not find user with such an ID in database""" - def __init__(self, user, user_id): - self.user = user - self.user_id = user_id - super().__init__(f"User of type {type(self.user)} with id {self.user_id} was not found") - -class UserInvalidError(Exception): - """Provided to HoloUser object is not supported""" - def __init__(self, user): - self.user = user - super().__init__(f"Could not find HoloUser by using {type(self.user)} as an input type") - -class LabelTooLongError(Exception): - def __init__(self, label: str) -> None: - self.label = label - super().__init__(f"Could not set label to '{label}' because it is {len(label)} characters long (16 is maximum)") - -class LabelSettingError(Exception): - def __init__(self, exp: Exception, trace: str) -> None: - super().__init__(f"❌ **Could not set label**\n\nException: `{exp}`\n\n**Traceback:**\n```\n{trace}\n```") - class HoloUser(): """This object represents a user of HoloChecker bot. It is primarily used to interact with a database in a more python-friendly way, diff --git a/modules/callbacks/sponsorship.py b/modules/callbacks/sponsorship.py index 30d5ea1..918135f 100644 --- a/modules/callbacks/sponsorship.py +++ b/modules/callbacks/sponsorship.py @@ -3,7 +3,8 @@ from app import app from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply, CallbackQuery from pyrogram.client import Client from pyrogram import filters -from classes.holo_user import HoloUser, LabelSettingError +from classes.errors.holo_user import LabelSettingError +from classes.holo_user import HoloUser from modules.utils import configGet, locale, logWrite, should_quote from modules.database import col_tmp, col_sponsorships diff --git a/modules/commands/application.py b/modules/commands/application.py index b1d429a..069c03e 100644 --- a/modules/commands/application.py +++ b/modules/commands/application.py @@ -5,7 +5,8 @@ from pyrogram.enums.parse_mode import ParseMode from pyrogram.types import Message from pyrogram.errors import bad_request_400 from pyrogram.client import Client -from classes.holo_user import HoloUser, UserNotFoundError +from classes.errors.holo_user import UserNotFoundError +from classes.holo_user import HoloUser from modules.utils import logWrite, locale, should_quote from dateutil.relativedelta import relativedelta from modules.database import col_applications diff --git a/modules/commands/identify.py b/modules/commands/identify.py index 953fd42..ad76a0b 100644 --- a/modules/commands/identify.py +++ b/modules/commands/identify.py @@ -5,7 +5,8 @@ from pyrogram.types import Message from pyrogram.client import Client from pyrogram.errors import bad_request_400 from pyrogram.enums.chat_action import ChatAction -from classes.holo_user import HoloUser, UserNotFoundError, UserInvalidError +from classes.errors.holo_user import UserNotFoundError, UserInvalidError +from classes.holo_user import HoloUser from modules.utils import jsonLoad, should_quote, logWrite, locale, download_tmp, create_tmp, find_user from modules import custom_filters diff --git a/modules/commands/label.py b/modules/commands/label.py index f669489..70821b8 100644 --- a/modules/commands/label.py +++ b/modules/commands/label.py @@ -3,7 +3,8 @@ from pyrogram import filters from pyrogram.types import Message from pyrogram.client import Client from modules.utils import configGet, locale, should_quote, find_user -from classes.holo_user import HoloUser, LabelTooLongError, LabelSettingError +from classes.errors.holo_user import LabelTooLongError, LabelSettingError +from classes.holo_user import HoloUser from modules import custom_filters # Label command ================================================================================================================ diff --git a/modules/commands/message.py b/modules/commands/message.py index a2a8205..50c6b0a 100644 --- a/modules/commands/message.py +++ b/modules/commands/message.py @@ -2,7 +2,8 @@ from app import app from pyrogram import filters from pyrogram.types import Message from pyrogram.client import Client -from classes.holo_user import HoloUser, UserInvalidError +from classes.errors.holo_user import UserInvalidError +from classes.holo_user import HoloUser from modules.utils import logWrite, locale, should_quote, find_user from modules import custom_filters diff --git a/modules/commands/spoiler.py b/modules/commands/spoiler.py index 691d8f5..3f0e5e7 100644 --- a/modules/commands/spoiler.py +++ b/modules/commands/spoiler.py @@ -2,7 +2,8 @@ from app import app from pyrogram import filters from pyrogram.types import Message, ReplyKeyboardMarkup from pyrogram.client import Client -from classes.holo_user import HoloUser, UserInvalidError, UserNotFoundError +from classes.errors.holo_user import UserNotFoundError, UserInvalidError +from classes.holo_user import HoloUser from modules.logging import logWrite from modules.utils import locale from modules.database import col_spoilers diff --git a/modules/inline.py b/modules/inline.py index dec4344..d50ec8d 100644 --- a/modules/inline.py +++ b/modules/inline.py @@ -9,7 +9,8 @@ from pyrogram.client import Client from pyrogram.enums.chat_type import ChatType from pyrogram.enums.chat_members_filter import ChatMembersFilter from dateutil.relativedelta import relativedelta -from classes.holo_user import HoloUser, UserInvalidError, UserNotFoundError +from classes.errors.holo_user import UserNotFoundError, UserInvalidError +from classes.holo_user import HoloUser from modules.utils import configGet, locale from modules.database import col_applications, col_spoilers from bson.objectid import ObjectId