From a56d1f2bd8ef70b6384d74303b6156ab0908939f Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Mon, 2 Sep 2024 11:43:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=B6=85?= =?UTF-8?q?=E7=BA=A7=E7=94=A8=E6=88=B7=E5=AF=B9=E7=BE=A4=E7=BB=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/plugin_switch/__init__.py | 8 ++-- .../admin/plugin_switch/_data_source.py | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/zhenxun/builtin_plugins/admin/plugin_switch/__init__.py b/zhenxun/builtin_plugins/admin/plugin_switch/__init__.py index 0dfb68af4..a73b89108 100644 --- a/zhenxun/builtin_plugins/admin/plugin_switch/__init__.py +++ b/zhenxun/builtin_plugins/admin/plugin_switch/__init__.py @@ -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, ) @@ -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( @@ -145,7 +145,7 @@ async def _( True, default_status.result, gid ) logger.info( - f"开启群组中全部功能", + "开启群组中全部功能", arparma.header_result, session=session, ) @@ -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, diff --git a/zhenxun/builtin_plugins/admin/plugin_switch/_data_source.py b/zhenxun/builtin_plugins/admin/plugin_switch/_data_source.py index b10a929e3..0eaaf6e5f 100644 --- a/zhenxun/builtin_plugins/admin/plugin_switch/_data_source.py +++ b/zhenxun/builtin_plugins/admin/plugin_switch/_data_source.py @@ -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 "没有找到这个功能喔..."