Skip to content

Commit

Permalink
update 完善文档
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien8261 committed Sep 18, 2023
1 parent e1b157b commit a3ecb36
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 24 deletions.
8 changes: 4 additions & 4 deletions docs/.vitepress/nav/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export default [
{
text: '常见问题',
link: '/guide/deploy/faq/commonProblem'
},
{
text: '插件开发',
link: '/develop/plugin/'
}
]
},
{
text: '插件开发',
link: '/develop/plugin/'
},
{
text: '下载',
link: '/download'
Expand Down
15 changes: 14 additions & 1 deletion docs/.vitepress/nav/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ export default {
items: [
{ text: '创建&编写插件', link: '/develop/plugin/create.md' },
{ text: '插件生命周期', link: '/develop/plugin/life.md' },
{ text: '添加插件文档', link: '/develop/plugin/addDoc.md' },
{ text: '对接控制台', link: '/develop/plugin/consoleConfig.md' },
{ text: '添加插件文档', link: '/develop/plugin/addDoc.md' },
]
},
{
text: '调试',
collapsible: true,
items: [
{ text: '调试插件', link: '/develop/plugin/debug.md' },
]
},
Expand All @@ -116,6 +122,13 @@ export default {
{ text: '发布到插件商店', link: '/develop/plugin/publish.md' },
]
},
{
text: '其他',
collapsible: true,
items: [
{ text: 'JsonSchema 解释', link: '/develop/plugin/jsonSchema.md' },
]
},
],
'/guide/deploy/': [
{
Expand Down
19 changes: 15 additions & 4 deletions docs/develop/plugin/addDoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,40 @@

## 添加一个 markdown 文档

```text {6}
```text {6,7}
Amiya-Bot
├── pluginsDev
│ ├── myPlugin
│ │ ├── __init__.py
│ │ ├── main.py
│ │ └── README.md
│ │ ├── README.md
│ │ └── HOWTOUSE.md
│ ...
...
```

demo 允许直接使用 markdown 文件路径作为文档,只需要把路径传入到 PluginInstance 对象的 `document` 参数。
demo 允许直接使用 markdown 文件路径作为文档,只需要把路径传入到 **PluginInstance** 对象的 `document` 参数。

若使用了 [AmiyaBotPluginInstance](/develop/plugin/consoleConfig.html#amiyabotplugininstance)
对象创建插件,可使用参数 `instruction`,其作用是当 bot 的用户在使用 “查看功能指引”
类的指令时,向其展示 `instruction` 的内容。`document` 更偏向于提供给 bot
的部署者查看的文档。在没有配置 `instruction` 时,“查看功能指引” 将返回 `document` 的内容。

```python
import os

from amiyabot import PluginInstance
from amiyabot import PluginInstance, AmiyaBotPluginInstance

plugin_dir = os.path.dirname(__file__)

bot = PluginInstance(
document=f'{plugin_dir}/README.md'
)
#
bot = AmiyaBotPluginInstance(
document=f'{plugin_dir}/README.md',
instruction=f'{plugin_dir}/HOWTOUSE.md'
)
```

## 直接在参数内编写
Expand Down
14 changes: 9 additions & 5 deletions docs/develop/plugin/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

### 示例

如在插件内使用了库 `numpy`,在本地 python 环境内找到 **numpy 文件夹**,并拷贝进 zip 包内。
如在插件内使用了库 `pypyodbc`,在本地 python 环境内找到 **pypyodbc.py**(有时候会是 package 文件夹),并拷贝进 zip 包内。

```python
# main.py
import numpy
import pypyodbc

...
```
Expand All @@ -21,12 +21,16 @@ import numpy
myPlugin.zip
├── __init__.py
├── main.py
└── numpy
└── pypyodbc.py
```

`main.py` 内的导入语句 `import numpy` 被执行时,可以优先使用插件内的 numpy 包。
`main.py` 内的导入语句 `import pypyodbc` 被执行时,优先使用插件内的 pypyodbc 包。

这是良好的做法,因为主体程序必会缺少其不必要的库,你应该保持将第三方库手动加进插件的习惯。
::: warning 注意<br>
若无法通过上述手段将第三方包添加进插件包,你的插件将可能不支持
[可执行文件部署](/guide/deploy/getStarted.html#通过可执行文件部署)
。你可以在你的插件文档内注明,并让代码部署的用户使用 `pip install xxx` 安装第三方依赖。
:::

## 使用脚本打包

Expand Down
14 changes: 9 additions & 5 deletions docs/develop/plugin/consoleConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ AmiyaBotPluginInstance 继承了 PluginInstance,并且拥有以下新参数和
- 如果提供了 JsonSchema,必须同时提供默认值数据。

```python
plugin_dir = os.path.dirname(__file__)

bot = AmiyaBotPluginInstance(
channel_config_default='./config.yaml',
channel_config_schema='./jsonSchema.json'
channel_config_default=f'{plugin_dir}/config.yaml',
channel_config_schema=f'{plugin_dir}/jsonSchema.json'
)
```

### 方法
## [JsonSchema](/develop/plugin/jsonSchema)

请阅读 [介绍文档](/develop/plugin/jsonSchema) 了解如何编辑 jsonSchema.json 文件。

**get_config**
## get_config

读取一个指定名称的配置项,如果没有频道级别的配置则返回同名全局配置,如果也没有全局配置,返回 `None`。传入 `channel_id=None`
可以直接读取全局配置。
Expand All @@ -67,7 +71,7 @@ bot = AmiyaBotPluginInstance(
config_value = bot.get_config('name', channel_id='...')
```

**set_config**
## set_config

写入配置,传入 `channel_id=None` 可以强制指定写入全局配置。

Expand Down
Loading

0 comments on commit a3ecb36

Please sign in to comment.