Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/DEPLOY.md

515 lines
21 KiB
Markdown
Raw Normal View History

2023-08-05 09:50:29 +00:00
# 目录
2023-08-05 09:50:29 +00:00
* [简介](#简介)
* [正常部署](#正常部署)
2023-08-14 13:53:28 +00:00
* [准备](#准备)
* [下载源代码](#下载源代码)
* [安装依赖](#安装依赖)
* [配置](#配置)
* [运行机器人](#运行机器人)
2023-08-05 09:50:29 +00:00
* [获取帮助](#获取帮助)
2023-08-05 09:50:29 +00:00
# 简介
2023-08-05 09:50:29 +00:00
本文将会教您如何搭建自己的小可机器人。
2023-08-05 09:50:29 +00:00
# 正常部署
2023-08-14 13:53:28 +00:00
若想使用 Docker 部署,请转到[使用 Docker 部署](./DEPLOY_Docker.md)。
2023-08-14 13:53:28 +00:00
## 准备
2023-08-05 09:50:29 +00:00
1. 一台可运行 Python 的服务器或主机(电脑、树莓派、安装了 Termux 的手机、etc...)。
2. 主机已安装并可运行 [Python 3 环境](https://www.python.org/) ,版本大于 3.8 皆可部署。
3. 对应您需要运行的平台所需要的必要内容环境、token 等)。
2023-08-14 13:53:28 +00:00
## 下载源代码
2023-08-05 09:50:29 +00:00
**Windows**
2023-08-14 15:31:37 +00:00
**方式一:使用 [Git](https://git-scm.com/) 克隆**
2023-08-05 09:50:29 +00:00
1. 请在要放置小可的文件夹中右键打开 Git Bash并输入以下指令
2023-08-05 09:50:29 +00:00
```sh
git clone https://github.com/Teahouse-studios/akari-bot.git
```
2023-08-05 09:50:29 +00:00
直连GitHub的克隆速度较慢在特殊情况下您可以使用镜像站进行克隆
2023-08-05 09:50:29 +00:00
```sh
git clone https://gitclone.com/github.com/Teahouse-studios/akari-bot.git
```
2023-08-14 15:31:37 +00:00
镜像站会在每天晚上进行仓库更新,所以若想在镜像站更新之前获取最新版本的代码,请使用原 GitHub 地址。
2023-08-14 15:31:37 +00:00
2. 按住 `Shift` + `右键`,选择`在此处打开 Powershell 窗口`或`在此处打开命令窗口`来打开终端。
2023-08-14 15:31:37 +00:00
**方式二:直接下载代码**
2023-08-05 09:50:29 +00:00
1. 从 [Release 页面](https://github.com/Teahouse-Studios/bot/releases/latest) 的 Assets 板块中下载 Source code源代码。当然您也可以下载 [master 分支的最新代码](https://github.com/Teahouse-Studios/akari-bot/archive/refs/heads/master.zip)。
2023-08-14 15:31:37 +00:00
> 注意master 分支下的部署文档可能会有所不同,请在下载对应版本的源码后打开目录下的 DEPLOY.md 继续查看部署教程。
2023-08-05 09:50:29 +00:00
2. 解压源代码,按住 `Shift` + `右键`,选择 `在此处打开 Powershell 窗口``在此处打开命令窗口` 来打开终端,进入文件夹。
2023-08-05 09:50:29 +00:00
**Linux**
2023-08-14 15:31:37 +00:00
1. 安装 [Git](https://git-scm.com/)。
2023-08-05 09:50:29 +00:00
2. 进入文件夹并执行以下指令:
2023-08-05 09:50:29 +00:00
```sh
git clone https://github.com/Teahouse-studios/akari-bot.git
```
2023-08-05 09:50:29 +00:00
直连GitHub的克隆速度较慢在特殊情况下您可以使用镜像站进行克隆
2023-08-05 09:50:29 +00:00
```sh
git clone https://gitclone.com/github.com/Teahouse-studios/akari-bot.git
```
2023-08-14 15:31:37 +00:00
镜像站会在每天晚上进行仓库更新,所以若想在镜像站更新之前获取最新版本的代码,请使用原 GitHub 地址。
2023-08-14 13:53:28 +00:00
## 安装依赖
2023-08-05 09:50:29 +00:00
**Windows**
2023-08-05 09:50:29 +00:00
**方式一:使用 [Poetry](https://python-poetry.org/)**
2023-08-05 09:50:29 +00:00
如果您已经安装了 Poetry您可以跳过以下安装步骤。
2023-08-05 09:50:29 +00:00
1. 打开 Powershell并执行以下指令来安装 Poetry
2023-08-05 09:50:29 +00:00
```powershell
(Invoke-WebRequest -Uri "https://install.python-poetry.org" -UseBasicParsing).Content | py -
```
2023-08-05 09:50:29 +00:00
> 若您使用了 Microsoft Store 或 pyenv-windows 安装 Python请将 `py` 替换为 `python`。
2023-08-14 15:31:37 +00:00
> 安装 Poetry 前请**务必**检查系统环境变量中是否存在多个 Python Executable PathPython 可执行路径)并及时清除,否则安装 Poetry 后可能会出现 Python 环境混乱导致无法正常加载依赖的情况。
2023-08-05 09:50:29 +00:00
2. 安装完成后,请将以下目录添加到 PATH 环境变量,方便调用:
2023-08-05 09:50:29 +00:00
```
%APPDATA%\Python\Scripts
```
2023-08-05 09:50:29 +00:00
请善用搜索引擎寻找更改 PATH 的方法。
2023-08-05 09:50:29 +00:00
在添加到 PATH 之后,您通常需要重启终端,甚至整个电脑才能使其生效。
2023-08-05 09:50:29 +00:00
您可以通过 `poetry --version` 确认安装是否有效。
2023-08-05 09:50:29 +00:00
3. 在安装完 Poetry 后,请执行以下指令:
2023-08-05 09:50:29 +00:00
```powershell
poetry install
```
2023-08-05 09:50:29 +00:00
**方式二:使用 pip**
2023-08-05 09:50:29 +00:00
如果您不想使用 Poetry您可以使用 pip 来安装依赖:
2023-08-05 09:50:29 +00:00
```powershell
pip install -r requirements.txt
```
2023-08-05 09:50:29 +00:00
**Linux**
2023-08-05 09:50:29 +00:00
**方式一:使用 [Poetry](https://python-poetry.org/)**
2023-08-05 09:50:29 +00:00
如果您已经安装了 Poetry您可以跳过以下安装步骤。
2023-07-27 13:58:54 +00:00
2023-08-14 15:31:37 +00:00
1. 打开终端,并执行以下指令来安装 Poetry
2023-08-05 09:50:29 +00:00
```sh
curl -sSL "https://install.python-poetry.org" | python3 -
```
2023-08-05 09:50:29 +00:00
> 安装 Poetry 前请**务必**检查系统环境变量中是否存在多个 Python Executable PathPython可执行路径 并及时清除,否则安装 Poetry 后可能会出现 Python 环境混乱导致无法正常加载依赖的情况。
2023-08-05 09:50:29 +00:00
2. 安装完成后,请将以下目录添加到 PATH 环境变量,方便调用:
2023-08-05 09:50:29 +00:00
```
$HOME/.local/bin
```
2023-08-05 09:50:29 +00:00
请善用搜索引擎寻找更改 PATH 的方法。
2023-08-05 09:50:29 +00:00
在添加到 PATH 之后,您通常需要重启终端,甚至整个电脑才能使其生效。
2023-08-05 09:50:29 +00:00
您可以通过 `poetry --version` 确认安装是否有效。
2023-08-05 09:50:29 +00:00
3. 在安装完 Poetry 后,请执行以下指令:
2023-08-05 09:50:29 +00:00
```sh
poetry install
```
2023-08-05 09:50:29 +00:00
**方式二:使用 pip**
2023-08-05 09:50:29 +00:00
如果您不想使用 Poetry您可以使用 pip 来安装依赖:
2023-08-05 09:50:29 +00:00
```powershell
pip install -r requirements.txt
```
2023-08-14 13:53:28 +00:00
## 配置
2023-08-05 09:50:29 +00:00
进入 `config` 文件夹,将 `config.toml.example` 重命名为 `config.toml`,然后开始配置您所需要的内容。
2023-08-14 15:31:37 +00:00
> 由于目前配置文件后缀改为 `toml`,与 `cfg` 不同的是,请在填写好必要的字段后,请删除所有配置文件中留空的字段,否则程序无法正常运行。若您拥有旧版 `cfg` 文件,机器人会自动帮您转换为 `toml` 格式。
2023-08-05 09:50:29 +00:00
### 配置数据库
2023-08-14 15:31:37 +00:00
机器人需要一个数据库以用于存储用户数据,对于第一次的简单部署,我们只需要关注数据库字段即可,其余字段可留空。
2023-08-05 09:50:29 +00:00
此字段需要填写一个可被 `sqlalchemy` 支持的数据库链接,以下为推荐方案,请任选一个:
2023-08-05 09:50:29 +00:00
#### MySQL
2023-08-05 09:50:29 +00:00
若使用 `MySQL` 作为主要使用数据库:
2023-08-05 09:50:29 +00:00
**格式**`db_path = "mysql+pymysql://<数据库用户名>:<数据库用户密码>@<数据库地址>"`
2023-08-05 09:50:29 +00:00
**实际示例**`db_path = "mysql+pymysql://bot:123456@example.com/bot_prod"`
2023-08-05 09:50:29 +00:00
#### SQLite
2023-08-14 15:31:37 +00:00
如果您不希望为了部署一个机器人而去研究如何安装数据库(或购买某服务商的数据库服务)的话,使用 SQLite 就是最佳选择。缺点是可能会遇到锁表问题(极小概率发生),以及将来运维失误(误删除 db 且没有备份)导致原先用户数据损毁的情况。
2023-08-05 09:50:29 +00:00
如果您选择 SQLite只需要将字段内容填写为以下格式即可。无需再关注数据库搭建等问题
2023-08-05 09:50:29 +00:00
**格式**`db_path = "sqlite:///<相对路径>/<数据库文件名>.db"`
2023-08-05 09:50:29 +00:00
**实际示例**`db_path = "sqlite:///database/save.db"`
2023-08-05 09:50:29 +00:00
此示例将会在 `database` 文件夹内创建 `save.db` 来存储用户数据。
2023-08-05 09:50:29 +00:00
### 配置平台机器人
2023-08-05 09:50:29 +00:00
#### QQ
2023-08-05 09:50:29 +00:00
我们在这里使用了 [aiocqhttp](https://github.com/nonebot/aiocqhttp) 来对接 [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 客户端。
2023-08-14 15:31:37 +00:00
如果您想使用 Docker 部署 go-cqhttp请转到[使用 Docker](https://docs.go-cqhttp.org/guide/docker.html)。
2023-08-05 09:50:29 +00:00
2023-08-14 15:31:37 +00:00
1. 从 go-cqhttp 的官方仓库上下载最新的 [Release](https://github.com/Mrs4s/go-cqhttp/releases/latest)。
2023-08-05 09:50:29 +00:00
| 系统类型 | 可执行文件 | 压缩文件 |
| -------------- | ----------------------------- | ------------------------------- |
| Intel 版 Macos | Not available | `go-cqhttp_darwin_amd64.tar.gz` |
| M1 版 Macos | Not available | `go-cqhttp_darwin_arm64.tar.gz` |
| 32 位 Linux | Not available | `go-cqhttp_linux_386.tar.gz` |
| 64 位 Linux | Not available | `go-cqhttp_linux_amd64.tar.gz` |
| arm64 Linux | Not available | `go-cqhttp_linux_arm64.tar.gz` |
| armv7 Linux | Not available | `go-cqhttp_linux_armv7.tar.gz` |
| 32 位 Windows | `go-cqhttp_windows_386.exe` | `go-cqhttp_windows_386.zip` |
| 64 位 Windows | `go-cqhttp_windows_amd64.exe` | `go-cqhttp_windows_amd64.zip` |
| arm64 Windows | `go-cqhttp_windows_arm64.exe` | `go-cqhttp_windows_arm64.zip` |
| armv7 Windows | `go-cqhttp_windows_armv7.exe` | `go-cqhttp_windows_armv7.zip` |
2. 解压下载好的文件到一个已经预先准备好的文件夹中:
2023-08-14 15:31:37 +00:00
**Windows** - 请使用自己熟悉的解压软件自行解压。
2023-08-05 09:50:29 +00:00
2023-08-14 15:31:37 +00:00
**Linux** - 请在命令行中输入 `tar -xzvf [文件名]`
2023-08-05 09:50:29 +00:00
3. 运行 go-cqhttp
**Windows**
2023-08-14 15:31:37 +00:00
1. 双击`go-cqhttp_*.exe`,根据提示生成运行脚本。
2. 双击运行脚本。
2023-08-05 09:50:29 +00:00
**Linux**
2023-08-14 15:31:37 +00:00
1. 通过 SSH 连接到服务器。
2. `cd`到解压目录。
3. 输入 `./go-cqhttp``Enter` 运行。
2023-08-05 09:50:29 +00:00
4. 此时将提示:
```
[WARNING]: 尝试加载配置文件 config.yml 失败: 文件不存在
[INFO]: 默认配置文件已生成,请编辑 config.yml 后重启程序.
```
程序将会自动在存放 [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 文件夹的目录下生成一个默认配置文件 `config.yml`
接下来,请配置 [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 的 `config.yml` 文件中的对应的连接方式和签名服务器。
```
account:
...
# 数据包的签名服务器
# 兼容 https://github.com/fuqiuluo/unidbg-fetch-qsign
# 暂不支持最新版qsign服务可用版本v1.1.0-
# 如果遇到 登录 45 错误, 或者发送信息风控的话需要填入一个服务器
# 示例:
# sign-server: 'http://127.0.0.1:8080' # 本地签名服务器
# sign-server: 'https://signserver.example.com' # 线上签名服务器
# 服务器可使用docker在本地搭建或者使用他人开放的服务
# 不建议使用公共服务器, 有封号风险
sign-server: '-'
...
# 连接服务列表
servers:
# 添加方式,同一连接方式可添加多个,具体配置说明请查看文档
#- http: # http 通信
#- ws: # 正向 Websocket
#- ws-reverse: # 反向 Websocket
#- pprof: #性能分析服务器
- ws-reverse:
universal: ws://127.0.0.1:11451/ws/ # 此处填写先前的 IP 地址和端口,注意不要删去后面的 /ws/
reconnect-interval: 3000
middlewares:
<<: *default # 引用默认中间件
...
```
请在小可机器人的配置文件 `config.toml` 填写以下字段:
`qq_host = "127.0.0.1:11451"` - 将会在填写的 IP 地址和端口中开启一个 Websocket 服务器,用于 go-cqhttp 反向连接。
2023-08-14 15:31:37 +00:00
`qq_account = 2314163511` - 填写机器人的 QQ 号。
2023-08-05 09:50:29 +00:00
> 由于最近 QQ 封控机制加强go-cqhttp 若出现 Code45 报错情况,请配置签名服务器,请注意:目前 go-cqhttp 暂不支持最新版本的签名服务器。
2023-08-14 15:31:37 +00:00
> 若在配置中遇到问题,请参阅 [go-cqhttp官方文档](https://docs.go-cqhttp.org/)。
2023-08-05 09:50:29 +00:00
#### Discord
我们在这里使用了 [Pycord](https://github.com/Pycord-Development/pycord) 来调用 Discord API。
2023-08-14 15:31:37 +00:00
为了达到目的,您需要于 [Discord 开发者平台](https://discord.com/developers)创建一个机器人并获取 Token。
2023-08-05 09:50:29 +00:00
`dc_token =` - 填写您获取到的机器人 Token。
2023-08-05 09:50:29 +00:00
#### Telegram
我们在这里使用了 [AIOGram](https://github.com/aiogram/aiogram) 来异步调用 Telegram API。
2023-08-05 09:50:29 +00:00
为了达到目的,您需要在 Telegram 搜索 `@BotFather` 来创建机器人。
2023-08-05 09:50:29 +00:00
`tg_token =` - 填写您获取到的机器人 Token。
2023-08-05 09:50:29 +00:00
#### Kook
2023-06-30 07:59:11 +00:00
2023-08-14 15:31:37 +00:00
您需要在 [Kook 开发者平台](https://developer.kookapp.cn/)创建一个机器人并获取 Token。
2023-06-30 07:59:11 +00:00
2023-08-05 09:50:29 +00:00
`kook_token =` - 填写您获取到的机器人 Token。
2023-06-30 07:59:11 +00:00
2023-08-05 09:50:29 +00:00
#### Matrix
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-14 13:53:28 +00:00
您需要自行完成账号注册与登录。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-05 09:50:29 +00:00
`matrix_homeserver =` - 填写您使用的 Matrix server URL只包括协议与主机最后无需添加`/`)。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-14 15:31:37 +00:00
`matrix_user =` - 填写机器人的[用户 ID](https://spec.matrix.org/v1.7/appendices/#user-identifiers)(包括`@`与`:`)。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-05 09:50:29 +00:00
`matrix_token =` - 填写机器人任意设备的 Access Token。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-05 09:50:29 +00:00
> 获取完 Access Token 后,不要使用客户端的退出登录功能,推荐通过浏览器隐私模式登陆并获取 Token。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
对于 Element 及其分支(如 SchindiChatAccess Token 可以从“所有设置”->“帮助及关于”->“高级”->“访问令牌”中获取。
2023-08-05 09:50:29 +00:00
对于 CinnyAccess Token 可以从浏览器的的 localStorage 中提取(参考 [cinnyapp/cinny#938](https://github.com/cinnyapp/cinny/issues/938))。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-14 15:31:37 +00:00
对于没有合适的客户端的用户(?),您也可以使用以下命令进行密码登录(但仍需手动完成后续的[设备验证](https://spec.matrix.org/v1.7/client-server-api/#device-verification)、[交叉签名](https://spec.matrix.org/v1.7/client-server-api/#cross-signing)和[服务端密钥备份](https://spec.matrix.org/v1.7/client-server-api/#server-side-key-backups)恢复等流程):
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-05 09:50:29 +00:00
```
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
curl -XPOST -d '{"type":"m.login.password", "user":"<user>", "password":"<password>"}' "https://<homeserver>/_matrix/client/r0/login"
```
2023-08-14 15:31:37 +00:00
目前,由于 libolm 在一些情况下需要手动安装机器人没有端对端加密e2ee支持。
feat: partial matrix support (#680) * build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit 3688213c802562b7f27ecf8fe88269d911036d60. * Revert "feat: add post test" This reverts commit 259fcf54ca92a6d20ada99ddcda7fcc8ded63675. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
2023-07-30 09:41:01 +00:00
2023-08-05 09:50:29 +00:00
### 配置其他功能
2023-08-14 15:31:37 +00:00
由于小可有较多功能,部分功能需要进一步的配置才能使用。
部分字段可能并未预设于 `config.toml.example` 中,手动添加即可。
2023-08-05 09:50:29 +00:00
#### 屏蔽词
2023-08-14 15:31:37 +00:00
小可内置了[阿里云内容安全服务](https://www.aliyun.com/product/lvwang)对接,可用于 QQ 和 Kook 平台下部分模块检查发送文本是否安全,以达到机器人账户安全的目的。
2023-06-30 09:25:59 +00:00
如有需求,请前往阿里云进行开通并获取 AccessKeyID 及 AccessKeySecret。未填写字段将不会使用屏蔽词服务。
2023-08-05 09:50:29 +00:00
`check_accessKeyId =` - 填写获取的 AccessKeyID。
2023-08-05 09:50:29 +00:00
`check_accessKeySecret =` - 填写获取的 AccessKeySecret。
2023-08-14 15:31:37 +00:00
#### QQ 频道消息处理beta
2023-08-14 15:31:37 +00:00
通过上文的 [aiocqhttp](https://github.com/nonebot/aiocqhttp) 对接 [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) 方式,可以按需选择是否启用 QQ 频道消息处理功能。
2023-08-14 15:31:37 +00:00
根据 go-cqhttp 的文档iPad / Android Pad / Android Phone 协议支持处理 QQ 频道消息,可以在其生成的 `device.json` 中寻找 `"protocol":6,` 字段,将本处的数值修改为 1Android Phone、5iPad或 6Android Pad任意一个均可调用本功能。
2023-06-30 09:25:59 +00:00
> 注意QQ频道消息的处理仍然处于测试阶段由于 go-cqhttp 对频道消息支持的不完善,频道内消息无法撤回,且频道列表不会自动刷新(加入新频道需要手动重启一次 gocqhttp
2023-08-05 09:50:29 +00:00
> 关于 go-cqhttp 选用以上方式登录时出现的的 Code45 或其他登录问题,请根据 go-cqhttp 官方 [Issue](https://github.com/Mrs4s/go-cqhttp) 对照解决,或选用除以上协议外的其他协议。
2023-08-05 09:50:29 +00:00
#### Webrender
此为小可的外置服务。主要用于处理 html 渲染图片及部分功能的访问代理。
2023-08-05 09:50:29 +00:00
##### 部署
2023-08-05 09:50:29 +00:00
1. 此服务使用 JavaScript 编写,由 `Puppeteer` 驱动,为此,您需要安装好 [Node.js](https://nodejs.org/) 环境,以及安装好 [Chrome](https://www.google.cn/intl/zh-CN/chrome/) 。
2. 下载 [源代码文件](https://github.com/Teahouse-Studios/oa-web-render) ,并在终端内使用 `npm install` 安装依赖。
2023-08-05 09:50:29 +00:00
3.`package.json` 同级目录中,创建 `.env` 文件,并于内填写以下字段:
2023-08-05 09:50:29 +00:00
```
CHROMIUM_PATH="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" # 填写 chrome.exe 的绝对路径
FC_SERVER_PORT=15551 # 填写服务运行的端口
```
> 在填写好配置文件之后,请删除所有配置文件中的注释,否则程序无法正确读取配置。
4. 于终端内,使用 `node ./src/index.js` 来开启服务。服务无任何内容输出。
2023-08-05 09:50:29 +00:00
您亦可使用云服务产商的 Serverless 服务来部署本服务。
2023-08-05 09:50:29 +00:00
##### 字段填写
2023-06-30 09:25:59 +00:00
`web_render =` - Webrender 的地址IP 或域名)及端口。
2023-06-30 09:25:59 +00:00
`web_render_local =` - 本地 Webrender 的地址。(可与上一字段同一参数)
**示例**
2023-07-29 12:49:47 +00:00
`web_render = "http://127.0.0.1:15551"`
2023-08-05 09:50:29 +00:00
#### 模块
##### coin
2023-06-28 14:58:45 +00:00
`coin` 模块需要一些额外的参数才能正常工作。
`coin_limit = 10000` - 一次可投掷的硬币最大个数。
`coin_faceup_rate = 4994` - 硬币正面朝上的概率,按一万分之几计算。
2023-06-28 14:58:45 +00:00
`coin_facedown_rate = 4994` - 硬币反面朝上的概率,按一万分之几计算。
2023-08-05 09:50:29 +00:00
##### dice
2023-06-28 14:58:45 +00:00
`dice` 模块需要一些额外的参数才能正常工作。
`dice_limit = 10000` - 一次可投掷的骰子最大个数。
`dice_roll_limit = 100` - 投掷骰子的最大次数。
`dice_mod_max = 10000` - 投掷骰子的最大调节值。
`dice_mod_min = -10000` - 投掷骰子的最小调节值。
`dice_output_cnt = 50` - 输出时的最大数据量,超过则无法正常显示。
`dice_detail_cnt= 5` - 多次投掷骰子的总数,超过则不再显示详细信息。
`dice_count_limit = 10` - 多项式最多的项数。
2023-08-05 09:50:29 +00:00
##### maimai
2023-06-28 14:58:45 +00:00
`maimai` 模块基于 [mai-bot](https://github.com/Diving-Fish/mai-bot) 修改而来。此模块需要额外的资源文件才可正常工作。
1. 下载 [资源文件](https://www.diving-fish.com/maibot/static.zip) ,并于 `assets` 目录下创建一个 `maimai` 文件夹。
2. 解压资源文件,形成以下目录结构:
2023-08-05 09:50:29 +00:00
```angular2html
assets
└─maimai
└─static
│ adobe_simhei.otf
│ aliases.csv
│ msyh.ttc
└─mai
│...
```
2023-08-05 09:50:29 +00:00
##### secret
2023-06-28 14:58:45 +00:00
此模块下的内容主要用于监测 Minecraft Wiki 注册日志和滥用日志,如无需要可直接删除此模块的文件夹。
2023-08-05 09:50:29 +00:00
#### 其他功能
2023-08-05 09:50:29 +00:00
`base_superuser =` - 设置机器人主超级用户。可用格式为 `QQ|<QQ号>`、`Discord|Client|<ClientID>`、`Telegram|Client|<ClientID>`、`Kook|User|<UserID>`,可在机器人开启后使用 `~whoami` 命令来查看自身的 ID机器人启动后将自动标记对象为超级用户。
`qq_disable_temp_session = true` - 是否禁用 QQ 平台的临时会话功能。
2023-07-07 17:52:06 +00:00
`qq_enable_listening_self_message = false` - 是否启用 QQ 平台的自我消息处理(可能有助于多设备下使用,但也可能会导致误触发导致消息陷入死循环状态)。
2023-07-07 17:30:31 +00:00
`enable_dirty_check = true` - 是否启用屏蔽词检查。
2023-07-07 17:30:31 +00:00
`enable_urlmanager = true` - 是否启用 URL 管理(替换外部链接,提示非官方页面)。若停用此功能将同时停用 `wiki_audit` 命令。
`slower_schedule = false` - 部分计划任务模块使用更长的时间间隔执行,可能有助于网络较差环境的优化。
`enable_tos = false` - 是否启用内置的违反服务条款的检查。
`enable_analytics = true` - 是否启用内置的 `analytics` 命令,用于统计命令使用次数。
2023-06-28 14:58:45 +00:00
2023-06-30 09:25:59 +00:00
`enable_eval = true` - 是否启用内置的 `eval` 命令。
2023-06-28 14:58:45 +00:00
`allow_request_private_ip = true` - 是否允许机器人请求私有 IP 地址。
#### 自定义确认词及命令前缀
2023-08-14 15:31:37 +00:00
您可以通过编辑配置文件中的 `confirm_command` 来添加(或删除)机器人在部分场景下询问用户是否继续的确认词,编辑 `command_prefix` 来增加(或删除)可使用的默认命令前缀。
`command_prefix` 首位将被用作帮助文档中默认展示的前缀。
2023-08-05 09:50:29 +00:00
2023-08-14 13:53:28 +00:00
## 运行机器人
2023-08-05 09:50:29 +00:00
小可机器人主要由平台机器人构成,为了让开发者更好地测试模块,我们还提供了测试控制台,接下来我们将逐步讲解如何运行机器人。
### 运行平台机器人
2023-08-14 15:31:37 +00:00
**Windows**
2023-08-05 09:50:29 +00:00
我们不推荐双击运行 `start.bat` 来启动程序。
建议在启动机器人之前先打开终端cmd 或 Powershell再运行 `start.bat`
1.`start.bat` 所在目录,按下 `Shift` + `右键` 来打开右键菜单。
2023-08-14 13:53:28 +00:00
2. 选择 `在此处打开 Powershell 窗口``在此处打开命令窗口`
2023-08-05 09:50:29 +00:00
3. 于终端内输入 `.\start.bat` Powershell`start.bat` cmd来启动机器人。
2023-08-14 15:31:37 +00:00
**Linux**
2023-08-05 09:50:29 +00:00
1. 于终端内,设置 `start` 脚本的执行权限:`chmod +x start`
2. 启动脚本:`./start`
### 运行测试控制台
测试控制台包括一个基础的运行环境,您可以在测试控制台内使用命令进行基础的机器人交互。
测试控制台仅支持回复文本消息和图片,其它消息元素将被忽略或转换为文本或图片来显示。
您可能需要使用 `poetry shell` 切换 poetry 的虚拟环境来调用先前安装的依赖。
2023-08-14 15:31:37 +00:00
**Windows**
2023-08-05 09:50:29 +00:00
1.`console.py` 所在目录,按下 `Shift` + `右键` 来打开右键菜单。
2023-08-14 13:53:28 +00:00
2. 选择 `在此处打开 Powershell 窗口``在此处打开命令窗口`
2023-08-05 09:50:29 +00:00
3. 于终端内输入 `python console.py` 来启动测试控制台。
2023-08-14 15:31:37 +00:00
**Linux**
2023-08-05 09:50:29 +00:00
1.`console.py` 所在目录,打开终端。
2023-08-14 13:53:28 +00:00
2. 于终端内输入 `python console.py` 来启动测试控制台。
2023-08-05 09:50:29 +00:00
# 获取帮助
到此,恭喜您成功部署了属于您的小可机器人!
如果您在部署的过程中还有其他疑问,您可以向我们发送 Issue 来请求帮助。
> 请注意,您应该具备基本的提问技巧。
2023-08-14 13:53:28 +00:00
> 有关如何提问,请阅读[《提问的智慧》](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md)。