aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/hrc/rule/__init__.py
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2024-07-18 23:21:38 +0800
committer简律纯 <i@jyunko.cn>2024-07-18 23:21:38 +0800
commit14368e5a7bdcc4b6d3b151ecd9cb3162c30f292e (patch)
tree1638e77fa1e7b084e764a9f924005433d692d171 /hrc/rule/__init__.py
parent0f39a9dfbbb98975c4cc054f98fd7cb14b7e8fb7 (diff)
downloadHydroRollCore-14368e5a7bdcc4b6d3b151ecd9cb3162c30f292e.tar.gz
HydroRollCore-14368e5a7bdcc4b6d3b151ecd9cb3162c30f292e.zip
refactor: Comment hook function while running the rules packages
TODO: builtin hook function in every rules packages.
Diffstat (limited to 'hrc/rule/__init__.py')
-rw-r--r--hrc/rule/__init__.py19
1 files changed, 13 insertions, 6 deletions
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
+ )