Skip to content

Commit 13fda1f

Browse files
committed
docs: add storage guide for plugins in English and Chinese
1 parent 215614c commit 13fda1f

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

.vitepress/config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export default defineConfig({
190190
{ text: "发送消息", link: "/guides/send-message" },
191191
{ text: "插件配置", link: "/guides/plugin-config" },
192192
{ text: "调用 AI", link: "/guides/ai" },
193+
{ text: "存储", link: "/guides/storage" },
193194
{ text: "文转图", link: "/guides/html-to-pic" },
194195
{ text: "会话控制器", link: "/guides/session-control" },
195196
{ text: "杂项", link: "/guides/other" },
@@ -410,6 +411,7 @@ export default defineConfig({
410411
{ text: "Send Messages", link: "/guides/send-message" },
411412
{ text: "Plugin Configuration", link: "/guides/plugin-config" },
412413
{ text: "AI", link: "/guides/ai" },
414+
{ text: "Storage", link: "/guides/storage" },
413415
{ text: "HTML to Image", link: "/guides/html-to-pic" },
414416
{ text: "Session Control", link: "/guides/session-control" },
415417
{ text: "Publish Plugin", link: "/plugin-publish" },

en/dev/star/guides/storage.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Plugin Storage
2+
3+
## Simple KV Storage
4+
5+
> [!TIP]
6+
> Requires AstrBot version >= 4.9.2.
7+
8+
Plugins can use AstrBot's simple key-value store to persist configuration or temporary data. The storage is scoped per plugin, so each plugin has its own isolated space.
9+
10+
```py
11+
class Main(star.Star):
12+
@filter.command("hello")
13+
async def hello(self, event: AstrMessageEvent):
14+
"""Aloha!"""
15+
await self.put_kv_data("greeted", True)
16+
greeted = await self.get_kv_data("greeted", False)
17+
await self.delete_kv_data("greeted")
18+
```
19+
20+
21+
## Large File Storage Convention
22+
23+
To keep large file handling consistent, store large files under `data/plugin_data/{plugin_name}/`.
24+
25+
You can fetch the plugin data directory with:
26+
27+
```py
28+
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
29+
30+
plugin_data_path = get_astrbot_data_path() / "plugin_data" / self.name # self.name is the plugin name; available in v4.9.2 and above. For lower versions, specify the plugin name yourself.
31+
```

zh/dev/star/guides/storage.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 插件存储
2+
3+
## 简单 KV 存储
4+
5+
> [!TIP]
6+
> 该功能需要 AstrBot 版本 >= 4.9.2。
7+
8+
插件可以使用 AstrBot 提供的简单 KV 存储功能来存储一些配置信息或临时数据。该存储是基于插件维度的,每个插件有独立的存储空间,互不干扰。
9+
10+
```py
11+
class Main(star.Star):
12+
@filter.command("hello")
13+
async def hello(self, event: AstrMessageEvent):
14+
"""Aloha!"""
15+
await self.put_kv_data("greeted", True)
16+
greeted = await self.get_kv_data("greeted", False)
17+
await self.delete_kv_data("greeted")
18+
```
19+
20+
21+
## 存储大文件规范
22+
23+
为了规范插件存储大文件的行为,请将大文件存储于 `data/plugin_data/{plugin_name}/` 目录下。
24+
25+
你可以通过以下代码获取插件数据目录:
26+
27+
```py
28+
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
29+
30+
plugin_data_path = get_astrbot_data_path() / "plugin_data" / self.name # self.name 为插件名称,在 v4.9.2 及以上版本可用,低于此版本请自行指定插件名称
31+
```

0 commit comments

Comments
 (0)