去除线程逻辑
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user