Added more custom exceptions and prepared everything for documentation

This commit is contained in:
2025-04-27 12:39:30 +02:00
parent 6b143d8a2d
commit 638658af75
10 changed files with 146 additions and 53 deletions

View File

@@ -1,2 +1,10 @@
from pycord_event import EventNotFoundError
from pycord_event_stage import EventStageNotFoundError, EventStageMissingSequenceError
from .discord import DiscordGuildMemberNotFoundError, DiscordCategoryNotFoundError, DiscordChannelNotFoundError
from .pycord_guild import GuildNotFoundError
from .pycord_user import UserNotFoundError
from .pycord_user import (
UserNotFoundError,
UserAlreadyRegisteredForEventError,
UserNotRegisteredForEventError,
UserAlreadyCompletedEventError,
)

28
classes/errors/discord.py Normal file
View File

@@ -0,0 +1,28 @@
class DiscordGuildMemberNotFoundError(Exception):
"""Member was not found in a discord guild"""
def __init__(self, user_id: int, guild_id: int) -> None:
self.user_id: int = user_id
self.guild_id: int = guild_id
super().__init__(f"Member with id {self.user_id} was not found in guild with id {self.guild_id}")
class DiscordCategoryNotFoundError(Exception):
"""Category was not found in a discord guild"""
def __init__(self, category_id: int, guild_id: int) -> None:
self.category_id: int = category_id
self.guild_id: int = guild_id
super().__init__(f"Category with id {self.category_id} was not found in guild with id {self.guild_id}")
class DiscordChannelNotFoundError(Exception):
"""Channel was not found in a discord guild"""
def __init__(self, channel_id: int, guild_id: int) -> None:
self.channel_id: int = channel_id
self.guild_id: int = guild_id
super().__init__(f"Channel with id {self.channel_id} was not found in guild with id {self.guild_id}")

View File

@@ -0,0 +1,20 @@
from typing import Optional
from bson import ObjectId
class EventNotFoundError(Exception):
"""PycordEvent could not find event with such an ID in the database"""
def __init__(self, event_id: Optional[str | ObjectId] = None, event_name: Optional[str] = None) -> None:
self.event_id = event_id
self.event_name = event_name
if self.event_id is None and self.event_name is None:
raise AttributeError("Either event id or name must be provided")
super().__init__(
f"Event with id {self.event_id} was not found"
if event_id is not None
else f"Event with name {self.event_name} was not found"
)

View File

@@ -0,0 +1,17 @@
from bson import ObjectId
class EventStageNotFoundError(Exception):
"""PycordEventStage could not find event with such an ID in the database"""
def __init__(self, stage_id: str | ObjectId) -> None:
self.stage_id = stage_id
super().__init__(f"Stage with id {self.stage_id} was not found")
class EventStageMissingSequenceError(Exception):
"""No sequence is provided for the event stage"""
def __init__(self) -> None:
super().__init__("Stage does not have a defined sequence")

View File

@@ -1,3 +1,6 @@
from bson import ObjectId
class UserNotFoundError(Exception):
"""PycordUser could not find user with such an ID in the database"""
@@ -6,3 +9,33 @@ class UserNotFoundError(Exception):
self.guild_id: int = guild_id
super().__init__(f"User with id {self.user_id} was not found in guild {self.guild_id}")
class UserAlreadyRegisteredForEventError(Exception):
"""PycordUser is already registered for the provided event"""
def __init__(self, user_id: int, event_id: str | ObjectId) -> None:
self.user_id: int = user_id
self.event_id: str | ObjectId = event_id
super().__init__(f"User with id {self.user_id} is already registered for the event {self.event_id}")
class UserNotRegisteredForEventError(Exception):
"""PycordUser is not registered for the provided event"""
def __init__(self, user_id: int, event_id: str | ObjectId) -> None:
self.user_id: int = user_id
self.event_id: str | ObjectId = event_id
super().__init__(f"User with id {self.user_id} is not registered for the event {self.event_id}")
class UserAlreadyCompletedEventError(Exception):
"""PycordUser already completed the provided event"""
def __init__(self, user_id: int, event_id: str | ObjectId) -> None:
self.user_id: int = user_id
self.event_id: str | ObjectId = event_id
super().__init__(f"User with id {self.user_id} already completed the event {self.event_id}")