From 76593ac7b5afa28a855c9a7fa7c207b8a7c4828a Mon Sep 17 00:00:00 2001 From: kzndotsh Date: Thu, 22 Aug 2024 02:56:54 +0000 Subject: [PATCH] refactor(error.py, exceptions.py): move custom exceptions to a separate file for better code organization fix(error.py): update error_map to import exceptions from new location to maintain functionality --- tux/handlers/error.py | 19 +++---------------- tux/utils/exceptions.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 tux/utils/exceptions.py diff --git a/tux/handlers/error.py b/tux/handlers/error.py index e37a3f5..089c64d 100644 --- a/tux/handlers/error.py +++ b/tux/handlers/error.py @@ -6,21 +6,8 @@ from discord import app_commands from discord.ext import commands from loguru import logger -import tux.handlers.error as error from tux.utils.embeds import create_error_embed - - -class PermissionLevelError(commands.CheckFailure): - def __init__(self, permission: str) -> None: - self.permission = permission - super().__init__(f"User does not have the required permission: {permission}") - - -class AppCommandPermissionLevelError(app_commands.CheckFailure): - def __init__(self, permission: str) -> None: - self.permission = permission - super().__init__(f"User does not have the required permission: {permission}") - +from tux.utils.exceptions import AppCommandPermissionLevelError, PermissionLevelError error_map: dict[type[Exception], str] = { # app_commands @@ -51,8 +38,8 @@ error_map: dict[type[Exception], str] = { commands.NotOwner: "User not in sudoers file. This incident will be reported. (Not Owner)", commands.BotMissingPermissions: "User not in sudoers file. This incident will be reported. (Bot Missing Permissions)", # Custom errors - error.PermissionLevelError: "User not in sudoers file. This incident will be reported. (Missing required permission: {error.permission})", - error.AppCommandPermissionLevelError: "User not in sudoers file. This incident will be reported. (Missing required permission: {error.permission})", + PermissionLevelError: "User not in sudoers file. This incident will be reported. (Missing required permission: {error.permission})", + AppCommandPermissionLevelError: "User not in sudoers file. This incident will be reported. (Missing required permission: {error.permission})", } diff --git a/tux/utils/exceptions.py b/tux/utils/exceptions.py new file mode 100644 index 0000000..d84b4e5 --- /dev/null +++ b/tux/utils/exceptions.py @@ -0,0 +1,14 @@ +from discord import app_commands +from discord.ext import commands + + +class PermissionLevelError(commands.CheckFailure): + def __init__(self, permission: str) -> None: + self.permission = permission + super().__init__(f"User does not have the required permission: {permission}") + + +class AppCommandPermissionLevelError(app_commands.CheckFailure): + def __init__(self, permission: str) -> None: + self.permission = permission + super().__init__(f"User does not have the required permission: {permission}")