Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- 节点权限管理
- 特殊权限管理
- 权限组管理
- 特定指令权限管理
- 用户/群 权限分配

## 快速开始

Expand Down
32 changes: 0 additions & 32 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,38 +120,6 @@

</details>

## 指令权限管理

<details>

### `lp command` - 命令权限设置

- **格式**:`lp command <命令名> <操作类型> <操作> [节点] [值]`
- **操作类型**:
- `set_permission` - 设置命令权限
- `command` - 命令管理
- `list` - 列表查看

#### 权限设置 (`set_permission`)

| 操作 | 格式 | 示例 | 说明 |
|-----------|-----------------------------------|--------------------------|--------------------------|
| `set` | `lp command <命令> set_permission set <节点> <true/false>` | `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` | 列出所有已配置的命令权限 |

</details>

## 通用参数说明

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" },
Expand Down
5 changes: 5 additions & 0 deletions src/nonebot_plugin_liteperm/API/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .. import config

__all__ = [
"config",
]
6 changes: 5 additions & 1 deletion src/nonebot_plugin_liteperm/API/node.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from ..nodelib import Permissions # noqa: F401
from .. import nodelib

__all__ = [
"nodelib",
]
12 changes: 8 additions & 4 deletions src/nonebot_plugin_liteperm/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/nonebot_plugin_liteperm/commands/lp_command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""
import asyncio
from typing import Any, override

Expand Down Expand Up @@ -90,3 +91,5 @@ async def lp_user(
data_manager.save_command_settings(CommandConfig(**data))

await matcher.finish(result)

"""
13 changes: 10 additions & 3 deletions src/nonebot_plugin_liteperm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -90,13 +92,16 @@ 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:
json.dump(cmd_settings.model_dump(), f, indent=4)
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)
Expand Down Expand Up @@ -158,13 +163,15 @@ 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))

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()
5 changes: 4 additions & 1 deletion src/nonebot_plugin_liteperm/hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""
import nonebot.matcher as nbm
from nonebot import get_driver, logger
from nonebot.adapters import Event
Expand All @@ -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()
Expand Down Expand Up @@ -122,3 +123,5 @@ async def check_on_command(matcher: Matcher, event: Event):
raise e
except Exception as e:
logger.error(f"Matcher检查错误: {e}")

"""