From 6553f038c0604febd19230d53cc776077f802102 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Thu, 1 Feb 2024 13:32:09 +0100 Subject: add the AbstractCommandErrorHandler interface this represents an interface that all command handlers will need to implement in order to be able to use them in both app & text command errors --- .../utils/error_handling/commands/__init__.py | 3 +++ pydis_core/utils/error_handling/commands/abc.py | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 pydis_core/utils/error_handling/commands/__init__.py create mode 100644 pydis_core/utils/error_handling/commands/abc.py diff --git a/pydis_core/utils/error_handling/commands/__init__.py b/pydis_core/utils/error_handling/commands/__init__.py new file mode 100644 index 00000000..2b648c07 --- /dev/null +++ b/pydis_core/utils/error_handling/commands/__init__.py @@ -0,0 +1,3 @@ +from .abc import AbstractCommandErrorHandler + +__all__ = ["AbstractCommandErrorHandler"] diff --git a/pydis_core/utils/error_handling/commands/abc.py b/pydis_core/utils/error_handling/commands/abc.py new file mode 100644 index 00000000..f155b239 --- /dev/null +++ b/pydis_core/utils/error_handling/commands/abc.py @@ -0,0 +1,24 @@ +from abc import ABC, abstractmethod +from typing import NoReturn + +from discord import Interaction +from discord.ext.commands import Context + + +class AbstractCommandErrorHandler(ABC): + """An abstract command error handler.""" + + @abstractmethod + async def should_handle_error(self, error: Exception) -> bool: + """A predicate that determines whether the error should be handled.""" + raise NotImplementedError + + @abstractmethod + async def handle_app_command_error(self, interaction: Interaction, error: Exception) -> NoReturn: + """Handle error raised in the context of app commands.""" + raise NotImplementedError + + @abstractmethod + async def handle_text_command_error(self, context: Context, error: Exception) -> NoReturn: + """Handle error raised in the context of text commands.""" + raise NotImplementedError -- cgit v1.2.3