Merge 1a3abc22f8
into 75879cfb93
This commit is contained in:
commit
3ce3636e08
1 changed files with 21 additions and 3 deletions
|
@ -39,6 +39,15 @@ from mautrix.types import EventType, MessageType
|
||||||
from ..matrix import MaubotMessageEvent
|
from ..matrix import MaubotMessageEvent
|
||||||
from . import event
|
from . import event
|
||||||
|
|
||||||
|
|
||||||
|
class CommandError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class CommandFailure(CommandError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
PrefixType = Optional[Union[str, Callable[[], str], Callable[[Any], str]]]
|
PrefixType = Optional[Union[str, Callable[[], str], Callable[[Any], str]]]
|
||||||
AliasesType = Union[
|
AliasesType = Union[
|
||||||
List[str], Tuple[str, ...], Set[str], Callable[[str], bool], Callable[[Any, str], bool]
|
List[str], Tuple[str, ...], Set[str], Callable[[str], bool], Callable[[Any, str], bool]
|
||||||
|
@ -150,9 +159,18 @@ class CommandHandler:
|
||||||
await evt.reply(self.__mb_full_help__)
|
await evt.reply(self.__mb_full_help__)
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.__bound_instance__:
|
try:
|
||||||
return await self.__mb_func__(self.__bound_instance__, evt, **call_args)
|
if self.__bound_instance__:
|
||||||
return await self.__mb_func__(evt, **call_args)
|
return await self.__mb_func__(self.__bound_instance__, evt, **call_args)
|
||||||
|
return await self.__mb_func__(evt, **call_args)
|
||||||
|
except CommandFailure as e:
|
||||||
|
await evt.reply(f"Error: {e}")
|
||||||
|
except CommandError as e:
|
||||||
|
await evt.reply(f"Error: {e}")
|
||||||
|
raise e
|
||||||
|
except Exception as e:
|
||||||
|
await evt.reply("An error happened while running the command")
|
||||||
|
raise e
|
||||||
|
|
||||||
async def __call_subcommand__(
|
async def __call_subcommand__(
|
||||||
self, evt: MaubotMessageEvent, call_args: Dict[str, Any], remaining_val: str
|
self, evt: MaubotMessageEvent, call_args: Dict[str, Any], remaining_val: str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue