mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-06-06 12:26:38 +00:00
删除说明前缀
This commit is contained in:
parent
0e11959347
commit
0099364838
@ -53,8 +53,6 @@ _driver: Optional[Driver] = None
|
||||
|
||||
def get_driver() -> Driver:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取全局 Driver 对象。可用于在计划任务的回调中获取当前 Driver 对象。
|
||||
|
||||
:返回:
|
||||
@ -79,8 +77,6 @@ def get_driver() -> Driver:
|
||||
|
||||
def get_app() -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取全局 Driver 对应 Server App 对象。
|
||||
|
||||
:返回:
|
||||
@ -107,8 +103,6 @@ def get_app() -> Any:
|
||||
|
||||
def get_asgi() -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取全局 Driver 对应 Asgi 对象。
|
||||
|
||||
:返回:
|
||||
@ -135,8 +129,6 @@ def get_asgi() -> Any:
|
||||
|
||||
def get_bot(self_id: Optional[str] = None) -> Bot:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
当提供 self_id 时,此函数是 get_bots()[self_id] 的简写;当不提供时,返回一个 Bot。
|
||||
|
||||
:参数:
|
||||
@ -173,8 +165,6 @@ def get_bot(self_id: Optional[str] = None) -> Bot:
|
||||
|
||||
def get_bots() -> Dict[str, Bot]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取所有通过 ws 连接 NoneBot 的 Bot 对象。
|
||||
|
||||
:返回:
|
||||
@ -229,8 +219,6 @@ def _resolve_combine_expr(obj_str: str) -> Type[Driver]:
|
||||
|
||||
def init(*, _env_file: Optional[str] = None, **kwargs):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
初始化 NoneBot 以及 全局 Driver 对象。
|
||||
|
||||
NoneBot 将会从 .env 文件中读取环境信息,并使用相应的 env 文件配置。
|
||||
@ -277,8 +265,6 @@ def init(*, _env_file: Optional[str] = None, **kwargs):
|
||||
|
||||
def run(*args: Any, **kwargs: Any) -> None:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
启动 NoneBot,即运行全局 Driver 对象。
|
||||
|
||||
:参数:
|
||||
|
@ -63,8 +63,6 @@ class Adapter(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
async def _call_api(self, bot: Bot, api: str, **data) -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``adapter`` 实际调用 api 的逻辑实现函数,实现该方法以调用 api。
|
||||
|
||||
:参数:
|
||||
|
@ -27,11 +27,11 @@ class Bot(abc.ABC):
|
||||
|
||||
_calling_api_hook: Set[T_CallingAPIHook] = set()
|
||||
"""
|
||||
:说明: call_api 时执行的函数
|
||||
call_api 时执行的函数
|
||||
"""
|
||||
_called_api_hook: Set[T_CalledAPIHook] = set()
|
||||
"""
|
||||
:说明: call_api 后执行的函数
|
||||
call_api 后执行的函数
|
||||
"""
|
||||
|
||||
def __init__(self, adapter: "Adapter", self_id: str):
|
||||
@ -58,8 +58,6 @@ class Bot(abc.ABC):
|
||||
|
||||
async def call_api(self, api: str, **data: Any) -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
|
||||
|
||||
:参数:
|
||||
@ -129,8 +127,6 @@ class Bot(abc.ABC):
|
||||
self, event: "Event", message: Union[str, "Message", "MessageSegment"], **kwargs
|
||||
) -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
调用机器人基础发送消息接口
|
||||
|
||||
:参数:
|
||||
@ -144,8 +140,6 @@ class Bot(abc.ABC):
|
||||
@classmethod
|
||||
def on_calling_api(cls, func: T_CallingAPIHook) -> T_CallingAPIHook:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
调用 api 预处理。
|
||||
|
||||
:参数:
|
||||
@ -160,8 +154,6 @@ class Bot(abc.ABC):
|
||||
@classmethod
|
||||
def on_called_api(cls, func: T_CalledAPIHook) -> T_CalledAPIHook:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
调用 api 后处理。
|
||||
|
||||
:参数:
|
||||
|
@ -16,8 +16,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def get_type(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件类型的方法,类型通常为 NoneBot 内置的四种类型。
|
||||
|
||||
:返回:
|
||||
@ -30,8 +28,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def get_event_name(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件名称的方法。
|
||||
|
||||
:返回:
|
||||
@ -43,8 +39,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def get_event_description(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件描述的方法,通常为事件具体内容。
|
||||
|
||||
:返回:
|
||||
@ -58,8 +52,6 @@ class Event(abc.ABC, BaseModel):
|
||||
|
||||
def get_log_string(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件日志信息的方法,通常你不需要修改这个方法,只有当希望 NoneBot 隐藏该事件日志时,可以抛出 ``NoLogException`` 异常。
|
||||
|
||||
:返回:
|
||||
@ -75,8 +67,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def get_user_id(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件主体 id 的方法,通常是用户 id 。
|
||||
|
||||
:返回:
|
||||
@ -88,8 +78,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def get_session_id(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取会话 id 的方法,用于判断当前事件属于哪一个会话,通常是用户 id、群组 id 组合。
|
||||
|
||||
:返回:
|
||||
@ -101,8 +89,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def get_message(self) -> "Message":
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件消息内容的方法。
|
||||
|
||||
:返回:
|
||||
@ -113,8 +99,6 @@ class Event(abc.ABC, BaseModel):
|
||||
|
||||
def get_plaintext(self) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取消息纯文本的方法,通常不需要修改,默认通过 ``get_message().extract_plain_text`` 获取。
|
||||
|
||||
:返回:
|
||||
@ -126,8 +110,6 @@ class Event(abc.ABC, BaseModel):
|
||||
@abc.abstractmethod
|
||||
def is_tome(self) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取事件是否与机器人有关的方法。
|
||||
|
||||
:返回:
|
||||
|
@ -26,11 +26,11 @@ class MessageSegment(Mapping, abc.ABC, Generic[TM]):
|
||||
|
||||
type: str
|
||||
"""
|
||||
- 说明: 消息段类型
|
||||
消息段类型
|
||||
"""
|
||||
data: Dict[str, Any] = field(default_factory=lambda: {})
|
||||
"""
|
||||
- 说明: 消息段数据
|
||||
消息段数据
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@ -114,9 +114,8 @@ class Message(List[TMS], abc.ABC):
|
||||
@classmethod
|
||||
def template(cls: Type[TM], format_string: Union[str, TM]) -> MessageTemplate[TM]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
根据创建消息模板, 用法和 ``str.format`` 大致相同, 但是可以输出消息对象, 并且支持以 ``Message`` 对象作为消息模板
|
||||
|
||||
并且提供了拓展的格式化控制符, 可以用适用于该消息类型的 ``MessageSegment`` 的工厂方法创建消息
|
||||
|
||||
:示例:
|
||||
@ -187,8 +186,6 @@ class Message(List[TMS], abc.ABC):
|
||||
|
||||
def append(self: TM, obj: Union[str, TMS]) -> TM:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
添加一个消息段到消息数组末尾
|
||||
|
||||
:参数:
|
||||
@ -205,8 +202,6 @@ class Message(List[TMS], abc.ABC):
|
||||
|
||||
def extend(self: TM, obj: Union[TM, Iterable[TMS]]) -> TM:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
拼接一个消息数组或多个消息段到消息数组末尾
|
||||
|
||||
:参数:
|
||||
@ -222,8 +217,6 @@ class Message(List[TMS], abc.ABC):
|
||||
|
||||
def extract_plain_text(self: "Message[MessageSegment]") -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
提取消息内纯文本消息
|
||||
"""
|
||||
|
||||
|
@ -47,8 +47,6 @@ class MessageTemplate(Formatter, Generic[TF]):
|
||||
|
||||
def __init__(self, template, factory=str) -> None:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
创建一个模板
|
||||
|
||||
:参数:
|
||||
@ -71,8 +69,6 @@ class MessageTemplate(Formatter, Generic[TF]):
|
||||
|
||||
def format(self, *args: Any, **kwargs: Any) -> TF:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
根据模板和参数生成消息对象
|
||||
"""
|
||||
msg = self.factory()
|
||||
|
@ -137,7 +137,6 @@ class Env(BaseConfig):
|
||||
|
||||
environment: str = "prod"
|
||||
"""
|
||||
:说明:
|
||||
当前环境名。 NoneBot 将从 ``.env.{environment}`` 文件中加载配置。
|
||||
"""
|
||||
|
||||
@ -160,8 +159,6 @@ class Config(BaseConfig):
|
||||
# nonebot configs
|
||||
driver: str = "~fastapi"
|
||||
"""
|
||||
:说明:
|
||||
|
||||
NoneBot 运行所使用的 ``Driver`` 。继承自 ``nonebot.drivers.Driver`` 。
|
||||
|
||||
配置格式为 ``<module>[:<Driver>][+<module>[:<Mixin>]]*``。
|
||||
@ -170,20 +167,14 @@ class Config(BaseConfig):
|
||||
"""
|
||||
host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore
|
||||
"""
|
||||
:说明:
|
||||
|
||||
NoneBot 的 HTTP 和 WebSocket 服务端监听的 IP/主机名。
|
||||
"""
|
||||
port: int = 8080
|
||||
"""
|
||||
:说明:
|
||||
|
||||
NoneBot 的 HTTP 和 WebSocket 服务端监听的端口。
|
||||
"""
|
||||
log_level: Union[int, str] = "INFO"
|
||||
"""
|
||||
:说明:
|
||||
|
||||
配置 NoneBot 日志输出等级,可以为 ``int`` 类型等级或等级名称,参考 `loguru 日志等级`_。
|
||||
|
||||
:示例:
|
||||
@ -200,16 +191,12 @@ class Config(BaseConfig):
|
||||
# bot connection configs
|
||||
api_timeout: Optional[float] = 30.0
|
||||
"""
|
||||
:说明:
|
||||
|
||||
API 请求超时时间,单位: 秒。
|
||||
"""
|
||||
|
||||
# bot runtime configs
|
||||
superusers: Set[str] = set()
|
||||
"""
|
||||
:说明:
|
||||
|
||||
机器人超级用户。
|
||||
|
||||
:示例:
|
||||
@ -220,26 +207,18 @@ class Config(BaseConfig):
|
||||
"""
|
||||
nickname: Set[str] = set()
|
||||
"""
|
||||
:说明:
|
||||
|
||||
机器人昵称。
|
||||
"""
|
||||
command_start: Set[str] = {"/"}
|
||||
"""
|
||||
:说明:
|
||||
|
||||
命令的起始标记,用于判断一条消息是不是命令。
|
||||
"""
|
||||
command_sep: Set[str] = {"."}
|
||||
"""
|
||||
:说明:
|
||||
|
||||
命令的分隔标记,用于将文本形式的命令切分为元组(实际的命令名)。
|
||||
"""
|
||||
session_expire_timeout: timedelta = timedelta(minutes=2)
|
||||
"""
|
||||
:说明:
|
||||
|
||||
等待用户回复的超时时间。
|
||||
|
||||
:示例:
|
||||
|
@ -41,15 +41,15 @@ class Driver(abc.ABC):
|
||||
|
||||
_adapters: Dict[str, "Adapter"] = {}
|
||||
"""
|
||||
:说明: 已注册的适配器列表
|
||||
已注册的适配器列表
|
||||
"""
|
||||
_bot_connection_hook: Set[T_BotConnectionHook] = set()
|
||||
"""
|
||||
:说明: Bot 连接建立时执行的函数
|
||||
Bot 连接建立时执行的函数
|
||||
"""
|
||||
_bot_disconnection_hook: Set[T_BotDisconnectionHook] = set()
|
||||
"""
|
||||
:说明: Bot 连接断开时执行的函数
|
||||
Bot 连接断开时执行的函数
|
||||
"""
|
||||
|
||||
def __init__(self, env: Env, config: Config):
|
||||
@ -61,30 +61,26 @@ class Driver(abc.ABC):
|
||||
"""
|
||||
self.env: str = env.environment
|
||||
"""
|
||||
:说明: 环境名称
|
||||
环境名称
|
||||
"""
|
||||
self.config: Config = config
|
||||
"""
|
||||
:说明: 配置对象
|
||||
配置对象
|
||||
"""
|
||||
self._clients: Dict[str, "Bot"] = {}
|
||||
"""
|
||||
:说明: 已连接的 Bot
|
||||
已连接的 Bot
|
||||
"""
|
||||
|
||||
@property
|
||||
def bots(self) -> Dict[str, "Bot"]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取当前所有已连接的 Bot
|
||||
"""
|
||||
return self._clients
|
||||
|
||||
def register_adapter(self, adapter: Type["Adapter"], **kwargs) -> None:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个协议适配器
|
||||
|
||||
:参数:
|
||||
@ -119,8 +115,6 @@ class Driver(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
def run(self, *args, **kwargs):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
启动驱动框架
|
||||
|
||||
:参数:
|
||||
@ -143,8 +137,6 @@ class Driver(abc.ABC):
|
||||
|
||||
def on_bot_connect(self, func: T_BotConnectionHook) -> T_BotConnectionHook:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。
|
||||
|
||||
:函数参数:
|
||||
@ -156,8 +148,6 @@ class Driver(abc.ABC):
|
||||
|
||||
def on_bot_disconnect(self, func: T_BotDisconnectionHook) -> T_BotDisconnectionHook:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。
|
||||
|
||||
:函数参数:
|
||||
|
@ -39,8 +39,6 @@ class BlockDriver(Driver):
|
||||
@overrides(Driver)
|
||||
def on_startup(self, func: STARTUP_FUNC) -> STARTUP_FUNC:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个启动时执行的函数
|
||||
|
||||
:参数:
|
||||
@ -53,8 +51,6 @@ class BlockDriver(Driver):
|
||||
@overrides(Driver)
|
||||
def on_shutdown(self, func: SHUTDOWN_FUNC) -> SHUTDOWN_FUNC:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个停止时执行的函数
|
||||
|
||||
:参数:
|
||||
|
@ -168,7 +168,7 @@ class WebSocket(abc.ABC):
|
||||
@abc.abstractmethod
|
||||
def closed(self) -> bool:
|
||||
"""
|
||||
:说明: 连接是否已经关闭
|
||||
连接是否已经关闭
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -48,56 +48,38 @@ class Config(BaseSettings):
|
||||
|
||||
fastapi_openapi_url: Optional[str] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``openapi.json`` 地址,默认为 ``None`` 即关闭
|
||||
"""
|
||||
fastapi_docs_url: Optional[str] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``swagger`` 地址,默认为 ``None`` 即关闭
|
||||
"""
|
||||
fastapi_redoc_url: Optional[str] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``redoc`` 地址,默认为 ``None`` 即关闭
|
||||
"""
|
||||
fastapi_include_adapter_schema: bool = True
|
||||
"""
|
||||
:说明:
|
||||
|
||||
是否包含适配器路由的 schema,默认为 ``True``
|
||||
"""
|
||||
fastapi_reload: bool = False
|
||||
"""
|
||||
:说明:
|
||||
|
||||
开启/关闭冷重载
|
||||
"""
|
||||
fastapi_reload_dirs: Optional[List[str]] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
重载监控文件夹列表,默认为 uvicorn 默认值
|
||||
"""
|
||||
fastapi_reload_delay: Optional[float] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
重载延迟,默认为 uvicorn 默认值
|
||||
"""
|
||||
fastapi_reload_includes: Optional[List[str]] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
"""
|
||||
fastapi_reload_excludes: Optional[List[str]] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
"""
|
||||
|
||||
|
@ -56,32 +56,22 @@ class Config(BaseSettings):
|
||||
|
||||
quart_reload: bool = False
|
||||
"""
|
||||
:说明:
|
||||
|
||||
开启/关闭冷重载
|
||||
"""
|
||||
quart_reload_dirs: Optional[List[str]] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
重载监控文件夹列表,默认为 uvicorn 默认值
|
||||
"""
|
||||
quart_reload_delay: Optional[float] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
重载延迟,默认为 uvicorn 默认值
|
||||
"""
|
||||
quart_reload_includes: Optional[List[str]] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
"""
|
||||
quart_reload_excludes: Optional[List[str]] = None
|
||||
"""
|
||||
:说明:
|
||||
|
||||
不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值
|
||||
"""
|
||||
|
||||
|
@ -13,8 +13,6 @@ from pydantic.fields import ModelField
|
||||
|
||||
class NoneBotException(Exception):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
所有 NoneBot 发生的异常基类。
|
||||
"""
|
||||
|
||||
@ -22,8 +20,6 @@ class NoneBotException(Exception):
|
||||
# Rule Exception
|
||||
class ParserExit(NoneBotException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``shell command`` 处理消息失败时返回的异常
|
||||
|
||||
:参数:
|
||||
@ -46,16 +42,12 @@ class ParserExit(NoneBotException):
|
||||
# Processor Exception
|
||||
class ProcessException(NoneBotException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
事件处理过程中发生的异常基类。
|
||||
"""
|
||||
|
||||
|
||||
class IgnoredException(ProcessException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
|
||||
|
||||
:参数:
|
||||
@ -75,8 +67,6 @@ class IgnoredException(ProcessException):
|
||||
|
||||
class MockApiException(ProcessException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。可由 api hook 抛出。
|
||||
|
||||
:参数:
|
||||
@ -96,8 +86,6 @@ class MockApiException(ProcessException):
|
||||
|
||||
class StopPropagation(ProcessException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 终止事件向下层传播。
|
||||
|
||||
:用法:
|
||||
@ -109,16 +97,12 @@ class StopPropagation(ProcessException):
|
||||
# Matcher Exceptions
|
||||
class MatcherException(NoneBotException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
所有 Matcher 发生的异常基类。
|
||||
"""
|
||||
|
||||
|
||||
class SkippedException(MatcherException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 立即结束当前 ``Handler`` 的处理,继续处理下一个 ``Handler``。
|
||||
|
||||
:用法:
|
||||
@ -129,8 +113,6 @@ class SkippedException(MatcherException):
|
||||
|
||||
class TypeMisMatch(SkippedException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
当前 ``Handler`` 的参数类型不匹配。
|
||||
"""
|
||||
|
||||
@ -147,8 +129,6 @@ class TypeMisMatch(SkippedException):
|
||||
|
||||
class PausedException(MatcherException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 结束当前 ``Handler`` 并等待下一条消息后继续下一个 ``Handler``。
|
||||
可用于用户输入新信息。
|
||||
|
||||
@ -160,8 +140,6 @@ class PausedException(MatcherException):
|
||||
|
||||
class RejectedException(MatcherException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 结束当前 ``Handler`` 并等待下一条消息后重新运行当前 ``Handler``。
|
||||
可用于用户重新输入。
|
||||
|
||||
@ -173,8 +151,6 @@ class RejectedException(MatcherException):
|
||||
|
||||
class FinishedException(MatcherException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 结束当前 ``Handler`` 且后续 ``Handler`` 不再被运行。
|
||||
可用于结束用户会话。
|
||||
|
||||
@ -187,8 +163,6 @@ class FinishedException(MatcherException):
|
||||
# Adapter Exceptions
|
||||
class AdapterException(NoneBotException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
代表 ``Adapter`` 抛出的异常,所有的 ``Adapter`` 都要在内部继承自这个 ``Exception``
|
||||
|
||||
:参数:
|
||||
@ -202,8 +176,6 @@ class AdapterException(NoneBotException):
|
||||
|
||||
class NoLogException(AdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
指示 NoneBot 对当前 ``Event`` 进行处理但不显示 Log 信息,可在 ``get_log_string`` 时抛出
|
||||
"""
|
||||
|
||||
@ -212,8 +184,6 @@ class NoLogException(AdapterException):
|
||||
|
||||
class ApiNotAvailable(AdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
在 API 连接不可用时抛出。
|
||||
"""
|
||||
|
||||
@ -222,8 +192,6 @@ class ApiNotAvailable(AdapterException):
|
||||
|
||||
class NetworkError(AdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
在网络出现问题时抛出,如: API 请求地址不正确, API 请求无返回或返回状态非正常等。
|
||||
"""
|
||||
|
||||
@ -232,8 +200,6 @@ class NetworkError(AdapterException):
|
||||
|
||||
class ActionFailed(AdapterException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
API 请求成功返回数据,但 API 操作失败。
|
||||
"""
|
||||
|
||||
@ -243,16 +209,12 @@ class ActionFailed(AdapterException):
|
||||
# Driver Exceptions
|
||||
class DriverException(NoneBotException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``Driver`` 抛出的异常基类
|
||||
"""
|
||||
|
||||
|
||||
class WebSocketClosed(DriverException):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
WebSocket 连接已关闭
|
||||
"""
|
||||
|
||||
|
@ -24,8 +24,6 @@ if TYPE_CHECKING:
|
||||
# logger = logging.getLogger("nonebot")
|
||||
logger: "Logger" = loguru.logger
|
||||
"""
|
||||
:说明:
|
||||
|
||||
NoneBot 日志记录器对象。
|
||||
|
||||
:默认信息:
|
||||
|
@ -66,7 +66,7 @@ T = TypeVar("T")
|
||||
|
||||
matchers: Dict[int, List[Type["Matcher"]]] = defaultdict(list)
|
||||
"""
|
||||
:说明: 用于存储当前所有的事件响应器
|
||||
用于存储当前所有的事件响应器
|
||||
"""
|
||||
current_bot: ContextVar[Bot] = ContextVar("current_bot")
|
||||
current_event: ContextVar[Event] = ContextVar("current_event")
|
||||
@ -105,66 +105,66 @@ class Matcher(metaclass=MatcherMeta):
|
||||
|
||||
plugin: Optional["Plugin"] = None
|
||||
"""
|
||||
:说明: 事件响应器所在插件
|
||||
事件响应器所在插件
|
||||
"""
|
||||
module: Optional[ModuleType] = None
|
||||
"""
|
||||
:说明: 事件响应器所在插件模块
|
||||
事件响应器所在插件模块
|
||||
"""
|
||||
plugin_name: Optional[str] = None
|
||||
"""
|
||||
:说明: 事件响应器所在插件名
|
||||
事件响应器所在插件名
|
||||
"""
|
||||
module_name: Optional[str] = None
|
||||
"""
|
||||
:说明: 事件响应器所在点分割插件模块路径
|
||||
事件响应器所在点分割插件模块路径
|
||||
"""
|
||||
|
||||
type: str = ""
|
||||
"""
|
||||
:说明: 事件响应器类型
|
||||
事件响应器类型
|
||||
"""
|
||||
rule: Rule = Rule()
|
||||
"""
|
||||
:说明: 事件响应器匹配规则
|
||||
事件响应器匹配规则
|
||||
"""
|
||||
permission: Permission = Permission()
|
||||
"""
|
||||
:说明: 事件响应器触发权限
|
||||
事件响应器触发权限
|
||||
"""
|
||||
handlers: List[Dependent[Any]] = []
|
||||
"""
|
||||
:说明: 事件响应器拥有的事件处理函数列表
|
||||
事件响应器拥有的事件处理函数列表
|
||||
"""
|
||||
priority: int = 1
|
||||
"""
|
||||
:说明: 事件响应器优先级
|
||||
事件响应器优先级
|
||||
"""
|
||||
block: bool = False
|
||||
"""
|
||||
:说明: 事件响应器是否阻止事件传播
|
||||
事件响应器是否阻止事件传播
|
||||
"""
|
||||
temp: bool = False
|
||||
"""
|
||||
:说明: 事件响应器是否为临时
|
||||
事件响应器是否为临时
|
||||
"""
|
||||
expire_time: Optional[datetime] = None
|
||||
"""
|
||||
:说明: 事件响应器过期时间点
|
||||
事件响应器过期时间点
|
||||
"""
|
||||
|
||||
_default_state: T_State = {}
|
||||
"""
|
||||
:说明: 事件响应器默认状态
|
||||
事件响应器默认状态
|
||||
"""
|
||||
|
||||
_default_type_updater: Optional[Dependent[str]] = None
|
||||
"""
|
||||
:说明: 事件响应器类型更新函数
|
||||
事件响应器类型更新函数
|
||||
"""
|
||||
_default_permission_updater: Optional[Dependent[Permission]] = None
|
||||
"""
|
||||
:说明: 事件响应器权限更新函数
|
||||
事件响应器权限更新函数
|
||||
"""
|
||||
|
||||
HANDLER_PARAM_TYPES = [
|
||||
@ -210,8 +210,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
default_permission_updater: Optional[T_PermissionUpdater] = None,
|
||||
) -> Type["Matcher"]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
创建一个新的事件响应器,并存储至 `matchers <#matchers>`_
|
||||
|
||||
:参数:
|
||||
@ -278,8 +276,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
dependency_cache: Optional[T_DependencyCache] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
检查是否满足触发权限
|
||||
|
||||
:参数:
|
||||
@ -306,8 +302,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
dependency_cache: Optional[T_DependencyCache] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
检查是否满足匹配规则
|
||||
|
||||
:参数:
|
||||
@ -328,8 +322,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
@classmethod
|
||||
def type_updater(cls, func: T_TypeUpdater) -> T_TypeUpdater:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数来更改当前事件响应器的默认响应事件类型更新函数
|
||||
|
||||
:参数:
|
||||
@ -344,8 +336,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
@classmethod
|
||||
def permission_updater(cls, func: T_PermissionUpdater) -> T_PermissionUpdater:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数来更改当前事件响应器的默认会话权限更新函数
|
||||
|
||||
:参数:
|
||||
@ -374,8 +364,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
cls, parameterless: Optional[List[Any]] = None
|
||||
) -> Callable[[T_Handler], T_Handler]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数来向事件响应器直接添加一个处理函数
|
||||
|
||||
:参数:
|
||||
@ -394,8 +382,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
cls, id: str = "", parameterless: Optional[List[Any]] = None
|
||||
) -> Callable[[T_Handler], T_Handler]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数来指示 NoneBot 在接收用户新的一条消息后继续运行该函数
|
||||
|
||||
:参数:
|
||||
@ -436,8 +422,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
parameterless: Optional[List[Any]] = None,
|
||||
) -> Callable[[T_Handler], T_Handler]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
装饰一个函数来指示 NoneBot 当要获取的 ``key`` 不存在时接收用户新的一条消息并经过 ``ArgsParser`` 处理后再运行该函数,如果 ``key`` 已存在则直接继续运行
|
||||
|
||||
:参数:
|
||||
@ -482,8 +466,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
**kwargs: Any,
|
||||
) -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
发送一条消息给当前交互用户
|
||||
|
||||
:参数:
|
||||
@ -507,8 +489,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
**kwargs,
|
||||
) -> NoReturn:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
发送一条消息给当前交互用户并结束当前事件响应器
|
||||
|
||||
:参数:
|
||||
@ -527,8 +507,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
**kwargs,
|
||||
) -> NoReturn:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续下一个处理函数
|
||||
|
||||
:参数:
|
||||
@ -547,10 +525,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
**kwargs,
|
||||
) -> NoReturn:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
最近使用 ``got`` / ``receive`` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,
|
||||
在接收用户新的一条消息后继续当前处理函数
|
||||
最近使用 ``got`` / ``receive`` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续当前处理函数
|
||||
|
||||
:参数:
|
||||
|
||||
@ -569,10 +544,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
**kwargs,
|
||||
) -> NoReturn:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
最近使用 ``got`` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,
|
||||
在接收用户新的一条消息后继续当前处理函数
|
||||
最近使用 ``got`` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续当前处理函数
|
||||
|
||||
:参数:
|
||||
|
||||
@ -594,10 +566,7 @@ class Matcher(metaclass=MatcherMeta):
|
||||
**kwargs,
|
||||
) -> NoReturn:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
最近使用 ``got`` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,
|
||||
在接收用户新的一条消息后继续当前处理函数
|
||||
最近使用 ``got`` 接收的消息不符合预期,发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续当前处理函数
|
||||
|
||||
:参数:
|
||||
|
||||
@ -642,8 +611,6 @@ class Matcher(metaclass=MatcherMeta):
|
||||
|
||||
def stop_propagation(self):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
阻止事件传播
|
||||
"""
|
||||
self.block = True
|
||||
|
@ -69,8 +69,6 @@ RUN_POSTPCS_PARAMS = [
|
||||
|
||||
def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
事件预处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
|
||||
"""
|
||||
_event_preprocessors.add(
|
||||
@ -81,8 +79,6 @@ def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
|
||||
|
||||
def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
事件后处理。装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
|
||||
"""
|
||||
_event_postprocessors.add(
|
||||
@ -93,8 +89,6 @@ def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
|
||||
|
||||
def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
运行预处理。装饰一个函数,使它在每次事件响应器运行前执行。
|
||||
"""
|
||||
_run_preprocessors.add(
|
||||
@ -105,8 +99,6 @@ def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
|
||||
|
||||
def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
运行后处理。装饰一个函数,使它在每次事件响应器运行后执行。
|
||||
"""
|
||||
_run_postprocessors.add(
|
||||
@ -242,8 +234,6 @@ async def _run_matcher(
|
||||
|
||||
async def handle_event(bot: "Bot", event: "Event") -> None:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
处理一个事件。调用该函数以实现分发事件。
|
||||
|
||||
:参数:
|
||||
|
@ -56,8 +56,6 @@ def Depends(
|
||||
use_cache: bool = True,
|
||||
) -> Any:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
参数依赖注入装饰器
|
||||
|
||||
:参数:
|
||||
|
@ -35,8 +35,6 @@ async def _run_coro_with_catch(coro: Coroutine[Any, Any, Any]):
|
||||
|
||||
class Permission:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``Matcher`` 规则类,当事件传递时,在 ``Matcher`` 运行前进行检查。
|
||||
|
||||
:示例:
|
||||
@ -74,8 +72,6 @@ class Permission:
|
||||
for checker in checkers
|
||||
)
|
||||
"""
|
||||
:说明:
|
||||
|
||||
存储 ``PermissionChecker``
|
||||
"""
|
||||
|
||||
@ -87,8 +83,6 @@ class Permission:
|
||||
dependency_cache: Optional[T_DependencyCache] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
检查是否满足某个权限
|
||||
|
||||
:参数:
|
||||
@ -155,19 +149,19 @@ class MetaEvent:
|
||||
|
||||
MESSAGE = Permission(Message())
|
||||
"""
|
||||
- **说明**: 匹配任意 ``message`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 message type 的 Matcher。
|
||||
匹配任意 ``message`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 message type 的 Matcher。
|
||||
"""
|
||||
NOTICE = Permission(Notice())
|
||||
"""
|
||||
- **说明**: 匹配任意 ``notice`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 notice type 的 Matcher。
|
||||
匹配任意 ``notice`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 notice type 的 Matcher。
|
||||
"""
|
||||
REQUEST = Permission(Request())
|
||||
"""
|
||||
- **说明**: 匹配任意 ``request`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 request type 的 Matcher。
|
||||
匹配任意 ``request`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 request type 的 Matcher。
|
||||
"""
|
||||
METAEVENT = Permission(MetaEvent())
|
||||
"""
|
||||
- **说明**: 匹配任意 ``meta_event`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 meta_event type 的 Matcher。
|
||||
匹配任意 ``meta_event`` 类型事件,仅在需要同时捕获不同类型事件时使用。优先使用 meta_event type 的 Matcher。
|
||||
"""
|
||||
|
||||
|
||||
@ -187,8 +181,6 @@ class User:
|
||||
|
||||
def USER(*users: str, perm: Optional[Permission] = None):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``event`` 的 ``session_id`` 在白名单内且满足 perm
|
||||
|
||||
:参数:
|
||||
@ -211,5 +203,5 @@ class SuperUser:
|
||||
|
||||
SUPERUSER = Permission(SuperUser())
|
||||
"""
|
||||
- **说明**: 匹配任意超级用户消息类型事件
|
||||
匹配任意超级用户消息类型事件
|
||||
"""
|
||||
|
@ -3,8 +3,6 @@ from . import _current_plugin
|
||||
|
||||
class Export(dict):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
插件导出内容以使得其他插件可以获得。
|
||||
|
||||
:示例:
|
||||
@ -46,8 +44,6 @@ class Export(dict):
|
||||
|
||||
def export() -> Export:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取插件的导出内容对象
|
||||
|
||||
:返回:
|
||||
|
@ -12,8 +12,6 @@ from .plugin import Plugin, get_plugin
|
||||
|
||||
def load_plugin(module_path: str) -> Optional[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
使用 ``PluginManager`` 加载单个插件,可以是本地插件或是通过 ``pip`` 安装的插件。
|
||||
|
||||
:参数:
|
||||
@ -32,8 +30,6 @@ def load_plugin(module_path: str) -> Optional[Plugin]:
|
||||
|
||||
def load_plugins(*plugin_dir: str) -> Set[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
导入目录下多个插件,以 ``_`` 开头的插件不会被导入!
|
||||
|
||||
:参数:
|
||||
@ -53,8 +49,6 @@ def load_all_plugins(
|
||||
module_path: Iterable[str], plugin_dir: Iterable[str]
|
||||
) -> Set[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
导入指定列表中的插件以及指定目录下多个插件,以 ``_`` 开头的插件不会被导入!
|
||||
|
||||
:参数:
|
||||
@ -73,8 +67,6 @@ def load_all_plugins(
|
||||
|
||||
def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
导入指定 json 文件中的 ``plugins`` 以及 ``plugin_dirs`` 下多个插件,以 ``_`` 开头的插件不会被导入!
|
||||
|
||||
:参数:
|
||||
@ -97,8 +89,6 @@ def load_from_json(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
|
||||
|
||||
def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
导入指定 toml 文件 ``[tool.nonebot]`` 中的 ``plugins`` 以及 ``plugin_dirs`` 下多个插件,
|
||||
以 ``_`` 开头的插件不会被导入!
|
||||
|
||||
@ -133,8 +123,6 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> Set[Plugin]:
|
||||
|
||||
def load_builtin_plugin(name: str) -> Optional[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
导入 NoneBot 内置插件
|
||||
|
||||
:返回:
|
||||
@ -146,8 +134,6 @@ def load_builtin_plugin(name: str) -> Optional[Plugin]:
|
||||
|
||||
def load_builtin_plugins(*plugins) -> Set[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
导入多个 NoneBot 内置插件
|
||||
|
||||
:返回:
|
||||
@ -159,8 +145,6 @@ def load_builtin_plugins(*plugins) -> Set[Plugin]:
|
||||
|
||||
def require(name: str) -> Export:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取一个插件的导出内容
|
||||
|
||||
:参数:
|
||||
|
@ -55,8 +55,6 @@ def on(
|
||||
_depth: int = 0,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个基础事件响应器,可自定义类型。
|
||||
|
||||
:参数:
|
||||
@ -101,8 +99,6 @@ def on_metaevent(
|
||||
_depth: int = 0,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个元事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -146,8 +142,6 @@ def on_message(
|
||||
_depth: int = 0,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -191,8 +185,6 @@ def on_notice(
|
||||
_depth: int = 0,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个通知事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -235,8 +227,6 @@ def on_request(
|
||||
_depth: int = 0,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个请求事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -276,8 +266,6 @@ def on_startswith(
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
|
||||
|
||||
:参数:
|
||||
@ -307,8 +295,6 @@ def on_endswith(
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
|
||||
|
||||
:参数:
|
||||
@ -337,8 +323,6 @@ def on_keyword(
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
|
||||
|
||||
:参数:
|
||||
@ -367,8 +351,6 @@ def on_command(
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息以指定命令开头时响应。
|
||||
|
||||
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`_
|
||||
@ -406,8 +388,6 @@ def on_shell_command(
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个支持 ``shell_like`` 解析参数的命令消息事件响应器。
|
||||
|
||||
与普通的 ``on_command`` 不同的是,在添加 ``parser`` 参数时, 响应器会自动处理消息。
|
||||
@ -448,8 +428,6 @@ def on_regex(
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
|
||||
|
||||
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`_
|
||||
@ -485,19 +463,17 @@ class CommandGroup:
|
||||
"""
|
||||
self.basecmd: Tuple[str, ...] = (cmd,) if isinstance(cmd, str) else cmd
|
||||
"""
|
||||
- **说明**: 命令前缀
|
||||
命令前缀
|
||||
"""
|
||||
if "aliases" in kwargs:
|
||||
del kwargs["aliases"]
|
||||
self.base_kwargs: Dict[str, Any] = kwargs
|
||||
"""
|
||||
- **说明**: 其他传递给 ``on_command`` 的参数默认值
|
||||
其他传递给 ``on_command`` 的参数默认值
|
||||
"""
|
||||
|
||||
def command(self, cmd: Union[str, Tuple[str, ...]], **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个新的命令。
|
||||
|
||||
:参数:
|
||||
@ -520,8 +496,6 @@ class CommandGroup:
|
||||
self, cmd: Union[str, Tuple[str, ...]], **kwargs
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个新的命令。
|
||||
|
||||
:参数:
|
||||
@ -546,23 +520,19 @@ class MatcherGroup:
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
创建一个事件响应器组合,参数为默认值,与 ``on`` 一致
|
||||
"""
|
||||
self.matchers: List[Type[Matcher]] = []
|
||||
"""
|
||||
:说明: 组内事件响应器列表
|
||||
组内事件响应器列表
|
||||
"""
|
||||
self.base_kwargs: Dict[str, Any] = kwargs
|
||||
"""
|
||||
- **说明**: 其他传递给 ``on`` 的参数默认值
|
||||
其他传递给 ``on`` 的参数默认值
|
||||
"""
|
||||
|
||||
def on(self, **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个基础事件响应器,可自定义类型。
|
||||
|
||||
:参数:
|
||||
@ -588,8 +558,6 @@ class MatcherGroup:
|
||||
|
||||
def on_metaevent(self, **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个元事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -615,8 +583,6 @@ class MatcherGroup:
|
||||
|
||||
def on_message(self, **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -642,8 +608,6 @@ class MatcherGroup:
|
||||
|
||||
def on_notice(self, **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个通知事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -668,8 +632,6 @@ class MatcherGroup:
|
||||
|
||||
def on_request(self, **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个请求事件响应器。
|
||||
|
||||
:参数:
|
||||
@ -696,8 +658,6 @@ class MatcherGroup:
|
||||
self, msg: Union[str, Tuple[str, ...]], **kwargs
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
|
||||
|
||||
:参数:
|
||||
@ -725,8 +685,6 @@ class MatcherGroup:
|
||||
|
||||
def on_endswith(self, msg: Union[str, Tuple[str, ...]], **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
|
||||
|
||||
:参数:
|
||||
@ -754,8 +712,6 @@ class MatcherGroup:
|
||||
|
||||
def on_keyword(self, keywords: Set[str], **kwargs) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
|
||||
|
||||
:参数:
|
||||
@ -787,8 +743,6 @@ class MatcherGroup:
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息以指定命令开头时响应。
|
||||
|
||||
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`_
|
||||
@ -824,8 +778,6 @@ class MatcherGroup:
|
||||
**kwargs,
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个支持 ``shell_like`` 解析参数的命令消息事件响应器。
|
||||
|
||||
与普通的 ``on_command`` 不同的是,在添加 ``parser`` 参数时, 响应器会自动处理消息。
|
||||
@ -862,8 +814,6 @@ class MatcherGroup:
|
||||
self, pattern: str, flags: Union[int, re.RegexFlag] = 0, **kwargs
|
||||
) -> Type[Matcher]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
注册一个消息事件响应器,并且当消息匹配正则表达式时响应。
|
||||
|
||||
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`_
|
||||
|
@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
||||
|
||||
plugins: Dict[str, "Plugin"] = {}
|
||||
"""
|
||||
:说明: 已加载的插件
|
||||
已加载的插件
|
||||
"""
|
||||
|
||||
|
||||
@ -20,42 +20,40 @@ class Plugin(object):
|
||||
|
||||
name: str
|
||||
"""
|
||||
- **说明**: 插件名称,使用 文件/文件夹 名称作为插件名
|
||||
插件名称,使用 文件/文件夹 名称作为插件名
|
||||
"""
|
||||
module: ModuleType
|
||||
"""
|
||||
- **说明**: 插件模块对象
|
||||
插件模块对象
|
||||
"""
|
||||
module_name: str
|
||||
"""
|
||||
- **说明**: 点分割模块路径
|
||||
点分割模块路径
|
||||
"""
|
||||
manager: "PluginManager"
|
||||
"""
|
||||
- **说明**: 导入该插件的插件管理器
|
||||
导入该插件的插件管理器
|
||||
"""
|
||||
export: Export = field(default_factory=Export)
|
||||
"""
|
||||
- **说明**: 插件内定义的导出内容
|
||||
插件内定义的导出内容
|
||||
"""
|
||||
matcher: Set[Type[Matcher]] = field(default_factory=set)
|
||||
"""
|
||||
- **说明**: 插件内定义的 ``Matcher``
|
||||
插件内定义的 ``Matcher``
|
||||
"""
|
||||
parent_plugin: Optional["Plugin"] = None
|
||||
"""
|
||||
- **说明**: 父插件
|
||||
父插件
|
||||
"""
|
||||
sub_plugins: Set["Plugin"] = field(default_factory=set)
|
||||
"""
|
||||
- **说明**: 子插件集合
|
||||
子插件集合
|
||||
"""
|
||||
|
||||
|
||||
def get_plugin(name: str) -> Optional[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取当前导入的某个插件。
|
||||
|
||||
:参数:
|
||||
@ -71,8 +69,6 @@ def get_plugin(name: str) -> Optional[Plugin]:
|
||||
|
||||
def get_loaded_plugins() -> Set[Plugin]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
获取当前已导入的所有插件。
|
||||
|
||||
:返回:
|
||||
|
@ -63,8 +63,6 @@ CMD_RESULT = TypedDict(
|
||||
|
||||
class Rule:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``Matcher`` 规则类,当事件传递时,在 ``Matcher`` 运行前进行检查。
|
||||
|
||||
:示例:
|
||||
@ -103,8 +101,6 @@ class Rule:
|
||||
for checker in checkers
|
||||
)
|
||||
"""
|
||||
:说明:
|
||||
|
||||
存储 ``RuleChecker``
|
||||
"""
|
||||
|
||||
@ -117,8 +113,6 @@ class Rule:
|
||||
dependency_cache: Optional[T_DependencyCache] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
检查是否符合所有规则
|
||||
|
||||
:参数:
|
||||
@ -220,8 +214,6 @@ class StartswithRule:
|
||||
|
||||
def startswith(msg: Union[str, Tuple[str, ...]], ignorecase: bool = False) -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
匹配消息开头
|
||||
|
||||
:参数:
|
||||
@ -255,8 +247,6 @@ class EndswithRule:
|
||||
|
||||
def endswith(msg: Union[str, Tuple[str, ...]], ignorecase: bool = False) -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
匹配消息结尾
|
||||
|
||||
:参数:
|
||||
@ -283,8 +273,6 @@ class KeywordsRule:
|
||||
|
||||
def keyword(*keywords: str) -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
匹配消息关键词
|
||||
|
||||
:参数:
|
||||
@ -308,8 +296,6 @@ class CommandRule:
|
||||
|
||||
def command(*cmds: Union[str, Tuple[str, ...]]) -> Rule:
|
||||
r"""
|
||||
:说明:
|
||||
|
||||
命令形式匹配,根据配置里提供的 ``command_start``, ``command_sep`` 判断消息是否为命令。
|
||||
|
||||
可以通过 ``state["_prefix"]["command"]`` 获取匹配成功的命令(例:``("test",)``),通过 ``state["_prefix"]["raw_command"]`` 获取匹配成功的原始命令文本(例:``"/test"``)。
|
||||
@ -352,8 +338,6 @@ def command(*cmds: Union[str, Tuple[str, ...]]) -> Rule:
|
||||
|
||||
class ArgumentParser(ArgParser):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``shell_like`` 命令参数解析器,解析出错时不会退出程序。
|
||||
"""
|
||||
|
||||
@ -408,8 +392,6 @@ def shell_command(
|
||||
*cmds: Union[str, Tuple[str, ...]], parser: Optional[ArgumentParser] = None
|
||||
) -> Rule:
|
||||
r"""
|
||||
:说明:
|
||||
|
||||
支持 ``shell_like`` 解析参数的命令形式匹配,根据配置里提供的 ``command_start``, ``command_sep`` 判断消息是否为命令。
|
||||
|
||||
可以通过 ``state["_prefix"]["command"]`` 获取匹配成功的命令(例:``("test",)``),通过 ``state["_prefix"]["raw_command"]`` 获取匹配成功的原始命令文本(例:``"/test"``)。
|
||||
@ -488,8 +470,6 @@ class RegexRule:
|
||||
|
||||
def regex(regex: str, flags: Union[int, re.RegexFlag] = 0) -> Rule:
|
||||
r"""
|
||||
:说明:
|
||||
|
||||
根据正则表达式进行匹配。
|
||||
|
||||
可以通过 ``state["_matched"]`` ``state["_matched_groups"]`` ``state["_matched_dict"]``
|
||||
@ -515,8 +495,6 @@ class ToMeRule:
|
||||
|
||||
def to_me() -> Rule:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
通过 ``event.is_tome()`` 判断事件是否与机器人有关
|
||||
|
||||
:参数:
|
||||
|
@ -47,35 +47,25 @@ def overrides(InterfaceClass: object):
|
||||
|
||||
T_State = Dict[Any, Any]
|
||||
"""
|
||||
:说明:
|
||||
|
||||
事件处理状态 State 类型
|
||||
"""
|
||||
|
||||
T_BotConnectionHook = Callable[["Bot"], Awaitable[None]]
|
||||
"""
|
||||
:说明:
|
||||
|
||||
Bot 连接建立时执行的函数
|
||||
"""
|
||||
T_BotDisconnectionHook = Callable[["Bot"], Awaitable[None]]
|
||||
"""
|
||||
:说明:
|
||||
|
||||
Bot 连接断开时执行的函数
|
||||
"""
|
||||
T_CallingAPIHook = Callable[["Bot", str, Dict[str, Any]], Awaitable[None]]
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``bot.call_api`` 时执行的函数
|
||||
"""
|
||||
T_CalledAPIHook = Callable[
|
||||
["Bot", Optional[Exception], str, Dict[str, Any], Any], Awaitable[None]
|
||||
]
|
||||
"""
|
||||
:说明:
|
||||
|
||||
``bot.call_api`` 后执行的函数,参数分别为 bot, exception, api, data, result
|
||||
"""
|
||||
|
||||
@ -89,8 +79,6 @@ T_EventPreProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
* ``StateParam``: State 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
事件预处理函数 EventPreProcessor 类型
|
||||
"""
|
||||
T_EventPostProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
@ -103,8 +91,6 @@ T_EventPostProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
* ``StateParam``: State 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
事件预处理函数 EventPostProcessor 类型
|
||||
"""
|
||||
T_RunPreProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
@ -118,8 +104,6 @@ T_RunPreProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
* ``MatcherParam``: Matcher 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
事件响应器运行前预处理函数 RunPreProcessor 类型
|
||||
"""
|
||||
T_RunPostProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
@ -134,8 +118,6 @@ T_RunPostProcessor = Callable[..., Union[None, Awaitable[None]]]
|
||||
* ``ExceptionParam``: 异常对象(可能为 None)
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
事件响应器运行前预处理函数 RunPostProcessor 类型,第二个参数为运行时产生的错误(如果存在)
|
||||
"""
|
||||
|
||||
@ -149,8 +131,6 @@ T_RuleChecker = Callable[..., Union[bool, Awaitable[bool]]]
|
||||
* ``StateParam``: State 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
RuleChecker 即判断是否响应事件的处理函数。
|
||||
"""
|
||||
T_PermissionChecker = Callable[..., Union[bool, Awaitable[bool]]]
|
||||
@ -162,15 +142,11 @@ T_PermissionChecker = Callable[..., Union[bool, Awaitable[bool]]]
|
||||
* ``EventParam``: Event 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
RuleChecker 即判断是否响应消息的处理函数。
|
||||
"""
|
||||
|
||||
T_Handler = Callable[..., Any]
|
||||
"""
|
||||
:说明:
|
||||
|
||||
Handler 处理函数。
|
||||
"""
|
||||
T_TypeUpdater = Callable[..., Union[str, Awaitable[str]]]
|
||||
@ -184,8 +160,6 @@ T_TypeUpdater = Callable[..., Union[str, Awaitable[str]]]
|
||||
* ``MatcherParam``: Matcher 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。默认会更新为 ``message``。
|
||||
"""
|
||||
T_PermissionUpdater = Callable[..., Union["Permission", Awaitable["Permission"]]]
|
||||
@ -199,12 +173,9 @@ T_PermissionUpdater = Callable[..., Union["Permission", Awaitable["Permission"]]
|
||||
* ``MatcherParam``: Matcher 对象
|
||||
* ``DefaultParam``: 带有默认值的参数
|
||||
|
||||
:说明:
|
||||
|
||||
PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。默认会更新为当前事件的触发对象。
|
||||
"""
|
||||
T_DependencyCache = Dict[Callable[..., Any], "Task[Any]"]
|
||||
"""
|
||||
:说明:
|
||||
依赖缓存, 用于存储依赖函数的返回值
|
||||
"""
|
||||
|
@ -31,8 +31,6 @@ V = TypeVar("V")
|
||||
|
||||
def escape_tag(s: str) -> str:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
用于记录带颜色日志时转义 ``<tag>`` 类型特殊标签
|
||||
|
||||
:参数:
|
||||
@ -90,8 +88,6 @@ def is_async_gen_callable(call: Callable[..., Any]) -> bool:
|
||||
|
||||
def run_sync(call: Callable[P, R]) -> Callable[P, Awaitable[R]]:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
一个用于包装 sync function 为 async function 的装饰器
|
||||
|
||||
:参数:
|
||||
@ -135,8 +131,6 @@ def get_name(obj: Any) -> str:
|
||||
|
||||
class DataclassEncoder(json.JSONEncoder):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
在JSON序列化 ``Message`` (List[Dataclass]) 时使用的 ``JSONEncoder``
|
||||
"""
|
||||
|
||||
@ -149,8 +143,6 @@ class DataclassEncoder(json.JSONEncoder):
|
||||
|
||||
def logger_wrapper(logger_name: str):
|
||||
"""
|
||||
:说明:
|
||||
|
||||
用于打印 adapter 的日志。
|
||||
|
||||
:log 参数:
|
||||
|
Loading…
x
Reference in New Issue
Block a user