fix: 重命名变量以避免与内置函数冲突
1. 将 Message 类中的 time 参数重命名为 timestamp,避免与 Python 内置模块 time 冲突 2. 在消息处理相关函数中统一使用 timestamp 变量名称 3. 优化 message_storage 查询条件构建方式 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -124,7 +124,7 @@ class Conversation:
|
|||||||
return Message(
|
return Message(
|
||||||
message_id=msg_dict["message_id"],
|
message_id=msg_dict["message_id"],
|
||||||
chat_stream=chat_stream,
|
chat_stream=chat_stream,
|
||||||
time=msg_dict["time"],
|
timestamp=msg_dict["time"],
|
||||||
user_info=user_info,
|
user_info=user_info,
|
||||||
processed_plain_text=msg_dict.get("processed_plain_text", ""),
|
processed_plain_text=msg_dict.get("processed_plain_text", ""),
|
||||||
detailed_plain_text=msg_dict.get("detailed_plain_text", ""),
|
detailed_plain_text=msg_dict.get("detailed_plain_text", ""),
|
||||||
|
|||||||
@@ -51,11 +51,9 @@ class MongoDBMessageStorage(MessageStorage):
|
|||||||
"""MongoDB消息存储实现"""
|
"""MongoDB消息存储实现"""
|
||||||
|
|
||||||
async def get_messages_after(self, chat_id: str, message_time: float) -> List[Dict[str, Any]]:
|
async def get_messages_after(self, chat_id: str, message_time: float) -> List[Dict[str, Any]]:
|
||||||
query = {"chat_id": chat_id}
|
query = {"chat_id": chat_id, "time": {"$gt": message_time}}
|
||||||
# print(f"storage_check_message: {message_time}")
|
# print(f"storage_check_message: {message_time}")
|
||||||
|
|
||||||
query["time"] = {"$gt": message_time}
|
|
||||||
|
|
||||||
return list(db.messages.find(query).sort("time", 1))
|
return list(db.messages.find(query).sort("time", 1))
|
||||||
|
|
||||||
async def get_messages_before(self, chat_id: str, time_point: float, limit: int = 5) -> List[Dict[str, Any]]:
|
async def get_messages_before(self, chat_id: str, time_point: float, limit: int = 5) -> List[Dict[str, Any]]:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class Message(MessageBase):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
message_id: str,
|
message_id: str,
|
||||||
time: float,
|
timestamp: float,
|
||||||
chat_stream: ChatStream,
|
chat_stream: ChatStream,
|
||||||
user_info: UserInfo,
|
user_info: UserInfo,
|
||||||
message_segment: Optional[Seg] = None,
|
message_segment: Optional[Seg] = None,
|
||||||
@@ -43,7 +43,7 @@ class Message(MessageBase):
|
|||||||
message_info = BaseMessageInfo(
|
message_info = BaseMessageInfo(
|
||||||
platform=chat_stream.platform,
|
platform=chat_stream.platform,
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
time=time,
|
time=timestamp,
|
||||||
group_info=chat_stream.group_info,
|
group_info=chat_stream.group_info,
|
||||||
user_info=user_info,
|
user_info=user_info,
|
||||||
)
|
)
|
||||||
@@ -143,7 +143,7 @@ class MessageRecv(Message):
|
|||||||
def _generate_detailed_text(self) -> str:
|
def _generate_detailed_text(self) -> str:
|
||||||
"""生成详细文本,包含时间和用户信息"""
|
"""生成详细文本,包含时间和用户信息"""
|
||||||
# time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.message_info.time))
|
# time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.message_info.time))
|
||||||
time = self.message_info.time
|
timestamp = self.message_info.time
|
||||||
user_info = self.message_info.user_info
|
user_info = self.message_info.user_info
|
||||||
# name = (
|
# name = (
|
||||||
# f"{user_info.user_nickname}(ta的昵称:{user_info.user_cardname},ta的id:{user_info.user_id})"
|
# f"{user_info.user_nickname}(ta的昵称:{user_info.user_cardname},ta的id:{user_info.user_id})"
|
||||||
@@ -151,7 +151,7 @@ class MessageRecv(Message):
|
|||||||
# else f"{user_info.user_nickname}(ta的id:{user_info.user_id})"
|
# else f"{user_info.user_nickname}(ta的id:{user_info.user_id})"
|
||||||
# )
|
# )
|
||||||
name = f"<{self.message_info.platform}:{user_info.user_id}:{user_info.user_nickname}:{user_info.user_cardname}>"
|
name = f"<{self.message_info.platform}:{user_info.user_id}:{user_info.user_nickname}:{user_info.user_cardname}>"
|
||||||
return f"[{time}] {name}: {self.processed_plain_text}\n"
|
return f"[{timestamp}] {name}: {self.processed_plain_text}\n"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -170,7 +170,7 @@ class MessageProcessBase(Message):
|
|||||||
# 调用父类初始化
|
# 调用父类初始化
|
||||||
super().__init__(
|
super().__init__(
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
time=round(time.time(), 3), # 保留3位小数
|
timestamp=round(time.time(), 3), # 保留3位小数
|
||||||
chat_stream=chat_stream,
|
chat_stream=chat_stream,
|
||||||
user_info=bot_user_info,
|
user_info=bot_user_info,
|
||||||
message_segment=message_segment,
|
message_segment=message_segment,
|
||||||
@@ -242,7 +242,7 @@ class MessageProcessBase(Message):
|
|||||||
def _generate_detailed_text(self) -> str:
|
def _generate_detailed_text(self) -> str:
|
||||||
"""生成详细文本,包含时间和用户信息"""
|
"""生成详细文本,包含时间和用户信息"""
|
||||||
# time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.message_info.time))
|
# time_str = time.strftime("%m-%d %H:%M:%S", time.localtime(self.message_info.time))
|
||||||
time = self.message_info.time
|
timestamp = self.message_info.time
|
||||||
user_info = self.message_info.user_info
|
user_info = self.message_info.user_info
|
||||||
# name = (
|
# name = (
|
||||||
# f"{user_info.user_nickname}(ta的昵称:{user_info.user_cardname},ta的id:{user_info.user_id})"
|
# f"{user_info.user_nickname}(ta的昵称:{user_info.user_cardname},ta的id:{user_info.user_id})"
|
||||||
@@ -250,7 +250,7 @@ class MessageProcessBase(Message):
|
|||||||
# else f"{user_info.user_nickname}(ta的id:{user_info.user_id})"
|
# else f"{user_info.user_nickname}(ta的id:{user_info.user_id})"
|
||||||
# )
|
# )
|
||||||
name = f"<{self.message_info.platform}:{user_info.user_id}:{user_info.user_nickname}:{user_info.user_cardname}>"
|
name = f"<{self.message_info.platform}:{user_info.user_id}:{user_info.user_nickname}:{user_info.user_cardname}>"
|
||||||
return f"[{time}] {name}: {self.processed_plain_text}\n"
|
return f"[{timestamp}] {name}: {self.processed_plain_text}\n"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ async def get_recent_group_messages(chat_id: str, limit: int = 12) -> list:
|
|||||||
msg = Message(
|
msg = Message(
|
||||||
message_id=msg_data["message_id"],
|
message_id=msg_data["message_id"],
|
||||||
chat_stream=chat_stream,
|
chat_stream=chat_stream,
|
||||||
time=msg_data["time"],
|
timestamp=msg_data["time"],
|
||||||
user_info=user_info,
|
user_info=user_info,
|
||||||
processed_plain_text=msg_data.get("processed_text", ""),
|
processed_plain_text=msg_data.get("processed_text", ""),
|
||||||
detailed_plain_text=msg_data.get("detailed_plain_text", ""),
|
detailed_plain_text=msg_data.get("detailed_plain_text", ""),
|
||||||
|
|||||||
Reference in New Issue
Block a user