From 10169866635fc06a32ff771134bb25be94739091 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Thu, 1 Oct 2020 00:55:03 +0800 Subject: [PATCH] :bookmark: Pre Release 2.0.0a2 --- archive/{2.0.0a1 => 2.0.0a2}/README.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/README.md | 3 + archive/2.0.0a2/api/adapters/README.md | 41 ++ archive/2.0.0a2/api/adapters/cqhttp.md | 411 ++++++++++++++++++ archive/{2.0.0a1 => 2.0.0a2}/api/config.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/exception.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/log.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/nonebot.md | 0 .../{2.0.0a1 => 2.0.0a2}/api/permission.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/rule.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/sched.md | 0 archive/{2.0.0a1 => 2.0.0a2}/api/typing.md | 16 + archive/{2.0.0a1 => 2.0.0a2}/api/utils.md | 23 + archive/{2.0.0a1 => 2.0.0a2}/guide/README.md | 0 .../guide/basic-configuration.md | 0 .../guide/creating-a-project.md | 0 .../guide/getting-started.md | 0 .../guide/installation.md | 0 .../guide/writing-a-plugin.md | 2 +- .../{2.0.0a1 => 2.0.0a2}/sidebar.config.json | 8 + docs/.vuepress/versions.json | 2 +- docs/api/utils.md | 23 + docs_build/utils.rst | 1 + nonebot/utils.py | 2 +- 24 files changed, 529 insertions(+), 3 deletions(-) rename archive/{2.0.0a1 => 2.0.0a2}/README.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/README.md (87%) create mode 100644 archive/2.0.0a2/api/adapters/README.md create mode 100644 archive/2.0.0a2/api/adapters/cqhttp.md rename archive/{2.0.0a1 => 2.0.0a2}/api/config.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/exception.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/log.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/nonebot.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/permission.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/rule.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/sched.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/api/typing.md (94%) rename archive/{2.0.0a1 => 2.0.0a2}/api/utils.md (70%) rename archive/{2.0.0a1 => 2.0.0a2}/guide/README.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/guide/basic-configuration.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/guide/creating-a-project.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/guide/getting-started.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/guide/installation.md (100%) rename archive/{2.0.0a1 => 2.0.0a2}/guide/writing-a-plugin.md (99%) rename archive/{2.0.0a1 => 2.0.0a2}/sidebar.config.json (89%) diff --git a/archive/2.0.0a1/README.md b/archive/2.0.0a2/README.md similarity index 100% rename from archive/2.0.0a1/README.md rename to archive/2.0.0a2/README.md diff --git a/archive/2.0.0a1/api/README.md b/archive/2.0.0a2/api/README.md similarity index 87% rename from archive/2.0.0a1/api/README.md rename to archive/2.0.0a2/api/README.md index 2fa1066a..1c8acf1b 100644 --- a/archive/2.0.0a1/api/README.md +++ b/archive/2.0.0a2/api/README.md @@ -29,3 +29,6 @@ * [nonebot.exception](exception.html) + + + * [nonebot.adapters.cqhttp](adapters/cqhttp.html) diff --git a/archive/2.0.0a2/api/adapters/README.md b/archive/2.0.0a2/api/adapters/README.md new file mode 100644 index 00000000..b6529990 --- /dev/null +++ b/archive/2.0.0a2/api/adapters/README.md @@ -0,0 +1,41 @@ +--- +contentSidebar: true +sidebarDepth: 0 +--- + +# NoneBot.adapters 模块 + + +## _class_ `BaseBot` + +基类:`abc.ABC` + + +## _class_ `BaseEvent` + +基类:`abc.ABC` + + +### `_raw_event` + +原始 event + + +## _class_ `BaseMessageSegment` + +基类:`abc.ABC` + + +## _class_ `BaseMessage` + +基类:`list`, `abc.ABC` + + +### `append(obj)` + +Append object to the end of the list. + + +### `extend(obj)` + +Extend list by appending elements from the iterable. diff --git a/archive/2.0.0a2/api/adapters/cqhttp.md b/archive/2.0.0a2/api/adapters/cqhttp.md new file mode 100644 index 00000000..53fa04f9 --- /dev/null +++ b/archive/2.0.0a2/api/adapters/cqhttp.md @@ -0,0 +1,411 @@ +--- +contentSidebar: true +sidebarDepth: 0 +--- + +# NoneBot.adapters.cqhttp 模块 + +## CQHTTP (OneBot) v11 协议适配 + +协议详情请看: [CQHTTP](http://cqhttp.cc/) | [OneBot](https://github.com/howmanybots/onebot) + + +## `log(level, message)` + + +* **说明** + + 用于打印 CQHTTP 日志。 + + + +* **参数** + + + * `level: str`: 日志等级 + + + * `message: str`: 日志信息 + + + +## `escape(s, *, escape_comma=True)` + + +* **说明** + + 对字符串进行 CQ 码转义。 + + + +* **参数** + + + * `s: str`: 需要转义的字符串 + + + * `escape_comma: bool`: 是否转义逗号(`,`)。 + + + +## `unescape(s)` + + +* **说明** + + 对字符串进行 CQ 码去转义。 + + + +* **参数** + + + * `s: str`: 需要转义的字符串 + + + +## `_b2s(b)` + +转换布尔值为字符串。 + + +## _async_ `_check_reply(bot, event)` + + +* **说明** + + 检查消息中存在的回复,去除并赋值 `event.reply`, `event.to_me` + + + +* **参数** + + + * `bot: Bot`: Bot 对象 + + + * `event: Event`: Event 对象 + + + +## `_check_at_me(bot, event)` + + +* **说明** + + 检查消息开头或结尾是否存在 @机器人,去除并赋值 `event.to_me` + + + +* **参数** + + + * `bot: Bot`: Bot 对象 + + + * `event: Event`: Event 对象 + + + +## `_check_nickname(bot, event)` + + +* **说明** + + 检查消息开头是否存在,去除并赋值 `event.to_me` + + + +* **参数** + + + * `bot: Bot`: Bot 对象 + + + * `event: Event`: Event 对象 + + + +## `_handle_api_result(result)` + + +* **说明** + + 处理 API 请求返回值。 + + + +* **参数** + + + * `result: Optional[Dict[str, Any]]`: API 返回数据 + + + +* **返回** + + + * `Any`: API 调用返回数据 + + + +* **异常** + + + * `ActionFailed`: API 调用失败 + + + +## _class_ `Bot` + +基类:[`nonebot.adapters.BaseBot`](#None) + +CQHTTP 协议 Bot 适配。继承属性参考 [BaseBot](./#class-basebot) 。 + + +### _property_ `type` + + +* 返回: `"cqhttp"` + + +### _async_ `handle_message(message)` + + +* **说明** + + 调用 [_check_reply](#async-check-reply-bot-event), [_check_at_me](#check-at-me-bot-event), [_check_nickname](#check-nickname-bot-event) 处理事件并转换为 [Event](#class-event) + + + +### _async_ `call_api(api, **data)` + + +* **说明** + + 调用 CQHTTP 协议 API + + + +* **参数** + + + * `api: str`: API 名称 + + + * `**data: Any`: API 参数 + + + +* **返回** + + + * `Any`: API 调用返回数据 + + + +* **异常** + + + * `NetworkError`: 网络错误 + + + * `ActionFailed`: API 调用失败 + + + +### _async_ `send(event, message, at_sender=False, **kwargs)` + + +* **说明** + + 根据 `event` 向触发事件的主体发送消息。 + + + +* **参数** + + + * `event: Event`: Event 对象 + + + * `message: Union[str, Message, MessageSegment]`: 要发送的消息 + + + * `at_sender: bool`: 是否 @ 事件主体 + + + * `**kwargs`: 覆盖默认参数 + + + +* **返回** + + + * `Any`: API 调用返回数据 + + + +* **异常** + + + * `ValueError`: 缺少 `user_id`, `group_id` + + + * `NetworkError`: 网络错误 + + + * `ActionFailed`: API 调用失败 + + + +## _class_ `Event` + +基类:[`nonebot.adapters.BaseEvent`](#None) + +CQHTTP 协议 Event 适配。继承属性参考 [BaseEvent](./#class-baseevent) 。 + + +### _property_ `id` + + +* 类型: `Optional[int]` + + +* 说明: 事件/消息 ID + + +### _property_ `name` + + +* 类型: `str` + + +* 说明: 事件名称,由类型与 `.` 组合而成 + + +### _property_ `self_id` + + +* 类型: `str` + + +* 说明: 机器人自身 ID + + +### _property_ `time` + + +* 类型: `int` + + +* 说明: 事件发生时间 + + +### _property_ `type` + + +* 类型: `str` + + +* 说明: 事件类型 + + +### _property_ `detail_type` + + +* 类型: `str` + + +* 说明: 事件详细类型 + + +### _property_ `sub_type` + + +* 类型: `str` + + +* 说明: 事件类型 + + +### _property_ `user_id` + + +* 类型: `Optional[int]` + + +* 说明: 事件主体 ID + + +### _property_ `group_id` + + +* 类型: `Optional[int]` + + +* 说明: 事件主体群 ID + + +### _property_ `to_me` + + +* 类型: `Optional[bool]` + + +* 说明: 消息是否与机器人相关 + + +### _property_ `message` + + +* 类型: `Optional[Message]` + + +* 说明: 消息内容 + + +### _property_ `reply` + + +* 类型: `Optional[dict]` + + +* 说明: 回复消息详情 + + +### _property_ `raw_message` + + +* 类型: `Optional[str]` + + +* 说明: 原始消息 + + +### _property_ `plain_text` + + +* 类型: `Optional[str]` + + +* 说明: 纯文本消息内容 + + +### _property_ `sender` + + +* 类型: `Optional[dict]` + + +* 说明: 消息发送者信息 + + +## _class_ `MessageSegment` + +基类:[`nonebot.adapters.BaseMessageSegment`](#None) + + +## _class_ `Message` + +基类:[`nonebot.adapters.BaseMessage`](#None) diff --git a/archive/2.0.0a1/api/config.md b/archive/2.0.0a2/api/config.md similarity index 100% rename from archive/2.0.0a1/api/config.md rename to archive/2.0.0a2/api/config.md diff --git a/archive/2.0.0a1/api/exception.md b/archive/2.0.0a2/api/exception.md similarity index 100% rename from archive/2.0.0a1/api/exception.md rename to archive/2.0.0a2/api/exception.md diff --git a/archive/2.0.0a1/api/log.md b/archive/2.0.0a2/api/log.md similarity index 100% rename from archive/2.0.0a1/api/log.md rename to archive/2.0.0a2/api/log.md diff --git a/archive/2.0.0a1/api/nonebot.md b/archive/2.0.0a2/api/nonebot.md similarity index 100% rename from archive/2.0.0a1/api/nonebot.md rename to archive/2.0.0a2/api/nonebot.md diff --git a/archive/2.0.0a1/api/permission.md b/archive/2.0.0a2/api/permission.md similarity index 100% rename from archive/2.0.0a1/api/permission.md rename to archive/2.0.0a2/api/permission.md diff --git a/archive/2.0.0a1/api/rule.md b/archive/2.0.0a2/api/rule.md similarity index 100% rename from archive/2.0.0a1/api/rule.md rename to archive/2.0.0a2/api/rule.md diff --git a/archive/2.0.0a1/api/sched.md b/archive/2.0.0a2/api/sched.md similarity index 100% rename from archive/2.0.0a1/api/sched.md rename to archive/2.0.0a2/api/sched.md diff --git a/archive/2.0.0a1/api/typing.md b/archive/2.0.0a2/api/typing.md similarity index 94% rename from archive/2.0.0a1/api/typing.md rename to archive/2.0.0a2/api/typing.md index f68bdfcb..72d66f23 100644 --- a/archive/2.0.0a1/api/typing.md +++ b/archive/2.0.0a2/api/typing.md @@ -142,6 +142,22 @@ sidebarDepth: 0 +## `MatcherGroup` + + +* **类型** + + `MatcherGroup` + + + +* **说明** + + MatcherGroup 为 Matcher 的集合。可以共享 Handler。 + + + + ## `Rule` diff --git a/archive/2.0.0a1/api/utils.md b/archive/2.0.0a2/api/utils.md similarity index 70% rename from archive/2.0.0a1/api/utils.md rename to archive/2.0.0a2/api/utils.md index 7de3ba3f..ed98fab9 100644 --- a/archive/2.0.0a1/api/utils.md +++ b/archive/2.0.0a2/api/utils.md @@ -6,6 +6,29 @@ sidebarDepth: 0 # NoneBot.utils 模块 +## `escape_tag(s)` + + +* **说明** + + 用于记录带颜色日志时转义 `` 类型特殊标签 + + + +* **参数** + + + * `s: str`: 需要转义的字符串 + + + +* **返回** + + + * `str` + + + ## `run_sync(func)` diff --git a/archive/2.0.0a1/guide/README.md b/archive/2.0.0a2/guide/README.md similarity index 100% rename from archive/2.0.0a1/guide/README.md rename to archive/2.0.0a2/guide/README.md diff --git a/archive/2.0.0a1/guide/basic-configuration.md b/archive/2.0.0a2/guide/basic-configuration.md similarity index 100% rename from archive/2.0.0a1/guide/basic-configuration.md rename to archive/2.0.0a2/guide/basic-configuration.md diff --git a/archive/2.0.0a1/guide/creating-a-project.md b/archive/2.0.0a2/guide/creating-a-project.md similarity index 100% rename from archive/2.0.0a1/guide/creating-a-project.md rename to archive/2.0.0a2/guide/creating-a-project.md diff --git a/archive/2.0.0a1/guide/getting-started.md b/archive/2.0.0a2/guide/getting-started.md similarity index 100% rename from archive/2.0.0a1/guide/getting-started.md rename to archive/2.0.0a2/guide/getting-started.md diff --git a/archive/2.0.0a1/guide/installation.md b/archive/2.0.0a2/guide/installation.md similarity index 100% rename from archive/2.0.0a1/guide/installation.md rename to archive/2.0.0a2/guide/installation.md diff --git a/archive/2.0.0a1/guide/writing-a-plugin.md b/archive/2.0.0a2/guide/writing-a-plugin.md similarity index 99% rename from archive/2.0.0a1/guide/writing-a-plugin.md rename to archive/2.0.0a2/guide/writing-a-plugin.md index bd176750..42657d9d 100644 --- a/archive/2.0.0a1/guide/writing-a-plugin.md +++ b/archive/2.0.0a2/guide/writing-a-plugin.md @@ -159,7 +159,7 @@ weather = on_command("天气", rule=to_me(), permission=Permission(), priority=5 - `on_startswith(str)` ~ `on("message", startswith(str))`: 消息开头匹配处理器 - `on_endswith(str)` ~ `on("message", endswith(str))`: 消息结尾匹配处理器 - `on_command(str|tuple)` ~ `on("message", command(str|tuple))`: 命令处理器 -- `on_regax(pattern_str)` ~ `on("message", regax(pattern_str))`: 正则匹配处理器 +- `on_regex(pattern_str)` ~ `on("message", regex(pattern_str))`: 正则匹配处理器 #### 匹配规则 rule diff --git a/archive/2.0.0a1/sidebar.config.json b/archive/2.0.0a2/sidebar.config.json similarity index 89% rename from archive/2.0.0a1/sidebar.config.json rename to archive/2.0.0a2/sidebar.config.json index 9dd289f1..bec088a6 100644 --- a/archive/2.0.0a1/sidebar.config.json +++ b/archive/2.0.0a2/sidebar.config.json @@ -78,6 +78,14 @@ { "title": "nonebot.exception 模块", "path": "exception" + }, + { + "title": "nonebot.adapters 模块", + "path": "adapters/" + }, + { + "title": "nonebot.adapters.cqhttp 模块", + "path": "adapters/cqhttp" } ] } diff --git a/docs/.vuepress/versions.json b/docs/.vuepress/versions.json index 76e10341..386fcf77 100644 --- a/docs/.vuepress/versions.json +++ b/docs/.vuepress/versions.json @@ -1,3 +1,3 @@ [ - "2.0.0a1" + "2.0.0a2" ] \ No newline at end of file diff --git a/docs/api/utils.md b/docs/api/utils.md index 7de3ba3f..ed98fab9 100644 --- a/docs/api/utils.md +++ b/docs/api/utils.md @@ -6,6 +6,29 @@ sidebarDepth: 0 # NoneBot.utils 模块 +## `escape_tag(s)` + + +* **说明** + + 用于记录带颜色日志时转义 `` 类型特殊标签 + + + +* **参数** + + + * `s: str`: 需要转义的字符串 + + + +* **返回** + + + * `str` + + + ## `run_sync(func)` diff --git a/docs_build/utils.rst b/docs_build/utils.rst index 776bbfd0..b7609fdc 100644 --- a/docs_build/utils.rst +++ b/docs_build/utils.rst @@ -7,6 +7,7 @@ NoneBot.utils 模块 ================== +.. autofunction:: nonebot.utils.escape_tag .. autodecorator:: nonebot.utils.run_sync .. autoclass:: nonebot.utils.DataclassEncoder :show-inheritance: diff --git a/nonebot/utils.py b/nonebot/utils.py index aa718819..9efeb8ca 100644 --- a/nonebot/utils.py +++ b/nonebot/utils.py @@ -13,7 +13,7 @@ from nonebot.typing import Any, Callable, Awaitable, overrides def escape_tag(s: str) -> str: """ :说明: - 用于记录带颜色日志时转义 `` 类型特殊标签 + 用于记录带颜色日志时转义 ```` 类型特殊标签 :参数: * ``s: str``: 需要转义的字符串 :返回: