diff --git a/.github/workflows/api_docs.yml b/.github/workflows/api_docs.yml index 18d3085e..ac01aa18 100644 --- a/.github/workflows/api_docs.yml +++ b/.github/workflows/api_docs.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} - + - name: Set up Python uses: actions/setup-python@v2 with: @@ -27,10 +27,10 @@ jobs: - name: Build Doc run: poetry run sphinx-build -M markdown ./docs_build ./build - + - name: Copy Files run: cp -r ./build/markdown/* ./docs/api/ - + - run: | git config user.name nonebot git config user.email nonebot@nonebot.dev diff --git a/README.md b/README.md index 78caed43..31fd5ac3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@
- + # NoneBot -[![License](https://img.shields.io/github/license/richardchien/nonebot.svg)](LICENSE) -[![PyPI](https://img.shields.io/pypi/v/nonebot.svg)](https://pypi.python.org/pypi/nonebot) +[![License](https://img.shields.io/github/license/nonebot/nonebot2.svg)](LICENSE) +[![PyPI](https://img.shields.io/pypi/v/nonebot2.svg)](https://pypi.python.org/pypi/nonebot2) ![Python Version](https://img.shields.io/badge/python-3.7+-blue.svg) ![CQHTTP Version](https://img.shields.io/badge/cqhttp-11+-black.svg) [![QQ 群](https://img.shields.io/badge/qq%E7%BE%A4-768887710-orange.svg)](https://jq.qq.com/?_wv=1027&k=5OFifDh) @@ -16,8 +16,6 @@ ## 简介 -**NoneBot2 尚在开发中** - NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能。 除了起到解析消息的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理器,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。 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/components/Messenger.vue b/docs/.vuepress/components/Messenger.vue index 7c12d979..030e2188 100644 --- a/docs/.vuepress/components/Messenger.vue +++ b/docs/.vuepress/components/Messenger.vue @@ -1,7 +1,7 @@