1
Fork 0
mirror of https://github.com/allthingslinux/tux.git synced 2024-10-03 00:53:12 +00:00

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
This commit is contained in:
kzndotsh 2024-08-22 02:56:54 +00:00
parent c2cca276bd
commit 76593ac7b5
2 changed files with 17 additions and 16 deletions

View file

@ -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})",
}

14
tux/utils/exceptions.py Normal file
View file

@ -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}")