fix:PFC消息发送失败

This commit is contained in:
SengokuCola
2025-04-13 22:34:19 +08:00
parent 2a74989204
commit 7df9d8da6b
4 changed files with 35 additions and 29 deletions

View File

@@ -100,15 +100,15 @@ class NotificationManager:
"""
print(1145145511114445551111444)
if target not in self._handlers:
print("没11有target")
# print("没11有target")
self._handlers[target] = {}
if notification_type not in self._handlers[target]:
print("没11有notification_type")
# print("没11有notification_type")
self._handlers[target][notification_type] = []
print(self._handlers[target][notification_type])
print(f"注册1111111111111111111111处理器: {target} {notification_type} {handler}")
# print(self._handlers[target][notification_type])
# print(f"注册1111111111111111111111处理器: {target} {notification_type} {handler}")
self._handlers[target][notification_type].append(handler)
print(self._handlers[target][notification_type])
# print(self._handlers[target][notification_type])
def unregister_handler(self, target: str, notification_type: NotificationType, handler: NotificationHandler):
"""注销通知处理器

View File

@@ -3,7 +3,8 @@ from src.common.logger import get_module_logger
from ..chat.chat_stream import ChatStream
from ..chat.message import Message
from ..message.message_base import Seg
from src.plugins.chat.message import MessageSending
from src.plugins.chat.message import MessageSending, MessageSet
from src.plugins.chat.message_sender import message_manager
logger = get_module_logger("message_sender")
@@ -39,9 +40,11 @@ class DirectMessageSender:
message_sending = MessageSending(segments=segments)
# 发送消息
await chat_stream.send_message(message_sending)
logger.info(f"消息已发送: {content}")
message_set = MessageSet(chat_stream, message_sending.message_id)
message_set.add_message(message_sending)
message_manager.add_message(message_set)
logger.info(f"PFC消息已发送: {content}")
except Exception as e:
logger.error(f"发送消息失败: {str(e)}")
logger.error(f"PFC消息发送失败: {str(e)}")
raise

View File

@@ -299,6 +299,12 @@ class DirectMessageSender:
self.logger = get_module_logger("direct_sender")
self.storage = MessageStorage()
async def send_via_ws(self, message: MessageSending) -> None:
try:
await global_api.send_message(message)
except Exception as e:
raise ValueError(f"未找到平台:{message.message_info.platform} 的url配置请检查配置文件") from e
async def send_message(
self,
chat_stream: ChatStream,
@@ -335,21 +341,22 @@ class DirectMessageSender:
# 处理消息
await message.process()
message_json = message.to_dict()
# 发送消息
try:
message_json = message.to_dict()
end_point = global_config.api_urls.get(chat_stream.platform, None)
if not end_point:
raise ValueError(f"未找到平台:{chat_stream.platform} 的url配置")
await global_api.send_message_REST(end_point, message_json)
# 存储消息
await self.storage.store_message(message, message.chat_stream)
self.logger.info(f"直接发送消息成功: {content[:30]}...")
end_point = global_config.api_urls.get(message.message_info.platform, None)
if end_point:
# logger.info(f"发送消息到{end_point}")
# logger.info(message_json)
try:
await global_api.send_message_REST(end_point, message_json)
except Exception as e:
logger.error(f"REST方式发送失败出现错误: {str(e)}")
logger.info("尝试使用ws发送")
await self.send_via_ws(message)
else:
await self.send_via_ws(message)
logger.success(f"PFC消息已发送: {content}")
except Exception as e:
self.logger.error(f"直接发送消息失败: {str(e)}")
raise
logger.error(f"PFC消息发送失败: {str(e)}")

View File

@@ -65,10 +65,6 @@ class ChatBot:
- 没有思维流相关的状态管理
- 更简单直接的回复逻辑
3. pfc_chatting模式仅进行消息处理
- 不进行任何回复
- 只处理和存储消息
所有模式都包含:
- 消息过滤
- 记忆激活