Skip to content

Commit

Permalink
🔀 Merge pull request #194
Browse files Browse the repository at this point in the history
Pre Release 2.0.0a9.post1
  • Loading branch information
yanyongyu committed Feb 5, 2021
2 parents 3460d44 + f2d04c5 commit 050137f
Show file tree
Hide file tree
Showing 73 changed files with 469 additions and 248 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ NoneBot2 的驱动框架 `Driver` 以及通信协议 `Adapter` 均可**自定义

- [OneBot(CQHTTP) 协议](https://github.com/howmanybots/onebot/blob/master/README.md) (QQ 等)
- [Mirai-API-HTTP 协议](https://github.com/project-mirai/mirai-api-http)
- [钉钉](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p) _开发中_
- [钉钉](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)
- [Telegram](https://core.telegram.org/bots/api) _计划中_

## 即刻开始
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
home: true
heroImage: /logo.png
tagline: An asynchronous bot framework.
tagline: 跨平台 Python 异步 QQ 机器人框架
actionText: 开始使用
actionLink: guide/
features:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions archive/2.0.0a9.post1/advanced/runtime-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 钩子函数
Original file line number Diff line number Diff line change
Expand Up @@ -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.
## 从 v1 迁移
## NoneBot v1 迁移

`APScheduler` 作为 `nonebot` v1 的可选依赖,为众多 bot 提供了方便的定时任务功能。`nonebot2` 已将 `APScheduler` 独立为 `nonebot_plugin_apscheduler` 插件,你可以在 [插件广场](https://v2.nonebot.dev/plugin-store.html) 中找到它。

Expand All @@ -21,7 +21,7 @@ nb plugin install nonebot_plugin_apscheduler
```

:::tip 提示
`nb-cli` 默认通过 `pypi` 安装,你可以使用 `-i [mirror]``--index [mirror]` 来使用镜像源安装
`nb-cli` 默认通过 `pypi` 安装,你可以添加命令参数 `-i [mirror]``--index [mirror]` 以使用镜像源安装
:::

### 通过 poetry
Expand Down Expand Up @@ -96,10 +96,14 @@ scheduler = require('nonebot_plugin_apscheduler').scheduler

对于大多数情况,我们需要在 `nonebot2` 项目被启动时启动定时任务,则此处设为 `true`

##### `.env` 中添加

```bash
APSCHEDULER_AUTOSTART=true
```

##### `bot.py` 中添加

```python
nonebot.init(apscheduler_autostart=True)
```
Expand All @@ -116,10 +120,14 @@ nonebot.init(apscheduler_autostart=True)

> 官方文档在绝大多数时候能提供最准确和最具时效性的指南
##### `.env` 中添加

```bash
APSCHEDULER_CONFIG={"apscheduler.timezone": "Asia/Shanghai"}
```

##### `bot.py` 中添加

```python
nonebot.init(apscheduler_config={
"apscheduler.timezone": "Asia/Shanghai"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ sidebarDepth: 0

协议详情请看: [CQHTTP](https://github.com/howmanybots/onebot/blob/master/README.md) | [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md)

# NoneBot.adapters.cqhttp.config 模块


## _class_ `Config`

CQHTTP 配置类


* **配置项**


* `access_token` / `cqhttp_access_token`: CQHTTP 协议授权令牌


* `secret` / `cqhttp_secret`: CQHTTP HTTP 上报数据签名口令


# NoneBot.adapters.cqhttp.utils 模块


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ sidebarDepth: 0

协议详情请看: [钉钉文档](https://ding-doc.dingtalk.com/document#/org-dev-guide/elzz1p)

# NoneBot.adapters.ding.config 模块


## _class_ `Config`

钉钉配置类


* **配置项**


* `access_token` / `ding_access_token`: 钉钉令牌


* `secret` / `ding_secret`: 钉钉 HTTP 上报数据签名口令


# NoneBot.adapters.ding.exception 模块


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ Mirai-API-HTTP 的适配器以 [AGPLv3许可](https://opensource.org/licenses/AG
这意味着在使用该适配器时需要 **以该许可开源您的完整程序代码**
:::

# NoneBot.adapters.mirai.config 模块


## _class_ `Config`

Mirai 配置类


* **必填**


* `auth_key` / `mirai_auth_key`: mirai-api-http 的 auth_key


* `mirai_host`: mirai-api-http 的地址


* `mirai_port`: mirai-api-http 的端口


# NoneBot.adapters.mirai.bot 模块


Expand Down Expand Up @@ -690,28 +710,6 @@ mirai-api-http 正向 Websocket 协议 Bot 适配。
* `qq: int`: 要使用的Bot的QQ号 **注意: 在使用正向Websocket时必须指定该值!**


# NoneBot.adapters.mirai.config 模块


## _class_ `Config`

基类:`pydantic.main.BaseModel`

Mirai 配置类


* **必填**


* `mirai_auth_key`: mirai-api-http的auth_key


* `mirai_host`: mirai-api-http的地址


* `mirai_port`: mirai-api-http的端口


# NoneBot.adapters.mirai.message 模块


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Driver 基类。将后端框架封装,以满足适配器使用。



### `register_adapter(name, adapter)`
### `register_adapter(name, adapter, **kwargs)`


* **说明**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,58 @@ sidebarDepth: 0
后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/)


## _class_ `Config`

基类:`pydantic.env_settings.BaseSettings`

FastAPI 驱动框架设置,详情参考 FastAPI 文档


### `fastapi_openapi_url`


* **类型**

`Optional[str]`



* **说明**

openapi.json 地址,默认为 None 即关闭



### `fastapi_docs_url`


* **类型**

`Optional[str]`



* **说明**

swagger 地址,默认为 None 即关闭



### `fastapi_redoc_url`


* **类型**

`Optional[str]`



* **说明**

redoc 地址,默认为 None 即关闭



## _class_ `Driver`

基类:[`nonebot.drivers.Driver`](README.md#nonebot.drivers.Driver)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ def something_else():



### `on_startswith(msg, rule=None, **kwargs)`
### `on_startswith(msg, **kwargs)`


* **说明**
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def something_else():



### `on_endswith(msg, rule=None, **kwargs)`
### `on_endswith(msg, **kwargs)`


* **说明**
Expand Down Expand Up @@ -1054,7 +1054,7 @@ def something_else():



### `on_keyword(keywords, rule=None, **kwargs)`
### `on_keyword(keywords, **kwargs)`


* **说明**
Expand Down Expand Up @@ -1101,7 +1101,7 @@ def something_else():



### `on_command(cmd, rule=None, aliases=None, **kwargs)`
### `on_command(cmd, aliases=None, **kwargs)`


* **说明**
Expand All @@ -1118,10 +1118,10 @@ def something_else():
* `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容


* `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则
* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名


* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名
* `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则


* `permission: Optional[Permission]`: 事件响应权限
Expand Down Expand Up @@ -1153,64 +1153,64 @@ def something_else():



### `on_shell_command(cmd, rule=None, aliases=None, parser=None, **kwargs)`
### `on_shell_command(cmd, aliases=None, parser=None, **kwargs)`


* **说明**

注册一个支持 `shell_like` 解析参数的命令消息事件响应器。

注册一个支持 `shell_like` 解析参数的命令消息事件响应器
与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息

与普通的 `on_command` 不同的是,在添加 `parser` 参数时, 响应器会自动处理消息。
并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]`

并将用户输入的原始参数列表保存在 `state["argv"]`, `parser` 处理的参数保存在 `state["args"]`


* **参数**


* `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容


* `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容

* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名

* `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则

* `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象

* `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名

* `rule: Optional[Union[Rule, T_RuleChecker]]`: 事件响应规则

* `parser: Optional[ArgumentParser]`: `nonebot.rule.ArgumentParser` 对象

* `permission: Optional[Permission]`: 事件响应权限

* `permission: Optional[Permission]`: 事件响应权限

* `handlers: Optional[List[T_Handler]]`: 事件处理函数列表

* `handlers: Optional[List[T_Handler]]`: 事件处理函数列表

* `temp: bool`: 是否为临时事件响应器(仅执行一次)

* `temp: bool`: 是否为临时事件响应器(仅执行一次)

* `priority: int`: 事件响应器优先级

* `priority: int`: 事件响应器优先级

* `block: bool`: 是否阻止事件向更低优先级传递

* `block: bool`: 是否阻止事件向更低优先级传递

* `state: Optional[T_State]`: 默认 state

* `state: Optional[T_State]`: 默认 state

* `state_factory: Optional[T_StateFactory]`: 默认 state 的工厂函数

* `state_factory: Optional[T_StateFactory]`: 默认 state 的工厂函数


* **返回**


* `Type[Matcher]`


* `Type[Matcher]`


### `on_regex(pattern, flags=0, rule=None, **kwargs)`
### `on_regex(pattern, flags=0, **kwargs)`


* **说明**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
初次使用时可能会觉得这里的概览过于枯燥,可以先简单略读之后直接前往 [安装](./installation.md) 查看安装方法,并进行后续的基础使用教程。
:::

## 简介

NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人收到的事件进行解析和处理,并以插件化的形式,按优先级分发给事件所对应的事件响应器,来完成具体的功能。

除了起到解析事件的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制。对于命令处理,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

到目前为止我们还在使用 NoneBot 的默认行为,在开始编写自己的插件之前,我们先尝试在配置文件上动动手脚,让 NoneBot 表现出不同的行为。

在上一章节中,我们创建了默认的项目结构,其中 `.env`, `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。
在上一章节中,我们创建了默认的项目结构,其中 `.env` `.env.*` 均为项目的配置文件,下面将介绍几种 NoneBot 配置方式。

:::danger 警告
请勿将敏感信息写入配置文件并提交至开源仓库!
Expand Down Expand Up @@ -83,4 +83,4 @@ config.custom_config4 = "new config after init"

## 优先级

`bot.py init` > `system env` > `env file`
`bot.py` 文件( `nonebot.init` ) > 系统环境变量 > `.env` `.env.*` 文件
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 050137f

Please sign in to comment.