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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# NoneBot Plugin LitePerms 文档
# NoneBot Plugin LitePerm 文档

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

<p>
Expand Down Expand Up @@ -58,13 +58,13 @@

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

## 配置

```toml
# 是否启用指令权限检查
cmd_permission_checker=true
```

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

## [API文档](docs/API.md)

## 内置权限节点

| 权限节点 | 权限描述 |
| --- | --- |
| `liteperm.admin` | LitePerm管理员 |
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

## 用户权限管理

Expand Down
8 changes: 2 additions & 6 deletions 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.post3"
version = "0.0.2"
description = "基于权限节点/权限组/特殊权限的Nonebot权限管理插件。"
authors = [
{ name = "JohnRichard4096", email = "[email protected]" },
Expand All @@ -14,14 +14,10 @@ dependencies = [
"tomli>=2.2.1",
"tomli-w>=1.2.0",
]
requires-python = ">=3.9, <4.0"
requires-python = ">=3.10, <4.0"
readme = "README.md"
license = { text = "GPL-3.0-or-later" }
keywords = ['nonebot']
[build-system]
requires = ['pdm-backend']
build-backend = "pdm.backend"


[tool.pdm]
distribution = true
Expand Down
14 changes: 6 additions & 8 deletions src/nonebot_plugin_liteperm/API/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os

from dotenv import load_dotenv
from nonebot import get_driver
from nonebot.adapters.onebot.v11 import Event

from ..config import UserData, data_manager
from ..nodelib import Permissions

load_dotenv()
ENV_ADMINS = os.getenv("LP_ADMINS", [])
ENV_ADMINS = get_driver().config.superusers


async def is_lp_admin(event: Event) -> bool:
Expand All @@ -16,6 +13,7 @@ async def is_lp_admin(event: Event) -> bool:
"""
user_id = event.get_user_id()
user_data: UserData = data_manager.get_user_data(user_id)
return user_id in ENV_ADMINS or Permissions(user_data.permissions).check_permission(
"lp.admin"
)
return (
user_id in ENV_ADMINS
or Permissions(user_data.permissions).check_permission("lp.admin")
) and data_manager.config.enable
2 changes: 1 addition & 1 deletion src/nonebot_plugin_liteperm/command_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from nonebot.rule import to_me

command = CommandGroup(
("lp", "LP", "LitePerms"), priority=10, block=True, rule=to_me(), prefix_aliases=True
("lp", "LP", "LitePerm"), priority=10, block=True, rule=to_me(), prefix_aliases=True
)
95 changes: 0 additions & 95 deletions src/nonebot_plugin_liteperm/commands/lp_command.py

This file was deleted.

4 changes: 1 addition & 3 deletions src/nonebot_plugin_liteperm/commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ async def execute(
async def lp(event: MessageEvent, matcher: Matcher, args: Message = CommandArg()):
args_list = args.extract_plain_text().strip().split()
if not args_list:
lp_0_help = (
"LP LitePerms\n请输入参数\nlp user\nlp chat_group\nlp perm_group\nlp command\n"
)
lp_0_help = "LP LitePerm\n请输入参数\nlp user\nlp chat_group\nlp perm_group\nlp command\n"

await matcher.finish(lp_0_help)
21 changes: 2 additions & 19 deletions src/nonebot_plugin_liteperm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
os.makedirs(config_dir, exist_ok=True)


class BasicDataModel(BaseModel, extra="allow"):
def __getattr__(self, item) -> str:
if item in self.__dict__:
return self.__dict__[item]
if self.__pydantic_extra__ and item in self.__pydantic_extra__:
return self.__pydantic_extra__[item]
raise AttributeError(
f"'{self.__class__.__name__}' object has no attribute '{item}'"
)
class BasicDataModel(BaseModel, extra="allow"): ...


class UserData(BasicDataModel):
Expand All @@ -40,17 +32,8 @@ 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):
cmd_permission_checker: bool = Field(
default=True,
description="是否开启命令权限检查",
)
enable: bool = Field(default=True, description="是否启用插件")

def save_to_toml(self, path: Path):
"""保存配置到 TOML 文件"""
Expand Down
127 changes: 0 additions & 127 deletions src/nonebot_plugin_liteperm/hooks.py

This file was deleted.

Loading