diff --git a/README.md b/README.md index 4b1fac2..eec28ad 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ - 节点权限管理 - 特殊权限管理 - 权限组管理 -- 特定指令权限管理 +- 用户/群 权限分配 ## 快速开始 diff --git a/docs/commands.md b/docs/commands.md index ca428de..e759268 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -120,38 +120,6 @@ -## 指令权限管理 - -
- -### `lp command` - 命令权限设置 - -- **格式**:`lp command <命令名> <操作类型> <操作> [节点] [值]` -- **操作类型**: - - `set_permission` - 设置命令权限 - - `command` - 命令管理 - - `list` - 列表查看 - -#### 权限设置 (`set_permission`) - -| 操作 | 格式 | 示例 | 说明 | -|-----------|-----------------------------------|--------------------------|--------------------------| -| `set` | `lp command <命令> set_permission set <节点> ` | `lp command lp.admin set_permission set user.edit true` | 设置命令权限节点 | -| `del` | `lp command <命令> set_permission del <节点>` | `lp command lp.admin set_permission del user.edit` | 删除命令权限节点 | - -#### 命令管理 (`command`) - -| 操作 | 格式 | 示例 | 说明 | -|-----------|-----------------------------------|--------------------------|--------------------------| -| `del` | `lp command <命令> command del` | `lp command lp.user command del` | 删除命令的所有权限设置 | - -#### 列表查看 (`list`) - -| 操作 | 格式 | 示例 | 说明 | -|-----------|-----------------------------------|--------------------------|--------------------------| -| `list` | `lp command list` | `lp command list` | 列出所有已配置的命令权限 | - -
## 通用参数说明 diff --git a/pyproject.toml b/pyproject.toml index 24ca9fe..06e783c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nonebot_plugin_liteperm" -version = "0.0.1.post2" +version = "0.0.1.post3" description = "基于权限节点/权限组/特殊权限的Nonebot权限管理插件。" authors = [ { name = "JohnRichard4096", email = "windowserror@163.com" }, diff --git a/src/nonebot_plugin_liteperm/API/config.py b/src/nonebot_plugin_liteperm/API/config.py new file mode 100644 index 0000000..65d28db --- /dev/null +++ b/src/nonebot_plugin_liteperm/API/config.py @@ -0,0 +1,5 @@ +from .. import config + +__all__ = [ + "config", +] diff --git a/src/nonebot_plugin_liteperm/API/node.py b/src/nonebot_plugin_liteperm/API/node.py index 639482c..8fadc2c 100644 --- a/src/nonebot_plugin_liteperm/API/node.py +++ b/src/nonebot_plugin_liteperm/API/node.py @@ -1 +1,5 @@ -from ..nodelib import Permissions # noqa: F401 +from .. import nodelib + +__all__ = [ + "nodelib", +] \ No newline at end of file diff --git a/src/nonebot_plugin_liteperm/__init__.py b/src/nonebot_plugin_liteperm/__init__.py index e489f68..c6eaa74 100644 --- a/src/nonebot_plugin_liteperm/__init__.py +++ b/src/nonebot_plugin_liteperm/__init__.py @@ -1,15 +1,19 @@ from nonebot.plugin import PluginMetadata, require require("nonebot_plugin_localstore") -from . import command_manager, config, hooks, on_init -from .commands import lp_chat_group, lp_command, lp_perm_group, lp_user, main +from . import command_manager, config, on_init + +# ,hooks +from .commands import lp_chat_group, lp_perm_group, lp_user, main + +# ,lp_command __all__ = [ "command_manager", "config", - "hooks", + # "hooks", "lp_chat_group", - "lp_command", + # "lp_command", "lp_perm_group", "lp_user", "main", diff --git a/src/nonebot_plugin_liteperm/commands/lp_command.py b/src/nonebot_plugin_liteperm/commands/lp_command.py index b72974f..5e2d23f 100644 --- a/src/nonebot_plugin_liteperm/commands/lp_command.py +++ b/src/nonebot_plugin_liteperm/commands/lp_command.py @@ -1,3 +1,4 @@ +""" import asyncio from typing import Any, override @@ -90,3 +91,5 @@ async def lp_user( data_manager.save_command_settings(CommandConfig(**data)) await matcher.finish(result) + +""" diff --git a/src/nonebot_plugin_liteperm/config.py b/src/nonebot_plugin_liteperm/config.py index d7e2d83..4820a2d 100644 --- a/src/nonebot_plugin_liteperm/config.py +++ b/src/nonebot_plugin_liteperm/config.py @@ -40,8 +40,10 @@ class PermissionGroupData(BasicDataModel): permissions: dict[str, str | dict | bool] = {} +""" class CommandConfig(BasicDataModel): commands: dict[str, dict[str, bool]] = {"lp.user": {"lp.admin": True}} +""" class Config(BasicDataModel): @@ -77,8 +79,8 @@ class Data_Manager: user_data_path: Path = plugin_data_dir / "user_data" permission_groups_path: Path = plugin_data_dir / "permission_groups" config_path: Path = config_dir / "config.toml" - cmd_settings_path = plugin_data_dir / "command_settings.json" - config: Config = field(default_factory = Config) + # cmd_settings_path = plugin_data_dir / "command_settings.json" + config: Config = field(default_factory=Config) def init(self): os.makedirs(self.group_data_path, exist_ok=True) @@ -90,6 +92,8 @@ def init(self): self.config.save_to_toml(self.config_path) else: self.config = Config.load_from_toml(self.config_path) + + """ if not self.cmd_settings_path.exists(): cmd_settings = CommandConfig() with open(self.cmd_settings_path, "w") as f: @@ -97,6 +101,7 @@ def init(self): else: with open(self.cmd_settings_path) as f: self.cmd_settings = CommandConfig.model_validate_json(f.read()) +""" def save_user_data(self, user_id: str, data: dict[str, str | dict | bool]): UserData.model_validate(data) @@ -158,6 +163,8 @@ def get_user_data(self, user_id: str): with open(data_path) as f: return UserData(**json.load(f)) + +""" def get_command_settings(self): with open(self.cmd_settings_path) as f: return CommandConfig(**json.load(f)) @@ -165,6 +172,6 @@ def get_command_settings(self): def save_command_settings(self, data: CommandConfig): with open(self.cmd_settings_path, "w") as f: json.dump(data.model_dump(), f) - +""" data_manager = Data_Manager() diff --git a/src/nonebot_plugin_liteperm/hooks.py b/src/nonebot_plugin_liteperm/hooks.py index 81b0ab6..cde770a 100644 --- a/src/nonebot_plugin_liteperm/hooks.py +++ b/src/nonebot_plugin_liteperm/hooks.py @@ -1,3 +1,4 @@ +""" import nonebot.matcher as nbm from nonebot import get_driver, logger from nonebot.adapters import Event @@ -14,7 +15,7 @@ @event_preprocessor -async def check_on_command(matcher: Matcher, event: Event): +async def check_on_command(event: Event): # 获取消息文本并去除首尾空格 msg = event.get_message().extract_plain_text().strip() user_id = event.get_user_id() @@ -122,3 +123,5 @@ async def check_on_command(matcher: Matcher, event: Event): raise e except Exception as e: logger.error(f"Matcher检查错误: {e}") + +"""