修复群管理员权限检测会阻挡超级用户权限

This commit is contained in:
HibiKier 2022-12-24 18:57:56 +08:00
parent 83dc29a562
commit 3acd7d7d41
2 changed files with 17 additions and 12 deletions

View File

@ -296,6 +296,10 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
## 更新 ## 更新
## 2022/12/24
* 修复群管理员权限检测会阻挡超级用户权限
### 2022/12/23 ### 2022/12/23
* 优化`管理员帮助``超级用户帮助`图片 * 优化`管理员帮助``超级用户帮助`图片

View File

@ -116,7 +116,7 @@ async def send_msg(msg: str, bot: Bot, event: MessageEvent):
pass pass
class ReturnException(Exception): class IsSuperuserException(Exception):
pass pass
@ -144,14 +144,15 @@ class AuthChecker:
try: try:
plugin_name = matcher.plugin_name plugin_name = matcher.plugin_name
cost_gold = await self.auth_cost(plugin_name, bot, event) cost_gold = await self.auth_cost(plugin_name, bot, event)
await self.auth_basic(plugin_name, bot, event) if str(event.user_id) not in bot.config.superusers:
self.auth_group(plugin_name, bot, event) await self.auth_basic(plugin_name, bot, event)
await self.auth_admin(plugin_name, matcher, bot, event) self.auth_group(plugin_name, bot, event)
await self.auth_plugin(plugin_name, matcher, bot, event) await self.auth_admin(plugin_name, matcher, bot, event)
await self.auth_limit(plugin_name, bot, event) await self.auth_plugin(plugin_name, matcher, bot, event)
if cost_gold and str(event.user_id) not in bot.config.superusers: await self.auth_limit(plugin_name, bot, event)
await BagUser.spend_gold(event.user_id, event.group_id, cost_gold) if cost_gold:
except ReturnException: await BagUser.spend_gold(event.user_id, event.group_id, cost_gold)
except IsSuperuserException:
return return
async def auth_limit(self, plugin_name: str, bot: Bot, event: Event): async def auth_limit(self, plugin_name: str, bot: Bot, event: Event):
@ -336,7 +337,7 @@ class AuthChecker:
if isinstance( if isinstance(
event, GroupMessageEvent event, GroupMessageEvent
) and group_manager.check_group_is_white(event.group_id): ) and group_manager.check_group_is_white(event.group_id):
raise ReturnException() raise IsSuperuserException()
try: try:
if isinstance(event, GroupMessageEvent): if isinstance(event, GroupMessageEvent):
if ( if (
@ -463,7 +464,7 @@ class AuthChecker:
plugin_name plugin_name
).limit_superuser ).limit_superuser
): ):
raise ReturnException() raise IsSuperuserException()
_plugin = nonebot.plugin.get_plugin(plugin_name) _plugin = nonebot.plugin.get_plugin(plugin_name)
_module = _plugin.module _module = _plugin.module
_plugin_name = _module.__getattribute__("__zx_plugin_name__") _plugin_name = _module.__getattribute__("__zx_plugin_name__")
@ -471,7 +472,7 @@ class AuthChecker:
"[superuser]" in _plugin_name.lower() "[superuser]" in _plugin_name.lower()
and str(event.user_id) in bot.config.superusers and str(event.user_id) in bot.config.superusers
): ):
raise ReturnException() raise IsSuperuserException()
except AttributeError: except AttributeError:
pass pass