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_FORMAT group-{}.json 配置文件的名称格式化模板
GROUP_CONFIG_ENABLE_COMMAND true 启用对话中的/config指令,如果该项为列表则指令只获取列表中的作用域

本插件使用 localstore 插件进行存储,若需要修改群聊配置文件的存储路径,请参考 localstore 插件的说明更改 LOCALSTORE_PLUGIN_CONFIG_DIR 配置项。

🎉 使用

插件调用

每个群聊有单独的配置文件,配置文件为二级字典,一级字段为作用域,二级字段为该作用域下的配置项。配置文件存储于 localstore 配置文件夹的 group_config 文件夹下。

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

from nonebot_plugin_group_config import GroupConfigManager, GLOBAL

# 默认使用去除 nonebot_plugin_ 前缀的插件名称作为作用域
config_manager1 = GroupConfigManager({
  "key1": "value1",
  "key2": 2
})

# 使用自定义作用域
config_manager2 = GroupConfigManager({
  "key1": "value1",
  "key2": 2
}, "my_scope")

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

同一作用域的配置管理器只能声明一次。可以通过 GroupConfigManager.get_manager 方法获取已注册的配置管理器,若不存在则返回 None

配置管理器可以通过 get_group_config 方法获取指定群聊的 GroupConfig 对象,其中包含该作用域下的全部配置项。

group_config = config_manager1.get_group_config(group_id)

print(group_config["key1"]) # 输出:value1
group_config["key2"] = -1 # 只能修改已存在的配置项

注:获取 GroupConfig 对象时若对应的群聊配置信息文件不存在,会根据已注册的所有管理器的默认配置信息创建新的配置文件,对 GroupConfig 对象的操作会直接修改配置文件。

指令调用

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

使用 /config 指令查看当前群聊的所有可用配置项,这些配置项会以 <作用域>.<配置项> 的形式显示,但全局作用域不会显示其作用域名称。

使用 /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.2.0.tar.gz (6.2 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.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for nonebot_plugin_group_config-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a392ae73101dbd2c8df67be51eadf5ac55ba6736fcd00cd10cf78bf71b4a9ecc
MD5 164437a90453c9d607351e33d0c2241c
BLAKE2b-256 f96fc3ab7a3a8e9b7a4b310719c960844594304a6f0ab2aafd031fe8c55ca8fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nonebot_plugin_group_config-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90b349003d5f709bc11a5a9a8cbb39de285313c2634c4ee11411f6e98eb89940
MD5 e4ed67c514e610c33c69394c8e6c6c9a
BLAKE2b-256 3a1038fbd4394570507ee1db500dfca0c4737ad8c04ddd6174b35fbb9aefb60d

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