🔀 Merge pull request #188

update doc
This commit is contained in:
Ju4tCode 2021-02-02 22:01:49 +08:00 committed by GitHub
commit 78b0450d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 34 additions and 30 deletions

View File

@ -3,7 +3,7 @@ const path = require("path");
module.exports = context => ({ module.exports = context => ({
base: process.env.VUEPRESS_BASE || "/", base: process.env.VUEPRESS_BASE || "/",
title: "NoneBot", title: "NoneBot",
description: "基于 酷Q 的 Python 异步 QQ 机器人框架", description: "跨平台 Python 异步 QQ 机器人框架",
markdown: { markdown: {
lineNumbers: true lineNumbers: true
}, },
@ -56,7 +56,7 @@ module.exports = context => ({
"/": { "/": {
lang: "zh-CN", lang: "zh-CN",
title: "NoneBot", title: "NoneBot",
description: "基于 酷Q 的 Python 异步 QQ 机器人框架" description: "跨平台 Python 异步 QQ 机器人框架"
} }
}, },

View File

@ -3,7 +3,7 @@
"short_name": "NoneBot", "short_name": "NoneBot",
"background-color": "#ffffff", "background-color": "#ffffff",
"theme-color": "#ea5252", "theme-color": "#ea5252",
"description": "An asynchronous python bot framework.", "description": "跨平台 Python 异步 QQ 机器人框架",
"display": "standalone", "display": "standalone",
"icons": [ "icons": [
{ {

View File

@ -1,7 +1,7 @@
--- ---
home: true home: true
heroImage: /logo.png heroImage: /logo.png
tagline: An asynchronous bot framework. tagline: 跨平台 Python 异步 QQ 机器人框架
actionText: 开始使用 actionText: 开始使用
actionLink: guide/ actionLink: guide/
features: features:

View File

@ -1 +1 @@
# 运行时插槽 # 钩子函数

View File

@ -4,7 +4,7 @@
> Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline. > Advanced Python Scheduler (APScheduler) is a Python library that lets you schedule your Python code to be executed later, either just once or periodically. You can add new jobs or remove old ones on the fly as you please. If you store your jobs in a database, they will also survive scheduler restarts and maintain their state. When the scheduler is restarted, it will then run all the jobs it should have run while it was offline.
## 从 v1 迁移 ## 从 NoneBot v1 迁移
`APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/plugin-store.html) 中找到它。 `APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/plugin-store.html) 中找到它。
@ -21,7 +21,7 @@ nb plugin install nonebot_plugin_apscheduler
``` ```
:::tip 提示 :::tip 提示
`nb-cli` 默认通过 `pypi` 安装,你可以使用 `-i [mirror]``--index [mirror]`使用镜像源安装。 `nb-cli` 默认通过 `pypi` 安装,你可以添加命令参数 `-i [mirror]``--index [mirror]`使用镜像源安装。
::: :::
### 通过 poetry ### 通过 poetry
@ -96,10 +96,14 @@ scheduler = require('nonebot_plugin_apscheduler').scheduler
对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true` 对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true`
##### 在 `.env` 中添加
```bash ```bash
APSCHEDULER_AUTOSTART=true APSCHEDULER_AUTOSTART=true
``` ```
##### 在 `bot.py` 中添加
```python ```python
nonebot.init(apscheduler_autostart=True) nonebot.init(apscheduler_autostart=True)
``` ```
@ -116,10 +120,14 @@ nonebot.init(apscheduler_autostart=True)
> 官方文档在绝大多数时候能提供最准确和最具时效性的指南 > 官方文档在绝大多数时候能提供最准确和最具时效性的指南
##### 在 `.env` 中添加
```bash ```bash
APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"} APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"}
``` ```
##### 在 `bot.py` 中添加
```python ```python
nonebot.init(apscheduler_config={ nonebot.init(apscheduler_config={
"apscheduler.timezone": "Asia/Shanghai" "apscheduler.timezone": "Asia/Shanghai"

View File

@ -8,8 +8,6 @@
初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。 初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。
::: :::
## 简介
NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。 NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。
除了起到解析事件的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。 除了起到解析事件的作用NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。

View File

@ -2,7 +2,7 @@
到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。 到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。
在上一章节中,我们创建了默认的项目结构,其中 `.env`, `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。 在上一章节中,我们创建了默认的项目结构,其中 `.env` `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。
:::danger 警告 :::danger 警告
请勿将敏感信息写入配置文件并提交至开源仓库! 请勿将敏感信息写入配置文件并提交至开源仓库!
@ -83,4 +83,4 @@ config.custom_config4 = "new config after init"
## 优先级 ## 优先级
`bot.py init` > `system env` > `env file` `bot.py` 文件( `nonebot.init` ) > 系统环境变量 > `.env` `.env.*` 文件

View File

@ -34,18 +34,18 @@ AweSome-Bot
## 启动 Bot ## 启动 Bot
如果你使用 `nb-cli` 通过 `nb-cli`
```bash ```bash
nb run [--file=bot.py] [--app=app] nb run [--file=bot.py] [--app=app]
``` ```
者使用
```bash ```bash
python bot.py python bot.py
``` ```
:::tip 提示 :::tip 提示
如果在 bot 入口文件内定义了 asgi server `nb-cli` 将会为你启动**冷重载模式** 如果在 bot 入口文件内定义了 asgi server `nb-cli` 将会为你启动**冷重载模式**(当文件发生变动时自动重启 NoneBot 实例)
::: :::

View File

@ -1,16 +1,16 @@
# 开始使用 # 开始使用
一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备。 一切都安装成功后,你就已经做好了进行简单配置以运行一个最小的 NoneBot 实例的准备工作
## 最小实例 ## 最小实例
如果你已经按照推荐方式安装了 `nb-cli`,使用脚手架创建一个空项目: 如果你已经按照推荐方式安装了 `nb-cli`,使用创建一个空项目:
```bash ```bash
nb create nb create
``` ```
根据脚手架引导,将在当前目录下创建一个项目目录,项目目录内包含 `bot.py` 根据引导进行项目配置,完成后会在当前目录下创建一个项目目录,项目目录内包含 `bot.py`
如果未安装 `nb-cli`,使用你最熟悉的编辑器或 IDE创建一个名为 `bot.py` 的文件,内容如下(这里以 CQHTTP 适配器为例): 如果未安装 `nb-cli`,使用你最熟悉的编辑器或 IDE创建一个名为 `bot.py` 的文件,内容如下(这里以 CQHTTP 适配器为例):

View File

@ -7,7 +7,7 @@
::: :::
:::warning 注意 :::warning 注意
请在安装 nonebot2 之前卸载 nonebot 1.x 请在安装 NoneBot v2 之前卸载 NoneBot v1
```bash ```bash
pip uninstall nonebot pip uninstall nonebot
@ -15,10 +15,10 @@ pip uninstall nonebot
::: :::
### 通过脚手架安装(推荐安装方式) ### (推荐安装方式)通过脚手架安装
1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境 1. (推荐)使用你喜欢的 Python 环境管理工具(如 `poetry`)创建新的虚拟环境
2. 使用 `pip` (或其他包管理工具) 安装 nb-clinonebot2 作为其依赖会一起被安装。 2. 使用 `pip` 或 其他包管理工具 安装 `nb-cli``nonebot2` 会作为其依赖被一起安装
```bash ```bash
pip install nb-cli pip install nb-cli
@ -26,7 +26,7 @@ pip uninstall nonebot
3. 点个 star 吧 3. 点个 star 吧
nonebot2: [![nb-cli](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2) nonebot2: [![nonebot2](https://img.shields.io/github/stars/nonebot/nonebot2?style=social)](https://github.com/nonebot/nonebot2)
nb-cli: [![nb-cli](https://img.shields.io/github/stars/nonebot/nb-cli?style=social)](https://github.com/nonebot/nb-cli) nb-cli: [![nb-cli](https://img.shields.io/github/stars/nonebot/nb-cli?style=social)](https://github.com/nonebot/nb-cli)
@ -36,7 +36,7 @@ pip uninstall nonebot
[![Telegram Chat](https://img.shields.io/badge/telegram-cqhttp-blue?style=social)](https://t.me/cqhttp) [![Telegram Chat](https://img.shields.io/badge/telegram-cqhttp-blue?style=social)](https://t.me/cqhttp)
### 不使用脚手架(纯净安装) ### (纯净安装)不使用脚手架
```bash ```bash
pip install nonebot2 pip install nonebot2
@ -84,8 +84,6 @@ nb plugin install xxx
### 官方插件 ### 官方插件
~~自用插件~~ ~~确信~~
- [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs) 离线文档插件 - [NoneBot-Plugin-Docs](https://github.com/nonebot/nonebot2/tree/master/packages/nonebot-plugin-docs) 离线文档插件
- [NoneBot-Plugin-Test](https://github.com/nonebot/plugin-test) 本地机器人测试前端插件 - [NoneBot-Plugin-Test](https://github.com/nonebot/plugin-test) 本地机器人测试前端插件
- [NoneBot-Plugin-APScheduler](https://github.com/nonebot/plugin-apscheduler) 定时任务插件 - [NoneBot-Plugin-APScheduler](https://github.com/nonebot/plugin-apscheduler) 定时任务插件

View File

@ -4,7 +4,7 @@
Mirai-API-HTTP 的适配现在仍然处于早期阶段, 可能没有进行过充分的测试 Mirai-API-HTTP 的适配现在仍然处于早期阶段, 可能没有进行过充分的测试
在生产环境中谨慎使用 在生产环境中谨慎使用
::: :::
@ -34,7 +34,7 @@ Mirai-API-HTTP 的适配器以 [AGPLv3 许可](https://opensource.org/licenses/A
> 单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。 > 单纯运行 NoneBot 实例并不会产生任何效果,因为此刻 QQ 这边还不知道 NoneBot 的存在,也就无法把消息发送给它,因此现在需要使用一个无头 QQ 来把消息等事件上报给 NoneBot。
这次, 我们将采用在实现上有别于 onebot<sup>即 CQHTTP</sup>协议的另外一种无头 QQ API 协议, 即 MAH 这次, 我们将采用在实现上有别于 OneBotCQHTTP协议的另外一种无头 QQ API 协议, 即 MAH
为了配置 MAH 端, 我们现在需要移步到[MAH 的项目地址](https://github.com/project-mirai/mirai-api-http), 来看看它是如何配置的 为了配置 MAH 端, 我们现在需要移步到[MAH 的项目地址](https://github.com/project-mirai/mirai-api-http), 来看看它是如何配置的