mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 05:37:26 +08:00
📝 docs: guide, installation
This commit is contained in:
parent
4a890298db
commit
60bb6c45d2
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
**NoneBot2 尚在开发中**
|
**NoneBot2 尚在开发中**
|
||||||
|
|
||||||
NoneBot2 是一个可扩展的的 Python 异步机器人框架,它会对机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能。
|
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能。
|
||||||
|
|
||||||
除了起到解析消息的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理器,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
|
除了起到解析消息的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理器,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
|
||||||
|
|
||||||
|
@ -47,8 +47,21 @@ module.exports = context => ({
|
|||||||
selectText: "Languages",
|
selectText: "Languages",
|
||||||
editLinkText: "在 GitHub 上编辑此页",
|
editLinkText: "在 GitHub 上编辑此页",
|
||||||
lastUpdated: "上次更新",
|
lastUpdated: "上次更新",
|
||||||
nav: [{ text: "API", link: "/api/" }],
|
nav: [
|
||||||
|
{ text: "主页", link: "/" },
|
||||||
|
{ text: "指南", link: "/guide/" },
|
||||||
|
{ text: "API", link: "/api/" }
|
||||||
|
],
|
||||||
sidebar: {
|
sidebar: {
|
||||||
|
"/guide/": [
|
||||||
|
{
|
||||||
|
title: "指南",
|
||||||
|
path: "",
|
||||||
|
collapsable: false,
|
||||||
|
sidebar: "auto",
|
||||||
|
children: ["", "installation"]
|
||||||
|
}
|
||||||
|
],
|
||||||
"/api/": [
|
"/api/": [
|
||||||
{
|
{
|
||||||
title: "NoneBot Api Reference",
|
title: "NoneBot Api Reference",
|
||||||
|
@ -143,7 +143,7 @@ API_ROOT={"123456": "http://127.0.0.1:5700"}
|
|||||||
* 类型: `Optional[float]`
|
* 类型: `Optional[float]`
|
||||||
|
|
||||||
|
|
||||||
* 默认值: `60.`
|
* 默认值: `30.`
|
||||||
|
|
||||||
|
|
||||||
* 说明:
|
* 说明:
|
||||||
@ -242,3 +242,16 @@ SESSION_EXPIRE_TIMEOUT=120 # 单位: 秒
|
|||||||
SESSION_EXPIRE_TIMEOUT=[DD ][HH:MM]SS[.ffffff]
|
SESSION_EXPIRE_TIMEOUT=[DD ][HH:MM]SS[.ffffff]
|
||||||
SESSION_EXPIRE_TIMEOUT=P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
|
SESSION_EXPIRE_TIMEOUT=P[DD]DT[HH]H[MM]M[SS]S # ISO 8601
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### `apscheduler_config`
|
||||||
|
|
||||||
|
|
||||||
|
* 类型: `dict`
|
||||||
|
|
||||||
|
|
||||||
|
* 默认值: `{"apscheduler.timezone": "Asia/Shanghai"}`
|
||||||
|
|
||||||
|
|
||||||
|
* 说明:
|
||||||
|
APScheduler 的配置对象,见 [Configuring the Scheduler](https://apscheduler.readthedocs.io/en/latest/userguide.html#configuring-the-scheduler)
|
||||||
|
@ -39,8 +39,17 @@ NoneBot 使用 [loguru](https://github.com/Delgan/loguru) 来记录日志信息
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from nonebot.log import logger
|
from nonebot.log import logger
|
||||||
|
|
||||||
# 也可以这样
|
|
||||||
import logging
|
|
||||||
logger = logging.getLogger("nonebot")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## _class_ `LoguruHandler`
|
||||||
|
|
||||||
|
基类:`logging.Handler`
|
||||||
|
|
||||||
|
|
||||||
|
### `emit(record)`
|
||||||
|
|
||||||
|
Do whatever it takes to actually log the specified logging record.
|
||||||
|
|
||||||
|
This version is intended to be implemented by subclasses and so
|
||||||
|
raises a NotImplementedError.
|
||||||
|
38
docs/guide/README.md
Normal file
38
docs/guide/README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# 概览
|
||||||
|
|
||||||
|
:::tip 提示
|
||||||
|
如果在阅读本文档时遇到难以理解的词汇,请随时查阅 [术语表](../glossary.md) 或使用 [Google 搜索](https://www.google.com/)。
|
||||||
|
:::
|
||||||
|
|
||||||
|
:::tip 提示
|
||||||
|
初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。
|
||||||
|
:::
|
||||||
|
|
||||||
|
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能。
|
||||||
|
|
||||||
|
除了起到解析消息的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理器,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
|
||||||
|
|
||||||
|
目前 NoneBot2 在 [FastAPI](https://fastapi.tiangolo.com/) 的基础上封装了与 [CQHTTP(OneBot) 协议](http://cqhttp.cc/)插件的网络交互。
|
||||||
|
|
||||||
|
得益于 Python 的 [asyncio](https://docs.python.org/3/library/asyncio.html) 机制,NoneBot 处理消息的吞吐量有了很大的保障,再配合 WebSocket 通信方式(也是最建议的通信方式),NoneBot 的性能可以达到 HTTP 通信方式的两倍以上,相较于传统同步 I/O 的 HTTP 通信,更是有质的飞跃。
|
||||||
|
|
||||||
|
需要注意的是,NoneBot 仅支持 Python 3.7+ 及 CQHTTP(OneBot) 插件 v11+。
|
||||||
|
|
||||||
|
## 它如何工作?
|
||||||
|
|
||||||
|
NoneBot 的运行离不开 酷 Q 和 CQHTTP 插件。酷 Q 扮演着「无头 QQ 客户端」的角色,它进行实际的消息、通知、请求的接收和发送,当 酷 Q 收到消息时,它将这个消息包装为一个事件(通知和请求同理),并通过它自己的插件机制将事件传送给 CQHTTP 插件,后者再根据其配置中的 `post_url` 或 `ws_reverse_url` 等项来将事件发送至 NoneBot。
|
||||||
|
|
||||||
|
在 NoneBot 收到事件前,它底层的 aiocqhttp 实际已经先看到了事件,aiocqhttp 根据事件的类型信息,通知到 NoneBot 的相应函数。特别地,对于消息类型的事件,还将消息内容转换成了 `aiocqhttp.message.Message` 类型,以便处理。
|
||||||
|
|
||||||
|
NoneBot 的事件处理函数收到通知后,对于不同类型的事件,再做相应的预处理和解析,然后调用对应的插件,并向其提供适合此类事件的会话(Session)对象。NoneBot 插件的编写者要做的,就是利用 Session 对象中提供的数据,在插件的处理函数中实现所需的功能。
|
||||||
|
|
||||||
|
## 特色
|
||||||
|
|
||||||
|
- 提供直观的测试前端
|
||||||
|
- 提供使用简易的脚手架
|
||||||
|
- 基于异步 I/O
|
||||||
|
- 同时支持 HTTP 和反向 WebSocket 通信方式
|
||||||
|
- 支持多个机器人账号负载均衡
|
||||||
|
- 提供直观的交互式会话接口
|
||||||
|
- 提供可自定义的权限控制机制
|
||||||
|
- 多种方式渲染要发送的消息内容,使对话足够自然
|
72
docs/guide/installation.md
Normal file
72
docs/guide/installation.md
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# 安装
|
||||||
|
|
||||||
|
## NoneBot
|
||||||
|
|
||||||
|
:::warning 注意
|
||||||
|
请确保你的 Python 版本 >= 3.7。
|
||||||
|
:::
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install nonebot2
|
||||||
|
```
|
||||||
|
|
||||||
|
如果你需要使用最新的(可能尚未发布的)特性,可以克隆 Git 仓库后手动安装:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/nonebot/nonebot2.git
|
||||||
|
cd nonebot2
|
||||||
|
pip install .
|
||||||
|
```
|
||||||
|
|
||||||
|
## 额外依赖
|
||||||
|
|
||||||
|
### APScheduler
|
||||||
|
|
||||||
|
A task scheduling library for Python.
|
||||||
|
|
||||||
|
可用于定时任务,后台执行任务等
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install nonebot2[scheduler]
|
||||||
|
poetry add nonebot2[scheduler]
|
||||||
|
```
|
||||||
|
|
||||||
|
[View On GitHub](https://github.com/agronholm/apscheduler)
|
||||||
|
|
||||||
|
### NoneBot-Test
|
||||||
|
|
||||||
|
A test frontend for nonebot2.
|
||||||
|
|
||||||
|
通过前端展示 nonebot 已加载的插件以及运行状态,同时可以用于模拟发送事件测试机器人
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install nonebot2[test]
|
||||||
|
poetry add nonebot2[test]
|
||||||
|
```
|
||||||
|
|
||||||
|
[View On GitHub](https://github.com/nonebot/nonebot-test)
|
||||||
|
|
||||||
|
### CLI
|
||||||
|
|
||||||
|
CLI for nonebot2.
|
||||||
|
|
||||||
|
一个多功能脚手架
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install nonebot2[cli]
|
||||||
|
poetry add nonebot2[cli]
|
||||||
|
```
|
||||||
|
|
||||||
|
[View On GitHub](https://github.com/yanyongyu/nb-cli)
|
||||||
|
|
||||||
|
### 我全都要
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install nonebot2[full]
|
||||||
|
poetry add nonebot2[full]
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install nonebot2[cli,scheduler]
|
||||||
|
poetry add nonebot2[cli,scheduler]
|
||||||
|
```
|
@ -1,12 +1,12 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "nonebot"
|
name = "nonebot2"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
description = "An asynchronous python bot framework."
|
description = "An asynchronous python bot framework."
|
||||||
authors = ["yanyongyu <yanyongyu_1@126.com>"]
|
authors = ["yanyongyu <yanyongyu_1@126.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
homepage = "https://docs.nonebot.dev/"
|
homepage = "https://docs.nonebot.dev/"
|
||||||
repository = "https://github.com/nonebot/nonebot"
|
repository = "https://github.com/nonebot/nonebot2"
|
||||||
documentation = "https://docs.nonebot.dev/"
|
documentation = "https://docs.nonebot.dev/"
|
||||||
keywords = ["bot", "qq", "qqbot", "mirai", "coolq"]
|
keywords = ["bot", "qq", "qqbot", "mirai", "coolq"]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
@ -22,22 +22,25 @@ include = ["nonebot/py.typed"]
|
|||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.7"
|
python = "^3.7"
|
||||||
httpx = "^0.13.3"
|
httpx = "^0.13.3"
|
||||||
|
loguru = "^0.5.1"
|
||||||
pygtrie = "^2.3.3"
|
pygtrie = "^2.3.3"
|
||||||
fastapi = "^0.58.1"
|
fastapi = "^0.58.1"
|
||||||
uvicorn = "^0.11.5"
|
uvicorn = "^0.11.5"
|
||||||
pydantic = { extras = ["dotenv"], version = "^1.6.1" }
|
pydantic = { extras = ["dotenv"], version = "^1.6.1" }
|
||||||
apscheduler = { version = "^3.6.3", optional = true }
|
apscheduler = { version = "^3.6.3", optional = true }
|
||||||
# nonebot-test = { version = "^0.1.0", optional = true }
|
# nonebot-test = { version = "^0.1.0", optional = true }
|
||||||
|
# nb-cli = { version="^0.1.0", optional = true }
|
||||||
|
|
||||||
loguru = "^0.5.1"
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
yapf = "^0.30.0"
|
yapf = "^0.30.0"
|
||||||
sphinx = "^3.1.1"
|
sphinx = "^3.1.1"
|
||||||
sphinx-markdown-builder = { git = "https://github.com/nonebot/sphinx-markdown-builder.git" }
|
sphinx-markdown-builder = { git = "https://github.com/nonebot/sphinx-markdown-builder.git" }
|
||||||
|
|
||||||
[tool.poetry.extras]
|
[tool.poetry.extras]
|
||||||
|
# cli = ["nb-cli"]
|
||||||
# test = ["nonebot-test"]
|
# test = ["nonebot-test"]
|
||||||
scheduler = ["apscheduler"]
|
scheduler = ["apscheduler"]
|
||||||
|
full = ["nb-cli", "nonebot-test", "scheduler"]
|
||||||
|
|
||||||
[[tool.poetry.source]]
|
[[tool.poetry.source]]
|
||||||
name = "aliyun"
|
name = "aliyun"
|
||||||
|
Loading…
Reference in New Issue
Block a user