Skip to main content

Nonebot2 会话级配置信息存储插件

Project description

logo

✨ nonebot-plugin-session-config ✨

LICENSE pypi python uv
ruff pre-commit

📖 介绍

本插件为每个会话(群聊、私聊等场景)提供了独立的持久化配置存储功能。

💿 安装

使用 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_session_config-1.0.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_session_config-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_session_config-1.0.0.tar.gz.

File metadata

  • Download URL: nonebot_plugin_session_config-1.0.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nonebot_plugin_session_config-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fe3149d66a565b45388c108d37c019b83b3a0a55fb715a07fc3a4b7117c9553d
MD5 d67bfa9e4fbb569578c1f918acf2acda
BLAKE2b-256 bd8c362be17d8609913a26bf9787fdffc374dae4734b693ffa9352f9d4712a31

See more details on using hashes here.

File details

Details for the file nonebot_plugin_session_config-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nonebot_plugin_session_config-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nonebot_plugin_session_config-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41ad5a0d05f83798710ca1403b75d199d4bf603e9bbcdaa5bf5ccd4b55118921
MD5 320206c18f51131d5241366ef0735701
BLAKE2b-256 64072c5586a8d0379f6f44ad6f7f99c5776c90f1747393785a28b0be8ed36d22

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page