Skip to main content

Nonebot2 群聊配置信息存储与管理插件

Project description

NoneBotLogo

nonebot-plugin-group-config

✨ Nonebot2 群聊配置信息存储与管理插件 ✨

license pypi python

📖 介绍

本插件以插件调用与指令控制的方式管理不同群聊的配置信息,支持配置信息的持久化存储。

💿 安装

  • 使用 nb-cli 安装
nb plugin install nonebot-plugin-group-config
  • 使用包管理器安装
pip install nonebot-plugin-group-config

⚙️ 配置

配置项 必填 默认值 说明
GROUP_CONFIG_PATH 配置文件的存储文件夹
GROUP_CONFIG_FORMAT group-{}.json 配置文件的名称格式化模板
GROUP_CONFIG_ENABLE_COMMAND true 启用对话中的/config指令

🎉 使用

插件调用

每个群聊有单独的配置文件,配置文件为二级字典,一级字段默认为调用的插件名称,二级字段为配置项。

在使用其他插件时,可以通过GroupConfigManager类来管理配置信息。创建GroupConfigManager对象时,需要传入默认配置信息。

from nonebot_plugin_group_config import GroupConfigManager, GLOBAL

# 在插件中调用,默认使用插件名称作为一级字段
config_manager1 = GroupConfigManager({
  "key1": "value1",
  "key2": 2
})

# 使用指定的一级字段
config_manager2 = GroupConfigManager({
  "key1": "value1",
  "key2": 2
}, "scope")

# 使用全局字段,在配置文件中以`GLOBAL`为一级字段
global_config_manager = GroupConfigManager({
  "key1": "value1",
  "key2": 2
}, GLOBAL)

上文获取的配置管理器可以通过以群ID为键获取指定群聊对应的二级字段信息,返回 GroupConfig 对象。修改字段时不能添加新字段,对 GroupConfig 对象的操作会直接修改配置文件。

group_config = config_manager1[group_id] # 此处的 group_id 为 str 类型

print(group_config["key1"]) # value1
group_config["key2"] = -1

注:获取 GroupConfig 对象时若对应的群聊配置信息文件不存在,会根据已注册的所有管理器的默认配置信息创建新的配置文件。也可以通过 GroupConfigManager.complete_config 方法手动创建/补全配置文件。

指令调用

管理员与超级用户可以在群聊中通过指令对群聊配置进行管理。

使用 /config 指令查看当前群聊的所有可用配置字段,这些字段会以 <一级字段>.<二级字段> 的形式显示,但 GLOBAL 字段不会显示其一级字段。

使用 /config <一级字段>.<二级字段> <值> 指令可以设置指定的配置字段,但不能创建不存在的字段,配置后的值与旧值类型相同。

TODO

  • 获取所有群聊配置信息的接口
  • 超级管理员私聊指令
  • 多级字段支持

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_group_config-0.1.0.tar.gz (5.7 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_group_config-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file nonebot_plugin_group_config-0.1.0.tar.gz.

File metadata

File hashes

Hashes for nonebot_plugin_group_config-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c54cb81c36d01509f2b8a32ecb8102c24cb232374a2db73e1d3c882a5c4ab71a
MD5 18b4554a95988386458c5434158f65ea
BLAKE2b-256 50a1f3bbd65d9e2466b25b232fb509ffa90b303808cffc489f28cb5f70f32f52

See more details on using hashes here.

File details

Details for the file nonebot_plugin_group_config-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nonebot_plugin_group_config-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85d158343a0fc888e08e37c247759540157687ecd4c2865cb373e4f355e401b9
MD5 f9b9b7b69e6b05c9e01248ea8ba96002
BLAKE2b-256 0943a86ac02bca6959d3b6b4e16b51fec97b00daa05570b31fcd9b383247cd46

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