From 14368e5a7bdcc4b6d3b151ecd9cb3162c30f292e Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Thu, 18 Jul 2024 23:21:38 +0800 Subject: refactor: Comment hook function while running the rules packages TODO: builtin hook function in every rules packages. --- hrc/rule/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'hrc/rule/__init__.py') diff --git a/hrc/rule/__init__.py b/hrc/rule/__init__.py index 467f74a..e144091 100644 --- a/hrc/rule/__init__.py +++ b/hrc/rule/__init__.py @@ -140,12 +140,10 @@ class Rule(ABC, Generic[EventT, StateT, ConfigT]): @final def state(self, value: StateT) -> None: self.core.rule_state[self.name] = value - - @staticmethod - async def enable(): ... - - @staticmethod - async def disable(): ... + + async def enable(self): ... + + async def disable(self): ... @staticmethod def aliases(names, ignore_case=False): @@ -155,3 +153,12 @@ class Rule(ABC, Generic[EventT, StateT, ConfigT]): return func return decorator + + @final + async def safe_run(self) -> None: + try: + await self.enable() + except Exception as e: + self.bot.error_or_exception( + f"Enable rule {self.__class__.__name__} failed:", e + ) -- cgit v1.2.3-70-g09d2