fix:PFC消息发送失败
This commit is contained in:
@@ -100,15 +100,15 @@ class NotificationManager:
|
|||||||
"""
|
"""
|
||||||
print(1145145511114445551111444)
|
print(1145145511114445551111444)
|
||||||
if target not in self._handlers:
|
if target not in self._handlers:
|
||||||
print("没11有target")
|
# print("没11有target")
|
||||||
self._handlers[target] = {}
|
self._handlers[target] = {}
|
||||||
if notification_type not in self._handlers[target]:
|
if notification_type not in self._handlers[target]:
|
||||||
print("没11有notification_type")
|
# print("没11有notification_type")
|
||||||
self._handlers[target][notification_type] = []
|
self._handlers[target][notification_type] = []
|
||||||
print(self._handlers[target][notification_type])
|
# print(self._handlers[target][notification_type])
|
||||||
print(f"注册1111111111111111111111处理器: {target} {notification_type} {handler}")
|
# print(f"注册1111111111111111111111处理器: {target} {notification_type} {handler}")
|
||||||
self._handlers[target][notification_type].append(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):
|
def unregister_handler(self, target: str, notification_type: NotificationType, handler: NotificationHandler):
|
||||||
"""注销通知处理器
|
"""注销通知处理器
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ from src.common.logger import get_module_logger
|
|||||||
from ..chat.chat_stream import ChatStream
|
from ..chat.chat_stream import ChatStream
|
||||||
from ..chat.message import Message
|
from ..chat.message import Message
|
||||||
from ..message.message_base import Seg
|
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")
|
logger = get_module_logger("message_sender")
|
||||||
|
|
||||||
@@ -39,9 +40,11 @@ class DirectMessageSender:
|
|||||||
message_sending = MessageSending(segments=segments)
|
message_sending = MessageSending(segments=segments)
|
||||||
|
|
||||||
# 发送消息
|
# 发送消息
|
||||||
await chat_stream.send_message(message_sending)
|
message_set = MessageSet(chat_stream, message_sending.message_id)
|
||||||
logger.info(f"消息已发送: {content}")
|
message_set.add_message(message_sending)
|
||||||
|
message_manager.add_message(message_set)
|
||||||
|
logger.info(f"PFC消息已发送: {content}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"发送消息失败: {str(e)}")
|
logger.error(f"PFC消息发送失败: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -299,6 +299,12 @@ class DirectMessageSender:
|
|||||||
self.logger = get_module_logger("direct_sender")
|
self.logger = get_module_logger("direct_sender")
|
||||||
self.storage = MessageStorage()
|
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(
|
async def send_message(
|
||||||
self,
|
self,
|
||||||
chat_stream: ChatStream,
|
chat_stream: ChatStream,
|
||||||
@@ -335,21 +341,22 @@ class DirectMessageSender:
|
|||||||
# 处理消息
|
# 处理消息
|
||||||
await message.process()
|
await message.process()
|
||||||
|
|
||||||
|
message_json = message.to_dict()
|
||||||
|
|
||||||
# 发送消息
|
# 发送消息
|
||||||
try:
|
try:
|
||||||
message_json = message.to_dict()
|
end_point = global_config.api_urls.get(message.message_info.platform, None)
|
||||||
end_point = global_config.api_urls.get(chat_stream.platform, None)
|
if end_point:
|
||||||
|
# logger.info(f"发送消息到{end_point}")
|
||||||
if not end_point:
|
# logger.info(message_json)
|
||||||
raise ValueError(f"未找到平台:{chat_stream.platform} 的url配置")
|
try:
|
||||||
|
await global_api.send_message_REST(end_point, message_json)
|
||||||
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.storage.store_message(message, message.chat_stream)
|
await self.send_via_ws(message)
|
||||||
|
else:
|
||||||
self.logger.info(f"直接发送消息成功: {content[:30]}...")
|
await self.send_via_ws(message)
|
||||||
|
logger.success(f"PFC消息已发送: {content}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"直接发送消息失败: {str(e)}")
|
logger.error(f"PFC消息发送失败: {str(e)}")
|
||||||
raise
|
|
||||||
|
|||||||
@@ -65,10 +65,6 @@ class ChatBot:
|
|||||||
- 没有思维流相关的状态管理
|
- 没有思维流相关的状态管理
|
||||||
- 更简单直接的回复逻辑
|
- 更简单直接的回复逻辑
|
||||||
|
|
||||||
3. pfc_chatting模式:仅进行消息处理
|
|
||||||
- 不进行任何回复
|
|
||||||
- 只处理和存储消息
|
|
||||||
|
|
||||||
所有模式都包含:
|
所有模式都包含:
|
||||||
- 消息过滤
|
- 消息过滤
|
||||||
- 记忆激活
|
- 记忆激活
|
||||||
|
|||||||
Reference in New Issue
Block a user