去除线程逻辑
This commit is contained in:
@@ -118,8 +118,8 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
|||||||
await self.bot.send_text_message(group_id, "⏳群消息总结中… 😊")
|
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,
|
await self._async_generate_and_send_summary(chat_content, group_name, group_id,
|
||||||
message)
|
message)
|
||||||
|
|
||||||
return True, "异步总结已启动"
|
return True, "异步总结已启动"
|
||||||
|
|
||||||
@@ -127,15 +127,6 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
|||||||
self.LOG.error(f"处理消息总结命令失败: {e}")
|
self.LOG.error(f"处理消息总结命令失败: {e}")
|
||||||
return False, None
|
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,
|
async def _async_generate_and_send_summary(self, chat_content: str, group_name: str, group_id: str,
|
||||||
message: Dict[str, Any]):
|
message: Dict[str, Any]):
|
||||||
"""异步生成并发送总结"""
|
"""异步生成并发送总结"""
|
||||||
@@ -222,20 +213,12 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
|||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
output_filename = f"summary_{timestamp}.png"
|
output_filename = f"summary_{timestamp}.png"
|
||||||
output_dir = Path(os.path.dirname(os.path.abspath(__file__)), "outputs")
|
output_dir = Path(os.path.dirname(os.path.abspath(__file__)), "outputs")
|
||||||
|
|
||||||
# 确保输出目录存在
|
# 确保输出目录存在
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
# 构建完整的输出路径
|
# 构建完整的输出路径
|
||||||
output_path = os.path.join(output_dir, output_filename)
|
output_path = os.path.join(output_dir, output_filename)
|
||||||
|
spath = await convert_md_str_to_image(answer, output_path)
|
||||||
# 检查磁盘空间
|
self.LOG.info(f"成功生成图片: {spath}")
|
||||||
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
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"生成image失败:{e}", exc_info=True)
|
self.LOG.error(f"生成image失败:{e}", exc_info=True)
|
||||||
spath = None
|
spath = None
|
||||||
@@ -253,22 +236,3 @@ class MessageSummaryPlugin(MessagePluginInterface):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"处理总结时出现未知错误: {e}")
|
self.LOG.error(f"处理总结时出现未知错误: {e}")
|
||||||
return f"生成总结时出现未知错误: {str(e)}", None
|
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
|
|
||||||
|
|||||||
2
robot.py
2
robot.py
@@ -220,7 +220,7 @@ class Robot(Job):
|
|||||||
self.LOG.error(f"获取新消息失败 {e}")
|
self.LOG.error(f"获取新消息失败 {e}")
|
||||||
if e == "用户可能退出":
|
if e == "用户可能退出":
|
||||||
self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!")
|
self.LOG.error(f"获取新消息失败 {e},请重启应用重新登录!")
|
||||||
# self.ipad_running = False
|
self.ipad_running = False
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user