Skip to content

Commit

Permalink
🐛 修复超级用户对群组功能开关
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Sep 2, 2024
1 parent 133d4e1 commit a56d1f2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
8 changes: 4 additions & 4 deletions zhenxun/builtin_plugins/admin/plugin_switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def _(
if session.id1 in bot.config.superusers:
image = await build_plugin()
logger.info(
f"查看功能列表",
"查看功能列表",
arparma.header_result,
session=session,
)
Expand Down Expand Up @@ -123,7 +123,7 @@ async def _(
if task.result:
if all.result:
result = await PluginManage.unblock_group_all_task(gid)
logger.info(f"开启所有群组被动", arparma.header_result, session=session)
logger.info("开启所有群组被动", arparma.header_result, session=session)
else:
result = await PluginManage.unblock_group_task(name, gid)
logger.info(
Expand All @@ -145,7 +145,7 @@ async def _(
True, default_status.result, gid
)
logger.info(
f"开启群组中全部功能",
"开启群组中全部功能",
arparma.header_result,
session=session,
)
Expand Down Expand Up @@ -206,7 +206,7 @@ async def _(
)
await MessageUtils.build_message(result).finish(reply_to=True)
else:
result = await PluginManage.superuser_block(name, None, group_id)
result = await PluginManage.superuser_unblock(name, None, group_id)
logger.info(
f"超级用户开启功能 {name}",
arparma.header_result,
Expand Down
47 changes: 47 additions & 0 deletions zhenxun/builtin_plugins/admin/plugin_switch/_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,50 @@ async def superuser_block(
if block_type == BlockType.PRIVATE:
return f"已成功将 {plugin.name} 全局私聊关闭!"
return "没有找到这个功能喔..."

@classmethod
async def superuser_unblock(
cls, plugin_name: str, block_type: BlockType | None, group_id: str | None
) -> str:
"""超级用户开启插件
参数:
plugin_name: 插件名称
block_type: 禁用类型
group_id: 群组id
返回:
str: 返回信息
"""
if plugin_name.isdigit():
plugin = await PluginInfo.get_or_none(id=int(plugin_name))
else:
plugin = await PluginInfo.get_or_none(name=plugin_name)
if plugin:
if group_id:
if group := await GroupConsole.get_or_none(
group_id=group_id, channel_id__isnull=True
):
if f"super:{plugin.module}," in group.block_plugin:
group.block_plugin = group.block_plugin.replace(
f"super:{plugin.module},", ""
)
await group.save(update_fields=["block_plugin"])
return (
f"已成功开启群组 {group.group_name}{plugin_name} 功能!"
)
return "此群组该功能已被超级用户开启,不要重复开启..."
return "群组信息未更新,请先更新群组信息..."
plugin.block_type = block_type
plugin.status = not bool(block_type)
await plugin.save(update_fields=["status", "block_type"])
if not block_type:
return f"已成功将 {plugin.name} 全局启用!"
else:
if block_type == BlockType.ALL:
return f"已成功将 {plugin.name} 全局开启!"
if block_type == BlockType.GROUP:
return f"已成功将 {plugin.name} 全局群组开启!"
if block_type == BlockType.PRIVATE:
return f"已成功将 {plugin.name} 全局私聊开启!"
return "没有找到这个功能喔..."

0 comments on commit a56d1f2

Please sign in to comment.