Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien8261 committed Aug 2, 2023
1 parent 4373d45 commit 298f420
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 55 deletions.
6 changes: 2 additions & 4 deletions docs/components/download.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<div>
{{ text }}:<a @click="download">{{ latest }}-{{ version }}.zip</a>
</div>
<a @click="download">AmiyaBot-{{ latest }}-{{ version }}.zip</a>
</template>

<script>
Expand All @@ -26,7 +24,7 @@ export default {
}
},
mounted() {
axios.get(`${cos}/latest-V6-${this.version}.txt?time=${new Date().getTime()}`).then(response => {
axios.get(`${cos}/latest-${this.version}.txt?time=${new Date().getTime()}`).then(response => {
this.latest = response.data.toString().replace(/\r\n/g, '').replace(/\n/g, '')
})
}
Expand Down
57 changes: 51 additions & 6 deletions docs/develop/basic/sendMessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
```python {4}
@bot.on_message(keywords='hello')
async def _(data: Message):

await data.send(Chain(data).text('hello'))

return Chain(data).text(data.nickname)
Expand All @@ -15,11 +14,12 @@ async def _(data: Message):

## Chain 对象

| 参数名 | 类型 | 释义 | 默认值 |
|-----------|---------|--------------|-------|
| data | Message | Message 对象 | None |
| at | Bool | 是否 @ 用户 | True |
| reference | Bool | 是否回复用户(引用消息) | False |
| 参数名 | 类型 | 释义 | 默认值 |
|---------------|--------------|--------------|----------------|
| data | Message | Message 对象 | None |
| at | Bool | 是否 @ 用户 | True |
| reference | Bool | 是否回复用户(引用消息) | False |
| chain_builder | ChainBuilder | Chain 辅助构建实例 | ChainBuilder() |

`Chain` 对象是构建你的消息体的工具类。任何需要发送消息的时候,消息都必须由 Chain 类创建。<br>
Chain 对象提供丰富的消息构建方式,可以让你发送多彩的文字图片,甚至是html模板。<br>
Expand Down Expand Up @@ -69,3 +69,48 @@ voice 方法并不参与构建消息体,因为 QQ 无法在发送的文字消
```python
Chain().text(...).image(...)
```

## 使用辅助类扩展构建

Chain 在构建时,可使用辅助类介入图片或浏览器的构建过程。

### 创建辅助类

```python
from typing import Union
from amiyabot import Chain, ChainBuilder
from playwright.async_api import Page


# 继承 ChainBuilder
class MyBuilder(ChainBuilder):
@classmethod
async def get_image(cls, image: Union[str, bytes]):
...
return image

@classmethod
async def on_page_rendered(cls, page: Page):
...


# 在构造参数里使用辅助类
chain = Chain(..., chain_builder=MyBuilder())

# 为属性赋值使用辅助类
chain.builder = MyBuilder()
```

### get_image 函数

该函数会在 chain 构建图片消息时调用,每张图片会调用一次。传入一个参数 `image` ,类型为 `str`(path 或 url) 或
`bytes`(图片字节数据)。该函数必须拥有返回值,同样是以上两种类型,chain 会根据返回的类型做进一步处理。

### on_page_rendered 函数

该函数会在 chain 构建浏览器渲染的图片并打开了页面时调用,提供了浏览器的 `Page` 对象,可在此对 `Page` 进行操作(如对页面进行
JS 注入等)。

::: tip 提示
构建浏览器渲染的图片同样也会调用一次 `get_image` 函数。
:::
14 changes: 6 additions & 8 deletions docs/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import download from './components/download.vue'

# 下载

## 框架最新版本

![amiyabot](https://img.shields.io/pypi/v/amiyabot)

## AmiyaBot-demo-v6

<download version="master" text="正式版" />
| 操作系统 | 下载 | 备注 |
|---------|------------------------------|------------------------------------------|
| Windows | <download version="win32" /> | 仅支持 Windows 10、Windows Server 2016 及以上系统 |
| Linux | <download version="linux" /> | 不支持 Centos,目前在 Ubuntu 20.04 测试可用 |

## Git
## 框架最新版本

[点击下载](https://objects.githubusercontent.com/github-production-release-asset-2e65be/23216272/2c9b0433-013d-483f-8c1c-256e88ec86f3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220922%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220922T110228Z&X-Amz-Expires=300&X-Amz-Signature=366b23a99d9d870adc84fcfa3b7bbbebdff6484446b49a76922930f32a603102&X-Amz-SignedHeaders=host&actor_id=34387011&key_id=0&repo_id=23216272&response-content-disposition=attachment%3B%20filename%3DGit-2.37.3-64-bit.exe&response-content-type=application%2Foctet-stream)
或自行到 [官网](http://gitforwindows.org/) 下载合适自己系统的版本
![amiyabot](https://img.shields.io/pypi/v/amiyabot)
69 changes: 32 additions & 37 deletions docs/guide/deploy/getStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import download from '../../components/download.vue'

## 安装 Git

兔兔的资源更新依赖本地的 Git
服务。[点击下载](https://objects.githubusercontent.com/github-production-release-asset-2e65be/23216272/2c9b0433-013d-483f-8c1c-256e88ec86f3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220922%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220922T110228Z&X-Amz-Expires=300&X-Amz-Signature=366b23a99d9d870adc84fcfa3b7bbbebdff6484446b49a76922930f32a603102&X-Amz-SignedHeaders=host&actor_id=34387011&key_id=0&repo_id=23216272&response-content-disposition=attachment%3B%20filename%3DGit-2.37.3-64-bit.exe&response-content-type=application%2Foctet-stream)
部分插件依赖本地的 Git
服务,必须安装 Git
以确保正常使用。[点击下载](https://objects.githubusercontent.com/github-production-release-asset-2e65be/23216272/2c9b0433-013d-483f-8c1c-256e88ec86f3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220922%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220922T110228Z&X-Amz-Expires=300&X-Amz-Signature=366b23a99d9d870adc84fcfa3b7bbbebdff6484446b49a76922930f32a603102&X-Amz-SignedHeaders=host&actor_id=34387011&key_id=0&repo_id=23216272&response-content-disposition=attachment%3B%20filename%3DGit-2.37.3-64-bit.exe&response-content-type=application%2Foctet-stream)
并安装。或自行到[官网](http://gitforwindows.org/)下载合适自己系统的版本。

## 部署
Expand All @@ -27,28 +28,37 @@ Windows 系统推荐使用**可执行文件部署**,可执行文件部署是

## 通过可执行文件部署

::: danger 注意<br>
仅支持 Windows 10 以上系统
:::
| 操作系统 | 下载 | 备注 |
|---------|------------------------------|------------------------------------------|
| Windows | <download version="win32" /> | 仅支持 Windows 10、Windows Server 2016 及以上系统 |
| Linux | <download version="linux" /> | 不支持 Centos,目前在 Ubuntu 20.04 测试可用 |

点击下载可执行文件:
<download version="master" text="正式版" />
<download version="dev" text="测试版" />
### Windows

解压并运行 AmiyaBot-*.exe,如下图成功运行后可以进入[下一节](/guide/deploy/console/)
下载并解压,运行 `AmiyaBot-v6.x.x-win32.exe`,如下图成功运行后可以进入[下一节](/guide/deploy/console/)

![img.png](../../assets/deploy/running.png)

### Linux

下载并解压,进入 `package/dist` 目录,运行 `AmiyaBot-v6.x.x-linux`

```bash
cd package/dist/
chmod 777 ./AmiyaBot-v6.x.x-linux
./AmiyaBot-v6.x.x-linux
```

## 通过代码部署

::: warning 注意<br>
推荐使用 Python 3.7 ~ 3.8 运行本项目代码
推荐使用 Python 3.8 ~ 3.9 运行本项目代码,并参照可执行文件的系统支持选择部署的操作系统。
:::

1. [克隆仓库](https://github.com/AmiyaBot/Amiya-Bot)

```bash
git clone https://github.com/AmiyaBot/Amiya-Bot.git
git clone --depth 1 https://github.com/AmiyaBot/Amiya-Bot.git
```

2. 安装依赖
Expand Down Expand Up @@ -79,20 +89,10 @@ playwright install --with-deps firefox

::: details 使用火狐内核需要修改入口程序 `amiya.py`,点击查看代码

```python {6,16,21,31}
import os
import sys
import asyncio
import core.frozen
```python {3,6-11,20}
import ...

from amiyabot import BrowserLaunchConfig # 导入浏览器启动配置类
from core import app, bot, init_task, load_resource, load_plugins

sys.path += [
os.path.dirname(sys.executable),
os.path.dirname('resource/env/python-dlls'),
os.path.dirname('resource/env/python-standard-lib.zip'),
]


# 创建新启动类
Expand All @@ -103,21 +103,16 @@ class Launcher(BrowserLaunchConfig):
self.browser_type = 'firefox' # 修改浏览器属性


def run_amiya(*tasks: Coroutine):
...


if __name__ == '__main__':
try:
load_resource()
asyncio.run(
asyncio.wait(
[
*init_task,
bot.start(launch_browser=Launcher()), # 使用新启动类启动浏览器
app.serve(),
load_plugins()
]
)
)
except KeyboardInterrupt:
pass
run_amiya(
bot.start(launch_browser=Launcher()), # 使用新启动类启动浏览器
app.serve(),
load_plugins()
)
```

:::
Expand Down

0 comments on commit 298f420

Please sign in to comment.