mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
📝 Docs: 更新 localstore 插件文档 (#2871)
This commit is contained in:
parent
79c7ea5bab
commit
214bc838c2
@ -31,17 +31,17 @@ require("nonebot_plugin_localstore")
|
|||||||
import nonebot_plugin_localstore as store
|
import nonebot_plugin_localstore as store
|
||||||
|
|
||||||
# 获取插件缓存目录
|
# 获取插件缓存目录
|
||||||
cache_dir = store.get_cache_dir("plugin_name")
|
cache_dir = store.get_plugin_cache_dir()
|
||||||
# 获取插件缓存文件
|
# 获取插件缓存文件
|
||||||
cache_file = store.get_cache_file("plugin_name", "file_name")
|
cache_file = store.get_plugin_cache_file("file_name")
|
||||||
# 获取插件数据目录
|
# 获取插件数据目录
|
||||||
data_dir = store.get_data_dir("plugin_name")
|
data_dir = store.get_plugin_data_dir()
|
||||||
# 获取插件数据文件
|
# 获取插件数据文件
|
||||||
data_file = store.get_data_file("plugin_name", "file_name")
|
data_file = store.get_plugin_data_file("file_name")
|
||||||
# 获取插件配置目录
|
# 获取插件配置目录
|
||||||
config_dir = store.get_config_dir("plugin_name")
|
config_dir = store.get_plugin_config_dir()
|
||||||
# 获取插件配置文件
|
# 获取插件配置文件
|
||||||
config_file = store.get_config_file("plugin_name", "file_name")
|
config_file = store.get_plugin_config_file("file_name")
|
||||||
```
|
```
|
||||||
|
|
||||||
:::danger 警告
|
:::danger 警告
|
||||||
@ -53,9 +53,61 @@ config_file = store.get_config_file("plugin_name", "file_name")
|
|||||||
```python
|
```python
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
data_file = store.get_data_file("plugin_name", "file_name")
|
data_file = store.get_plugin_data_file("file_name")
|
||||||
# 写入文件内容
|
# 写入文件内容
|
||||||
data_file.write_text("Hello World!")
|
data_file.write_text("Hello World!")
|
||||||
# 读取文件内容
|
# 读取文件内容
|
||||||
data = data_file.read_text()
|
data = data_file.read_text()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
:::note 提示
|
||||||
|
|
||||||
|
对于嵌套插件,子插件的存储目录将位于父插件存储目录下。
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
## 配置项
|
||||||
|
|
||||||
|
### localstore_cache_dir
|
||||||
|
|
||||||
|
自定义缓存目录
|
||||||
|
|
||||||
|
默认值:
|
||||||
|
|
||||||
|
- macOS: `~/Library/Caches/<AppName>`
|
||||||
|
- Unix: `~/.cache/<AppName>` (XDG default)
|
||||||
|
- Windows: `C:\Users\<username>\AppData\Local\<AppName>\Cache`
|
||||||
|
|
||||||
|
```dotenv
|
||||||
|
LOCALSTORE_CACHE_DIR=/tmp/cache
|
||||||
|
```
|
||||||
|
|
||||||
|
### localstore_data_dir
|
||||||
|
|
||||||
|
自定义数据目录
|
||||||
|
|
||||||
|
默认值:
|
||||||
|
|
||||||
|
- macOS: `~/Library/Application Support/<AppName>`
|
||||||
|
- Unix: `~/.local/share/<AppName>` or in $XDG_DATA_HOME, if defined
|
||||||
|
- Win XP (not roaming): `C:\Documents and Settings\<username>\Application Data\<AppName>`
|
||||||
|
- Win 7 (not roaming): `C:\Users\<username>\AppData\Local\<AppName>`
|
||||||
|
|
||||||
|
```dotenv
|
||||||
|
LOCALSTORE_DATA_DIR=/tmp/data
|
||||||
|
```
|
||||||
|
|
||||||
|
### localstore_config_dir
|
||||||
|
|
||||||
|
自定义配置目录
|
||||||
|
|
||||||
|
默认值:
|
||||||
|
|
||||||
|
- macOS: same as user_data_dir
|
||||||
|
- Unix: `~/.config/<AppName>`
|
||||||
|
- Win XP (roaming): `C:\Documents and Settings\<username>\Local Settings\Application Data\<AppName>`
|
||||||
|
- Win 7 (roaming): `C:\Users\<username>\AppData\Roaming\<AppName>`
|
||||||
|
|
||||||
|
```dotenv
|
||||||
|
LOCALSTORE_CONFIG_DIR=/tmp/config
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user