From 7ff2cf49e363a294b2eb01d78da37624729df964 Mon Sep 17 00:00:00 2001 From: liuwei Date: Fri, 16 May 2025 10:34:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E7=BA=BF=E7=A8=8B=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/message_summary/main.py | 44 +++------------------------------ robot.py | 2 +- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/plugins/message_summary/main.py b/plugins/message_summary/main.py index 4f87b8e..0589ede 100644 --- a/plugins/message_summary/main.py +++ b/plugins/message_summary/main.py @@ -118,8 +118,8 @@ class MessageSummaryPlugin(MessagePluginInterface): await self.bot.send_text_message(group_id, "⏳群消息总结中… 😊") # 创建线程异步处理总结生成和发送 - self._run_async_in_thread(self._async_generate_and_send_summary, chat_content, group_name, group_id, - message) + await self._async_generate_and_send_summary(chat_content, group_name, group_id, + message) return True, "异步总结已启动" @@ -127,15 +127,6 @@ class MessageSummaryPlugin(MessagePluginInterface): self.LOG.error(f"处理消息总结命令失败: {e}") return False, None - def _run_async_in_thread(self, coro, *args, **kwargs): - def runner(): - asyncio.run(coro(*args, **kwargs)) - - t = threading.Thread(target=runner) - t.daemon = True - t.start() - return t - async def _async_generate_and_send_summary(self, chat_content: str, group_name: str, group_id: str, message: Dict[str, Any]): """异步生成并发送总结""" @@ -222,20 +213,12 @@ class MessageSummaryPlugin(MessagePluginInterface): timestamp = int(time.time()) output_filename = f"summary_{timestamp}.png" output_dir = Path(os.path.dirname(os.path.abspath(__file__)), "outputs") - # 确保输出目录存在 os.makedirs(output_dir, exist_ok=True) - # 构建完整的输出路径 output_path = os.path.join(output_dir, output_filename) - - # 检查磁盘空间 - if self._check_disk_space(output_dir): - spath = await convert_md_str_to_image(answer, output_path) - self.LOG.info(f"成功生成图片: {spath}") - else: - self.LOG.error("磁盘空间不足,无法生成图片") - spath = None + spath = await convert_md_str_to_image(answer, output_path) + self.LOG.info(f"成功生成图片: {spath}") except Exception as e: self.LOG.error(f"生成image失败:{e}", exc_info=True) spath = None @@ -253,22 +236,3 @@ class MessageSummaryPlugin(MessagePluginInterface): except Exception as e: self.LOG.error(f"处理总结时出现未知错误: {e}") return f"生成总结时出现未知错误: {str(e)}", None - - def _check_disk_space(self, path, min_space_mb=100): - """ - 检查指定路径的可用磁盘空间 - :param path: 要检查的路径 - :param min_space_mb: 最小所需空间(MB) - :return: 如果有足够空间则返回True,否则返回False - """ - try: - import shutil - # 获取路径所在磁盘的可用空间(字节) - free_space = shutil.disk_usage(path).free - # 转换为MB - free_space_mb = free_space / (1024 * 1024) - return free_space_mb >= min_space_mb - except Exception as e: - self.LOG.error(f"检查磁盘空间时出错: {e}") - # 出错时假设空间足够 - return True diff --git a/robot.py b/robot.py index d94c5ff..b60aa9a 100644 --- a/robot.py +++ b/robot.py @@ -220,7 +220,7 @@ class Robot(Job): self.LOG.error(f"获取新消息失败 {e}") if e == "用户可能退出": self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!") - # self.ipad_running = False + self.ipad_running = False await asyncio.sleep(5) continue