mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
⚡️ 减少插件限制查询次数
This commit is contained in:
parent
ae5df38c21
commit
6c189e81dc
@ -84,6 +84,12 @@ class LimitManage:
|
|||||||
key_type = user_id
|
key_type = user_id
|
||||||
if group_id and limit.watch_type == LimitWatchType.GROUP:
|
if group_id and limit.watch_type == LimitWatchType.GROUP:
|
||||||
key_type = channel_id or group_id
|
key_type = channel_id or group_id
|
||||||
|
logger.debug(
|
||||||
|
f"解除对象: {key_type} 的block限制",
|
||||||
|
"AuthChecker",
|
||||||
|
session=user_id,
|
||||||
|
group_id=group_id,
|
||||||
|
)
|
||||||
limiter.set_false(key_type)
|
limiter.set_false(key_type)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -152,11 +158,17 @@ class LimitManage:
|
|||||||
await MessageUtils.build_message(limit.result).send()
|
await MessageUtils.build_message(limit.result).send()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{limit.module}({limit.limit_type}) 正在限制中...",
|
f"{limit.module}({limit.limit_type}) 正在限制中...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException(f"{limit.module} 正在限制中...")
|
raise IgnoredException(f"{limit.module} 正在限制中...")
|
||||||
else:
|
else:
|
||||||
|
logger.debug(
|
||||||
|
f"开始进行限制 {limit.module}({limit.limit_type})...",
|
||||||
|
"AuthChecker",
|
||||||
|
session=user_id,
|
||||||
|
group_id=group_id,
|
||||||
|
)
|
||||||
if isinstance(limiter, FreqLimiter):
|
if isinstance(limiter, FreqLimiter):
|
||||||
limiter.start_cd(key_type)
|
limiter.start_cd(key_type)
|
||||||
if isinstance(limiter, UserBlockLimiter):
|
if isinstance(limiter, UserBlockLimiter):
|
||||||
@ -230,7 +242,10 @@ class AuthChecker:
|
|||||||
user = await UserConsole.get_user(user_id, session.platform)
|
user = await UserConsole.get_user(user_id, session.platform)
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"重复创建用户,已跳过全选该次权限...", "HOOK", session=session, e=e
|
"重复创建用户,已跳过该次权限...",
|
||||||
|
"AuthChecker",
|
||||||
|
session=session,
|
||||||
|
e=e,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if plugin := await PluginInfo.get_or_none(module_path=module_path):
|
if plugin := await PluginInfo.get_or_none(module_path=module_path):
|
||||||
@ -255,7 +270,7 @@ class AuthChecker:
|
|||||||
await self.auth_limit(plugin, session)
|
await self.auth_limit(plugin, session)
|
||||||
except IsSuperuserException:
|
except IsSuperuserException:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"超级用户或被ban跳过权限检测...", "HOOK", session=session
|
"超级用户或被ban跳过权限检测...", "AuthChecker", session=session
|
||||||
)
|
)
|
||||||
except IgnoredException:
|
except IgnoredException:
|
||||||
is_ignore = True
|
is_ignore = True
|
||||||
@ -279,7 +294,9 @@ class AuthChecker:
|
|||||||
if u := await UserConsole.get_user(user_id):
|
if u := await UserConsole.get_user(user_id):
|
||||||
u.gold = 0
|
u.gold = 0
|
||||||
await u.save(update_fields=["gold"])
|
await u.save(update_fields=["gold"])
|
||||||
logger.debug(f"调用功能花费金币: {cost_gold}", "HOOK", session=session)
|
logger.debug(
|
||||||
|
f"调用功能花费金币: {cost_gold}", "AuthChecker", session=session
|
||||||
|
)
|
||||||
if is_ignore:
|
if is_ignore:
|
||||||
raise IgnoredException("权限检测 ignore")
|
raise IgnoredException("权限检测 ignore")
|
||||||
|
|
||||||
@ -306,6 +323,7 @@ class AuthChecker:
|
|||||||
if not group_id:
|
if not group_id:
|
||||||
group_id = channel_id
|
group_id = channel_id
|
||||||
channel_id = None
|
channel_id = None
|
||||||
|
if plugin.module not in LimitManage.add_module:
|
||||||
limit_list: list[PluginLimit] = await plugin.plugin_limit.filter(
|
limit_list: list[PluginLimit] = await plugin.plugin_limit.filter(
|
||||||
status=True
|
status=True
|
||||||
).all() # type: ignore
|
).all() # type: ignore
|
||||||
@ -345,7 +363,7 @@ class AuthChecker:
|
|||||||
).send(reply_to=True)
|
).send(reply_to=True)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 超级管理员禁用了该群此功能...",
|
f"{plugin.name}({plugin.module}) 超级管理员禁用了该群此功能...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("超级管理员禁用了该群此功能...")
|
raise IgnoredException("超级管理员禁用了该群此功能...")
|
||||||
@ -358,7 +376,7 @@ class AuthChecker:
|
|||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 未开启此功能...",
|
f"{plugin.name}({plugin.module}) 未开启此功能...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("该群未开启此功能...")
|
raise IgnoredException("该群未开启此功能...")
|
||||||
@ -372,11 +390,14 @@ class AuthChecker:
|
|||||||
).send(reply_to=True)
|
).send(reply_to=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
"auth_plugin 发送消息失败", "HOOK", session=session, e=e
|
"auth_plugin 发送消息失败",
|
||||||
|
"AuthChecker",
|
||||||
|
session=session,
|
||||||
|
e=e,
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 该插件在群组中已被禁用...",
|
f"{plugin.name}({plugin.module}) 该插件在群组中已被禁用...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("该插件在群组中已被禁用...")
|
raise IgnoredException("该插件在群组中已被禁用...")
|
||||||
@ -392,11 +413,14 @@ class AuthChecker:
|
|||||||
).send()
|
).send()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
"auth_admin 发送消息失败", "HOOK", session=session, e=e
|
"auth_admin 发送消息失败",
|
||||||
|
"AuthChecker",
|
||||||
|
session=session,
|
||||||
|
e=e,
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 该插件在私聊中已被禁用...",
|
f"{plugin.name}({plugin.module}) 该插件在私聊中已被禁用...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("该插件在私聊中已被禁用...")
|
raise IgnoredException("该插件在私聊中已被禁用...")
|
||||||
@ -406,7 +430,7 @@ class AuthChecker:
|
|||||||
raise IsSuperuserException()
|
raise IsSuperuserException()
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 全局未开启此功能...",
|
f"{plugin.name}({plugin.module}) 全局未开启此功能...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
if self.is_send_limit_message(plugin, sid) and not is_poke:
|
||||||
@ -439,11 +463,14 @@ class AuthChecker:
|
|||||||
).send(reply_to=True)
|
).send(reply_to=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
"auth_admin 发送消息失败", "HOOK", session=session, e=e
|
"auth_admin 发送消息失败",
|
||||||
|
"AuthChecker",
|
||||||
|
session=session,
|
||||||
|
e=e,
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("管理员权限不足...")
|
raise IgnoredException("管理员权限不足...")
|
||||||
@ -454,11 +481,11 @@ class AuthChecker:
|
|||||||
).send()
|
).send()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
"auth_admin 发送消息失败", "HOOK", session=session, e=e
|
"auth_admin 发送消息失败", "AuthChecker", session=session, e=e
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
f"{plugin.name}({plugin.module}) 管理员权限不足...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("权限不足")
|
raise IgnoredException("权限不足")
|
||||||
@ -484,21 +511,21 @@ class AuthChecker:
|
|||||||
"""群权限小于0"""
|
"""群权限小于0"""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"群黑名单, 群权限-1...",
|
"群黑名单, 群权限-1...",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException("群黑名单")
|
raise IgnoredException("群黑名单")
|
||||||
if not group.status:
|
if not group.status:
|
||||||
"""群休眠"""
|
"""群休眠"""
|
||||||
if text.strip() != "醒来":
|
if text.strip() != "醒来":
|
||||||
logger.debug("群休眠状态...", "HOOK", session=session)
|
logger.debug("群休眠状态...", "AuthChecker", session=session)
|
||||||
raise IgnoredException("群休眠状态")
|
raise IgnoredException("群休眠状态")
|
||||||
if plugin.level > group.level:
|
if plugin.level > group.level:
|
||||||
"""插件等级大于群等级"""
|
"""插件等级大于群等级"""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 群等级限制.."
|
f"{plugin.name}({plugin.module}) 群等级限制.."
|
||||||
f"该功能需要的群等级: {plugin.level}..",
|
f"该功能需要的群等级: {plugin.level}..",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException(f"{plugin.name}({plugin.module}) 群等级限制...")
|
raise IgnoredException(f"{plugin.name}({plugin.module}) 群等级限制...")
|
||||||
@ -523,11 +550,13 @@ class AuthChecker:
|
|||||||
f"金币不足..该功能需要{plugin.cost_gold}金币.."
|
f"金币不足..该功能需要{plugin.cost_gold}金币.."
|
||||||
).send()
|
).send()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("auth_cost 发送消息失败", "HOOK", session=session, e=e)
|
logger.error(
|
||||||
|
"auth_cost 发送消息失败", "AuthChecker", session=session, e=e
|
||||||
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"{plugin.name}({plugin.module}) 金币限制.."
|
f"{plugin.name}({plugin.module}) 金币限制.."
|
||||||
f"该功能需要{plugin.cost_gold}金币..",
|
f"该功能需要{plugin.cost_gold}金币..",
|
||||||
"HOOK",
|
"AuthChecker",
|
||||||
session=session,
|
session=session,
|
||||||
)
|
)
|
||||||
raise IgnoredException(f"{plugin.name}({plugin.module}) 金币限制...")
|
raise IgnoredException(f"{plugin.name}({plugin.module}) 金币限制...")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user