总结优化

This commit is contained in:
liuwei
2025-06-20 11:14:07 +08:00
parent e388deb4ea
commit e4ed1c9aef

View File

@@ -137,10 +137,12 @@ class MessageSummaryPlugin(MessagePluginInterface):
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id, "⏳群消息总结中… 😊")
self.revoke.add_message_to_revoke(group_id, client_msg_id, create_time, new_msg_id, 5)
# 创建线程异步处理总结生成和发送
await self._async_generate_and_send_summary(chat_content, group_name, group_id,
message)
return True, "异步总结已启动"
res = await self._async_generate_and_send_summary(chat_content, group_name, group_id,
message)
if res:
return True, "异步总结已启动"
else:
return False, "总结失败"
except Exception as e:
self.LOG.error(f"处理消息总结命令失败: {e}")
@@ -155,16 +157,19 @@ class MessageSummaryPlugin(MessagePluginInterface):
if image_path:
await self.bot.send_image_message(group_id, Path(image_path))
return True
else:
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id,
"❌ 生成总结图片失败")
self.revoke.add_message_to_revoke(group_id, client_msg_id, create_time, new_msg_id, 5)
return False
except Exception as e:
self.LOG.error(f"异步生成总结失败: {e}")
client_msg_id, create_time, new_msg_id = await self.bot.send_text_message(group_id,
f"❌ 生成总结失败: {str(e)}")
self.revoke.add_message_to_revoke(group_id, client_msg_id, create_time, new_msg_id, 5)
return False
def _sanitize_group_name(self, group_name: str) -> str:
"""处理群名,去除特殊字符并限制长度"""
@@ -210,7 +215,7 @@ class MessageSummaryPlugin(MessagePluginInterface):
async with session.post(self._api_url, headers=headers, json=data) as response:
response.raise_for_status() # 检查请求是否成功
response_data = await response.json()
self.LOG.info(f"Dify API响应状态码: {response.status}")
self.LOG.debug(f"响应数据: {json.dumps(response_data, ensure_ascii=False, indent=2)}")
@@ -255,4 +260,3 @@ class MessageSummaryPlugin(MessagePluginInterface):
except Exception as e:
self.LOG.error(f"处理总结时出现未知错误: {e}")
return f"生成总结时出现未知错误: {str(e)}", None