版本更新

This commit is contained in:
HibiKier
2024-10-20 21:11:16 +08:00
parent 4e33bf3a50
commit d594d17bf6
253 changed files with 34987 additions and 2241 deletions
+39 -9
View File
@@ -1,10 +1,12 @@
from nonebot.adapters import Bot, Event
from nonebot.internal.rule import Rule
from nonebot.adapters import Bot, Event
from nonebot.permission import SUPERUSER
from nonebot_plugin_session import EventSession, SessionLevel
from nonebot_plugin_uninfo import Uninfo
from nonebot_plugin_session import EventSession
from zhenxun.configs.config import Config
from zhenxun.models.level_user import LevelUser
from zhenxun.utils.platform import PlatformUtils
def admin_check(a: int | str, key: str | None = None) -> Rule:
@@ -19,33 +21,38 @@ def admin_check(a: int | str, key: str | None = None) -> Rule:
Rule: Rule
"""
async def _rule(bot: Bot, event: Event, session: EventSession) -> bool:
async def _rule(bot: Bot, event: Event, session: Uninfo) -> bool:
if await SUPERUSER(bot, event):
return True
if session.id1 and session.id2:
if PlatformUtils.is_qbot(session):
"""官bot接口,放弃所有权限检查"""
return False
if session.id and session.group:
level = a
if type(a) == str and key:
if isinstance(a, str) and key:
level = Config.get_config(a, key)
if level is not None:
return bool(
await LevelUser.check_level(session.id1, session.id2, int(level))
await LevelUser.check_level(
session.id, session.group.id, int(level)
)
)
return False
return Rule(_rule)
def ensure_group(session: EventSession) -> bool:
def ensure_group(session: Uninfo) -> bool:
"""
是否在群聊中
参数:
session: session
session: Uninfo
返回:
bool: bool
"""
return session.level in [SessionLevel.LEVEL2, SessionLevel.LEVEL3]
return bool(session.group)
def ensure_private(session: EventSession) -> bool:
@@ -59,3 +66,26 @@ def ensure_private(session: EventSession) -> bool:
bool: bool
"""
return not session.id3 and not session.id2
def notice_rule(event_type: type | list[type]) -> Rule:
"""
Notice限制
参数:
event_type: Event类型
返回:
Rule: Rule
"""
async def _rule(event: Event) -> bool:
if isinstance(event_type, list):
for et in event_type:
if isinstance(event, et):
return True
else:
return isinstance(event, event_type)
return False
return Rule(_rule)