Nonebot2 会话级配置信息存储插件
Project description
📖 介绍
本插件为每个会话(群聊、私聊等场景)提供了独立的持久化配置存储功能。
💿 安装
使用 nb-cli 安装
nb plugin install nonebot-plugin-session-config --upgrade
使用 uv 安装
uv add nonebot-plugin-session-config
安装仓库 master 分支
uv add git+https://github.com/USTC-XeF2/nonebot-plugin-session-config@master
打开 nonebot2 项目根目录下的 pyproject.toml 文件, 在 [tool.nonebot.plugins] 部分追加写入
"@local" = ["nonebot_plugin_session_config"]
⚙️ 配置
所有配置项均以 SESSION_CONFIG_ 为前缀(下文省略),且均为选填项。
| 配置项 | 默认值 | 说明 |
|---|---|---|
| BASE_DIR | None | 配置存储的根目录,值为 None 时使用 localstore 提供的配置文件目录,一般不需要更改 |
| DIR_FORMAT | bot-{bot_id} | 各机器人所属目录的命名格式,不使用 bot_id 模板参数时所有机器人共用同一目录 |
| FILE_FORMAT | {scene_type}-{scene_id}.yaml | 配置文件的命名格式 |
| USE_GLOBAL | False | 是否尝试使用全局配置作为默认值,开启此项时请确保会话配置与全局配置间没有意料外的重复键 |
| ENABLE_PARAM | False | 是否启用会话配置参数注入功能,启用后可直接指定会话配置类作为消息处理函数参数类型,在插件冲突时可能会注入失败 |
🎉 使用
from nonebot import on_message
from nonebot_plugin_session_config import (
BaseSessionConfig,
check_enabled,
get_session_config,
)
# 所有会话配置类均应继承自 BaseSessionConfig
class SessionConfig(BaseSessionConfig):
test_enabled: bool = False
test_key: int = 0
message_handler = on_message(
rule=check_enabled(SessionConfig, "test_enabled"),
)
@message_handler.handle()
async def _(session_config: SessionConfig = get_session_config(SessionConfig)):
await message_handler.finish(f"Test key value is: {session_config.test_key}")
# 使用自动参数注入(需在配置中启用 ENABLE_PARAM 选项)
@message_handler.handle()
async def _(session_config: SessionConfig):
await message_handler.finish(f"Test key value is: {session_config.test_key}")
本插件提供的配置不提供在程序中动态修改的接口,若需要修改请手动或自动编辑对应的文件,无需重启即可更新。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_session_config-1.0.1.tar.gz.
File metadata
- Download URL: nonebot_plugin_session_config-1.0.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f235f053f442e593aa1744b614fd5f2415b03acd36aa0247719535ee0d3a8bad
|
|
| MD5 |
db3fbaa03f555d6064ff2f6b56cecce6
|
|
| BLAKE2b-256 |
486a703c4312681f2c75ac12368391386c499094103e3d72d1739cdd61115e1e
|
Provenance
The following attestation bundles were made for nonebot_plugin_session_config-1.0.1.tar.gz:
Publisher:
release.yml on USTC-XeF2/nonebot-plugin-session-config
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nonebot_plugin_session_config-1.0.1.tar.gz -
Subject digest:
f235f053f442e593aa1744b614fd5f2415b03acd36aa0247719535ee0d3a8bad - Sigstore transparency entry: 1203293765
- Sigstore integration time:
-
Permalink:
USTC-XeF2/nonebot-plugin-session-config@5527d5d7e7fd359ca3949dec4296d4cecd9c40ff -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/USTC-XeF2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5527d5d7e7fd359ca3949dec4296d4cecd9c40ff -
Trigger Event:
push
-
Statement type:
File details
Details for the file nonebot_plugin_session_config-1.0.1-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_session_config-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f681954a483633eb67cd73611bb4ff2c2c112b5a167a5795842c5593beb5449a
|
|
| MD5 |
cabee122fa489bf603b2b02ff4c01b5d
|
|
| BLAKE2b-256 |
fd3fdc0cf6ccae33552c58d1c1922942981c84cf2d203193082c534160bcb7d2
|
Provenance
The following attestation bundles were made for nonebot_plugin_session_config-1.0.1-py3-none-any.whl:
Publisher:
release.yml on USTC-XeF2/nonebot-plugin-session-config
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nonebot_plugin_session_config-1.0.1-py3-none-any.whl -
Subject digest:
f681954a483633eb67cd73611bb4ff2c2c112b5a167a5795842c5593beb5449a - Sigstore transparency entry: 1203293768
- Sigstore integration time:
-
Permalink:
USTC-XeF2/nonebot-plugin-session-config@5527d5d7e7fd359ca3949dec4296d4cecd9c40ff -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/USTC-XeF2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5527d5d7e7fd359ca3949dec4296d4cecd9c40ff -
Trigger Event:
push
-
Statement type: