Skip to content

Commit de4e5aa

Browse files
Merge pull request #5 from LiteSuggarDEV/patch-for-publish
按照Nonebot规范修改插件
1 parent fc7ece7 commit de4e5aa

File tree

10 files changed

+26
-289
lines changed

10 files changed

+26
-289
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# NoneBot Plugin LitePerms 文档
1+
# NoneBot Plugin LitePerm 文档
22

33
<div align="center">
44
<a href="https://github.com/JohnRichard4096/nonebot_plugin_liteperm/">
55
<img src="https://github.com/user-attachments/assets/b5162036-5b17-4cf4-b0cb-8ec842a71bc6" width="200" alt="SuggarChat Logo">
66
</a>
7-
<h1>LitePerms</h1>
7+
<h1>LitePerm</h1>
88
<h3>权限节点权限管理插件</h3>
99

1010
<p>
@@ -58,13 +58,13 @@
5858

5959
修改`pyproject.toml`,在`[tool.nonebot]`下的`plugins = ["nonebot_plugin_liteperm"]`添加插件
6060

61-
## 配置
62-
63-
```toml
64-
# 是否启用指令权限检查
65-
cmd_permission_checker=true
66-
```
6761

6862
## [指令文档](docs/commands.md)
6963

7064
## [API文档](docs/API.md)
65+
66+
## 内置权限节点
67+
68+
| 权限节点 | 权限描述 |
69+
| --- | --- |
70+
| `liteperm.admin` | LitePerm管理员 |

docs/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- **格式**:/lp
66
- **功能**:显示插件帮助信息
7-
- **响应**:LP LitePerms 请输入参数: lp user lp group lp perm_group lp command
7+
- **响应**:LP LitePerm 请输入参数: lp user lp group lp perm_group lp command
88

99
## 用户权限管理
1010

pyproject.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "nonebot_plugin_liteperm"
3-
version = "0.0.1.post3"
3+
version = "0.0.2"
44
description = "基于权限节点/权限组/特殊权限的Nonebot权限管理插件。"
55
authors = [
66
{ name = "JohnRichard4096", email = "[email protected]" },
@@ -14,14 +14,10 @@ dependencies = [
1414
"tomli>=2.2.1",
1515
"tomli-w>=1.2.0",
1616
]
17-
requires-python = ">=3.9, <4.0"
17+
requires-python = ">=3.10, <4.0"
1818
readme = "README.md"
1919
license = { text = "GPL-3.0-or-later" }
2020
keywords = ['nonebot']
21-
[build-system]
22-
requires = ['pdm-backend']
23-
build-backend = "pdm.backend"
24-
2521

2622
[tool.pdm]
2723
distribution = true
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import os
2-
3-
from dotenv import load_dotenv
1+
from nonebot import get_driver
42
from nonebot.adapters.onebot.v11 import Event
53

64
from ..config import UserData, data_manager
75
from ..nodelib import Permissions
86

9-
load_dotenv()
10-
ENV_ADMINS = os.getenv("LP_ADMINS", [])
7+
ENV_ADMINS = get_driver().config.superusers
118

129

1310
async def is_lp_admin(event: Event) -> bool:
@@ -16,6 +13,7 @@ async def is_lp_admin(event: Event) -> bool:
1613
"""
1714
user_id = event.get_user_id()
1815
user_data: UserData = data_manager.get_user_data(user_id)
19-
return user_id in ENV_ADMINS or Permissions(user_data.permissions).check_permission(
20-
"lp.admin"
21-
)
16+
return (
17+
user_id in ENV_ADMINS
18+
or Permissions(user_data.permissions).check_permission("lp.admin")
19+
) and data_manager.config.enable

src/nonebot_plugin_liteperm/command_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from nonebot.rule import to_me
33

44
command = CommandGroup(
5-
("lp", "LP", "LitePerms"), priority=10, block=True, rule=to_me(), prefix_aliases=True
5+
("lp", "LP", "LitePerm"), priority=10, block=True, rule=to_me(), prefix_aliases=True
66
)

src/nonebot_plugin_liteperm/commands/lp_command.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/nonebot_plugin_liteperm/commands/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ async def execute(
1919
async def lp(event: MessageEvent, matcher: Matcher, args: Message = CommandArg()):
2020
args_list = args.extract_plain_text().strip().split()
2121
if not args_list:
22-
lp_0_help = (
23-
"LP LitePerms\n请输入参数\nlp user\nlp chat_group\nlp perm_group\nlp command\n"
24-
)
22+
lp_0_help = "LP LitePerm\n请输入参数\nlp user\nlp chat_group\nlp perm_group\nlp command\n"
2523

2624
await matcher.finish(lp_0_help)

src/nonebot_plugin_liteperm/config.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@
1515
os.makedirs(config_dir, exist_ok=True)
1616

1717

18-
class BasicDataModel(BaseModel, extra="allow"):
19-
def __getattr__(self, item) -> str:
20-
if item in self.__dict__:
21-
return self.__dict__[item]
22-
if self.__pydantic_extra__ and item in self.__pydantic_extra__:
23-
return self.__pydantic_extra__[item]
24-
raise AttributeError(
25-
f"'{self.__class__.__name__}' object has no attribute '{item}'"
26-
)
18+
class BasicDataModel(BaseModel, extra="allow"): ...
2719

2820

2921
class UserData(BasicDataModel):
@@ -40,17 +32,8 @@ class PermissionGroupData(BasicDataModel):
4032
permissions: dict[str, str | dict | bool] = {}
4133

4234

43-
"""
44-
class CommandConfig(BasicDataModel):
45-
commands: dict[str, dict[str, bool]] = {"lp.user": {"lp.admin": True}}
46-
"""
47-
48-
4935
class Config(BasicDataModel):
50-
cmd_permission_checker: bool = Field(
51-
default=True,
52-
description="是否开启命令权限检查",
53-
)
36+
enable: bool = Field(default=True, description="是否启用插件")
5437

5538
def save_to_toml(self, path: Path):
5639
"""保存配置到 TOML 文件"""

src/nonebot_plugin_liteperm/hooks.py

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)