将PFC的麦麦发言存至数据库,删掉手动添加消息部分
This commit is contained in:
@@ -443,36 +443,6 @@ class Conversation:
|
|||||||
await self.direct_sender.send_message(chat_stream=self.chat_stream, content=reply_content)
|
await self.direct_sender.send_message(chat_stream=self.chat_stream, content=reply_content)
|
||||||
logger.info(f"消息已发送: {reply_content}") # 可以在发送后加个日志确认
|
logger.info(f"消息已发送: {reply_content}") # 可以在发送后加个日志确认
|
||||||
|
|
||||||
# --- 添加的立即更新状态逻辑开始 ---
|
|
||||||
try:
|
|
||||||
# 内层 try: 专门捕获手动更新状态时可能出现的错误
|
|
||||||
# 创建一个代表刚刚发送的消息的字典
|
|
||||||
bot_message_info = {
|
|
||||||
"message_id": f"bot_sent_{current_time}", # 创建一个简单的唯一ID
|
|
||||||
"time": current_time,
|
|
||||||
"user_info": UserInfo( # 使用 UserInfo 类构建用户信息
|
|
||||||
user_id=str(global_config.BOT_QQ),
|
|
||||||
user_nickname=global_config.BOT_NICKNAME,
|
|
||||||
platform=self.chat_stream.platform, # 从 chat_stream 获取平台信息
|
|
||||||
).to_dict(), # 转换为字典格式存储
|
|
||||||
"processed_plain_text": reply_content, # 使用发送的内容
|
|
||||||
"detailed_plain_text": f"{int(current_time)},{global_config.BOT_NICKNAME}:{reply_content}", # 构造一个简单的详细文本, 时间戳取整
|
|
||||||
# 可以根据需要添加其他字段,保持与 observation_info.chat_history 中其他消息结构一致
|
|
||||||
}
|
|
||||||
|
|
||||||
# 直接更新 ObservationInfo 实例
|
|
||||||
if self.observation_info:
|
|
||||||
self.observation_info.chat_history.append(bot_message_info) # 将消息添加到历史记录末尾
|
|
||||||
self.observation_info.last_bot_speak_time = current_time # 更新 Bot 最后发言时间
|
|
||||||
self.observation_info.last_message_time = current_time # 更新最后消息时间
|
|
||||||
logger.debug("已手动将Bot发送的消息添加到 ObservationInfo")
|
|
||||||
else:
|
|
||||||
logger.warning("无法手动更新 ObservationInfo:实例不存在")
|
|
||||||
|
|
||||||
except Exception as update_err:
|
|
||||||
logger.error(f"手动更新 ObservationInfo 时出错: {update_err}")
|
|
||||||
# --- 添加的立即更新状态逻辑结束 ---
|
|
||||||
|
|
||||||
# 原有的触发更新和等待代码
|
# 原有的触发更新和等待代码
|
||||||
self.chat_observer.trigger_update()
|
self.chat_observer.trigger_update()
|
||||||
if not await self.chat_observer.wait_for_update():
|
if not await self.chat_observer.wait_for_update():
|
||||||
|
|||||||
@@ -376,6 +376,7 @@ class DirectMessageSender:
|
|||||||
# 发送消息
|
# 发送消息
|
||||||
try:
|
try:
|
||||||
await self.send_via_ws(message)
|
await self.send_via_ws(message)
|
||||||
|
await self.storage.store_message(message, chat_stream)
|
||||||
logger.success(f"PFC消息已发送: {content}")
|
logger.success(f"PFC消息已发送: {content}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"PFC消息发送失败: {str(e)}")
|
logger.error(f"PFC消息发送失败: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user