diff options
| author | 2023-11-03 03:28:35 +0800 | |
|---|---|---|
| committer | 2023-11-03 03:28:35 +0800 | |
| commit | 5a2033860a328c4116f0ede2874915315e7487b0 (patch) | |
| tree | f7b6d88d50ce33bd5fb52fbcfbca906738f412d6 /hydroroll/core/__init__.py | |
| parent | 4bf6db5200affc2f623aa02301020092c0789d19 (diff) | |
| download | HydroRoll-5a2033860a328c4116f0ede2874915315e7487b0.tar.gz HydroRoll-5a2033860a328c4116f0ede2874915315e7487b0.zip | |
Co-authored-by: HadalFauna <HadalFauna@users.noreply.github.com>
Diffstat (limited to 'hydroroll/core/__init__.py')
| -rw-r--r-- | hydroroll/core/__init__.py | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/hydroroll/core/__init__.py b/hydroroll/core/__init__.py deleted file mode 100644 index ed02489..0000000 --- a/hydroroll/core/__init__.py +++ /dev/null @@ -1,70 +0,0 @@ -from abc import ABC, abstractmethod -import os, os.path -from enum import Enum -from iamai.config import ConfigModel -from iamai.utils import is_config_class -from typing import Generic, NoReturn, Optional, Type, TYPE_CHECKING -from ...HydroRoll.typing import T_Event, T_Config - -if TYPE_CHECKING: - from iamai.bot import Bot - -class RuleLoadType(Enum): - """插件加载类型。""" - - DIR = "dir" - NAME = "name" - FILE = "file" - CLASS = "class" - - -class Rule(ABC, Generic[T_Event, T_Config]): - """所有 iamai 插件的基类。 - - Attributes: - event: 当前正在被此插件处理的事件。 - priority: 插件的优先级,数字越小表示优先级越高,默认为 0。 - block: 插件执行结束后是否阻止事件的传播。True 表示阻止。 - __rule_load_type__: 插件加载类型,由 iamai 自动设置,反映了此插件是如何被加载的。 - __rule_file_path__: 当插件加载类型为 `RuleLoadType.CLASS` 时为 `None`, - 否则为定义插件在的 Python 模块的位置。 - """ - - event: T_Event - priority: int = 0 - Config: Type[ConfigModel] - - __rule_load_type__: RuleLoadType - __rule_file_path__: Optional[str] - - def __init__(self, event: T_Event): - self.event = event - - if not hasattr(self, "priority"): - self.priority = 0 - - self.get = self.bot.get - - self.__post_init__() - - def __post_init__(self): - """用于初始化后处理,被 `__init__()` 方法调用。""" - pass - - @property - def name(self) -> str: - """规则类名称。""" - return self.__class__.__name__ - - @property - def bot(self) -> "Bot": - """机器人对象。""" - return self.event.adapter.bot - - @property - def config(self) -> Optional[T_Config]: - """规则包配置。""" - config_class: ConfigModel = getattr(self, "Rule", None) - if is_config_class(config_class): - return getattr(self.config.rule, config_class.__config_name__, None) - return None
\ No newline at end of file |
