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

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

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

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.1.3.tar.gz (5.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_group_config-0.1.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for nonebot_plugin_group_config-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e9dbbae8356feb5c68ba0fb53e327af1f6e82fae1747e6383526e469b5f471ca
MD5 c22dbac77e4583d05777c7d952b086d5
BLAKE2b-256 933ce084f21c6fe017670997a0c639ebd081d5f218d12eceeac2c2044e11f97a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nonebot_plugin_group_config-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf7359ab24cd6b0dc88434d6f127bb9c1f2dbb7a6560430e8be7e9c74b141cde
MD5 7c737709290e2d9beb67b323c8803bd0
BLAKE2b-256 72781b508097d5a4c6b8f30df619b0579d7322b638efc08349cc0141a689abee

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