Skip to content

Commit 949caae

Browse files
committed
๐ŸŽจ ้ƒจๅˆ†ไปฃ็ ้€ป่พ‘็ฎ€ๅŒ–
1 parent cd61efe commit 949caae

File tree

10 files changed

+33
-34
lines changed

10 files changed

+33
-34
lines changed

โ€Žsrc/nonebot_plugin_liteperm/API/rules.pyโ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def checker(self) -> Callable[[Event, str], Awaitable[bool]]:
4848
"""
4949

5050
# ๆ•่Žทๅฝ“ๅ‰ๆƒ้™ๅ€ผๅˆฐ้—ญๅŒ…ไธญ
51-
current_perm = self.permission if self.permission else ""
51+
current_perm = self.permission or ""
5252

5353
async def _checker(event: Event, current_perm=current_perm) -> bool:
5454
"""ๅฎž้™…ๆ‰ง่กŒๆฃ€ๆŸฅ็š„ๅ็จ‹ๅ‡ฝๆ•ฐ"""
@@ -100,9 +100,9 @@ class GroupPermissionChecker(PermissionChecker):
100100
async def _check_permission(self, event: Event, perm: str) -> bool:
101101
if not isinstance(event, GroupEvent) and not self.only_group:
102102
return True
103-
elif not isinstance(event, GroupEvent) and self.only_group:
103+
elif not isinstance(event, GroupEvent):
104104
return False
105-
elif isinstance(event, GroupEvent):
105+
else:
106106
g_event: GroupEvent = event
107107
group_id: str = str(g_event.group_id)
108108
group_data = data_manager.get_group_data(group_id)

โ€Žsrc/nonebot_plugin_liteperm/__init__.pyโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
]
1818

1919
__plugin_meta__ = PluginMetadata(
20-
name="LitePerm ๆƒ้™็ฎก็†ๆ’ไปถ", # type: ignore
20+
name="LitePerm ๆƒ้™็ฎก็†ๆ’ไปถ",
2121
description="ๅŸบไบŽๆƒ้™่Š‚็‚น/ๆƒ้™็ป„/็‰นๆฎŠๆƒ้™็š„ๆƒ้™็ฎก็†ๆ’ไปถใ€‚",
2222
usage="https://github.com/LiteSuggarDEV/plugin-liteperm/blob/main/README.md",
2323
homepage="https://github.com/LiteSuggarDEV/plugin-liteperm/",

โ€Žsrc/nonebot_plugin_liteperm/commands/lp_chat_group.pyโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def get_handler(
113113
"parent": ParentGroupHandler(),
114114
"perm_group": PermissionGroupHandler(),
115115
}
116-
return handlers[action_type] if action_type in handlers else None
116+
return handlers.get(action_type)
117117

118118

119119
# ่ฟ่กŒ่ฟ›ๅ…ฅ็‚น

โ€Žsrc/nonebot_plugin_liteperm/commands/lp_command.pyโ€Ž

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ async def execute(
3939
) -> tuple[str, dict[str, Any]]:
4040
result = "โŒ ๆ“ไฝœๅคฑ่ดฅ"
4141
command_data = data_manager.get_command_settings()
42-
if operation == "del":
43-
if command in command_data.commands:
44-
del command_data.commands[command]
45-
result = "โœ… ๆ“ไฝœๆˆๅŠŸ"
42+
if operation == "del" and command in command_data.commands:
43+
del command_data.commands[command]
44+
result = "โœ… ๆ“ไฝœๆˆๅŠŸ"
4645
return result, command_data.model_dump()
4746

4847

@@ -67,7 +66,7 @@ def get_handler(
6766
"command": DelPermissionSetting(),
6867
"list": ListHandler(),
6968
}
70-
return handlers[action_type] if action_type in handlers else None
69+
return handlers.get(action_type)
7170

7271

7372
@command.command("command", permission=is_lp_admin).handle()

โ€Žsrc/nonebot_plugin_liteperm/commands/lp_perm_group.pyโ€Ž

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,13 @@ async def execute(
9292
if operation == "create":
9393
if data_manager.get_permission_group_data(group) is not None:
9494
return "โŒ ๆƒ้™็ป„ๅทฒๅญ˜ๅœจ", {}
95-
else:
96-
data_manager.get_permission_group_data(group, True)
97-
return "โœ… ๆƒ้™็ป„ๅˆ›ๅปบๆˆๅŠŸ", {}
95+
data_manager.get_permission_group_data(group, True)
96+
return "โœ… ๆƒ้™็ป„ๅˆ›ๅปบๆˆๅŠŸ", {}
9897
elif operation == "remove":
9998
if data_manager.get_permission_group_data(group) is None:
10099
return "โŒ ๆƒ้™็ป„ไธๅญ˜ๅœจ", {}
101-
else:
102-
data_manager.remove_permission_group(group)
103-
return "โœ… ๆƒ้™็ป„ๅˆ ้™คๆˆๅŠŸ", {}
100+
data_manager.remove_permission_group(group)
101+
return "โœ… ๆƒ้™็ป„ๅˆ ้™คๆˆๅŠŸ", {}
104102
return "โŒ ๆ“ไฝœ้”™่ฏฏ", {}
105103

106104
def get_handler(
@@ -111,7 +109,7 @@ def get_handler(
111109
"parent": ParentGroupHandler(),
112110
"to":PermissionGroupHandler(),
113111
}
114-
return handlers[action_type] if action_type in handlers else None
112+
return handlers.get(action_type)
115113

116114

117115
# ่ฟ่กŒ่ฟ›ๅ…ฅ็‚น

โ€Žsrc/nonebot_plugin_liteperm/commands/lp_user.pyโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def get_handler(
112112
"parent": ParentGroupHandler(),
113113
"perm_group": PermissionGroupHandler(),
114114
}
115-
return handlers[action_type] if action_type in handlers else None
115+
return handlers.get(action_type)
116116

117117

118118
# ่ฟ่กŒ่ฟ›ๅ…ฅ็‚น

โ€Žsrc/nonebot_plugin_liteperm/commands/main.pyโ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ async def execute(
1818
@command.command("", rule=to_me()).handle()
1919
async def lp(event: MessageEvent, matcher: Matcher, args: Message = CommandArg()):
2020
args_list = args.extract_plain_text().strip().split()
21-
lp_0_help = (
22-
"LP LitePerms\n่ฏท่พ“ๅ…ฅๅ‚ๆ•ฐ\nlp user\nlp chat_group\nlp perm_group\nlp command\n"
23-
)
24-
2521
if not args_list:
22+
lp_0_help = (
23+
"LP LitePerms\n่ฏท่พ“ๅ…ฅๅ‚ๆ•ฐ\nlp user\nlp chat_group\nlp perm_group\nlp command\n"
24+
)
25+
2626
await matcher.finish(lp_0_help)

โ€Žsrc/nonebot_plugin_liteperm/config.pyโ€Ž

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ def get_permission_group_data(
130130
self, group_name: str, new: bool = False
131131
) -> PermissionGroupData | None:
132132
data_path = self.permission_groups_path / f"{group_name}.json"
133-
if not data_path.exists() and new:
134-
data = PermissionGroupData()
135-
with open(data_path, "w") as f:
136-
json.dump(data.model_dump(), f)
137-
return data
138-
elif not data_path.exists():
139-
return None
133+
if not data_path.exists():
134+
if not new:
135+
return None
136+
else:
137+
data = PermissionGroupData()
138+
with open(data_path, "w") as f:
139+
json.dump(data.model_dump(), f)
140+
return data
140141
with open(data_path) as f:
141142
return PermissionGroupData(**json.load(f))
142143

โ€Žsrc/nonebot_plugin_liteperm/hooks.pyโ€Ž

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ async def check_on_command(matcher: Matcher, event: Event):
109109
).permissions # type: ignore
110110
).check_permission(permission):
111111
return
112-
else:
113-
raise IgnoredException(
114-
f"Permission {permission} denied"
115-
)
112+
raise IgnoredException(
113+
f"Permission {permission} denied"
114+
)
116115
else:
117116
raise IgnoredException(
118117
f"Permission {permission} denied"

โ€Žsrc/nonebot_plugin_liteperm/nodelib.pyโ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
class Permissions:
77
permissions_data: dict[str, str | dict | bool]
88

9-
def __init__(self, permissions_data: dict[str, str | dict | bool] = {}) -> None:
9+
def __init__(self, permissions_data: dict[str, str | dict | bool] | None = None) -> None:
10+
if permissions_data is None:
11+
permissions_data = {}
1012
self.permissions_data = permissions_data
1113

1214
__permissions_str: str = ""

0 commit comments

Comments
ย (0)