fix(file): 修复机器人对自身文件上传的响应并移除硬编码路径转换
- 在群文件上传通知中,增加对`self_id`的判断,使机器人忽略自身上传文件的事件,防止不必要的响应。 - 移除 `send_api` 与 `send_handler` 中硬编码的WSL路径转换逻辑,以实现更通用的路径处理。 - 增强文件发送逻辑,使其能处理路径数据为字典的情况并检查空路径。
This commit is contained in:
@@ -56,12 +56,6 @@ async def file_to_stream(
|
||||
if not file_name:
|
||||
file_name = Path(file_path).name
|
||||
|
||||
# 临时的WSL路径转换方案
|
||||
if file_path.startswith("E:"):
|
||||
original_path = file_path
|
||||
file_path = "/mnt/e/" + file_path[3:].replace("\\", "/")
|
||||
logger.info(f"WSL路径转换: {original_path} -> {file_path}")
|
||||
|
||||
params = {
|
||||
"file": file_path,
|
||||
"name": file_name,
|
||||
|
||||
@@ -100,6 +100,7 @@ class NoticeHandler:
|
||||
# message_time: int = raw_message.get("time")
|
||||
message_time: float = time.time() # 应可乐要求,现在是float了
|
||||
|
||||
self_id = raw_message.get("self_id")
|
||||
group_id = raw_message.get("group_id")
|
||||
user_id = raw_message.get("user_id")
|
||||
target_id = raw_message.get("target_id")
|
||||
@@ -161,9 +162,12 @@ class NoticeHandler:
|
||||
logger.warning(f"不支持的group_ban类型: {notice_type}.{sub_type}")
|
||||
case NoticeType.group_upload:
|
||||
logger.info("群文件上传")
|
||||
if user_id == self_id:
|
||||
logger.info("检测到机器人自己上传文件,忽略此通知")
|
||||
return None
|
||||
if not await message_handler.check_allow_to_chat(user_id, group_id, False, False):
|
||||
return None
|
||||
handled_message, user_info = await self.handle_group_upload_notify(raw_message, group_id, user_id)
|
||||
handled_message, user_info = await self.handle_group_upload_notify(raw_message, group_id, user_id, self_id)
|
||||
case _:
|
||||
logger.warning(f"不支持的notice类型: {notice_type}")
|
||||
return None
|
||||
@@ -382,7 +386,7 @@ class NoticeHandler:
|
||||
seg_data = Seg(type="text",data=f"{user_name}使用Emoji表情{QQ_FACE.get(like_emoji_id,"")}回复了你的消息[{target_message_text}]")
|
||||
return seg_data, user_info
|
||||
|
||||
async def handle_group_upload_notify(self, raw_message: dict, group_id: int, user_id: int):
|
||||
async def handle_group_upload_notify(self, raw_message: dict, group_id: int, user_id: int, self_id: int):
|
||||
if not group_id:
|
||||
logger.error("群ID不能为空,无法处理群文件上传通知")
|
||||
return None, None
|
||||
|
||||
@@ -273,6 +273,9 @@ class SendHandler:
|
||||
new_payload = self.build_payload(payload, self.handle_videourl_message(video_url), False)
|
||||
elif seg.type == "file":
|
||||
file_path = seg.data
|
||||
file_path = seg.data
|
||||
if isinstance(file_path, dict):
|
||||
file_path = file_path.get("file", "")
|
||||
new_payload = self.build_payload(payload, self.handle_file_message(file_path), False)
|
||||
return new_payload
|
||||
|
||||
@@ -410,11 +413,9 @@ class SendHandler:
|
||||
|
||||
def handle_file_message(self, file_path: str) -> dict:
|
||||
"""处理文件消息"""
|
||||
# 临时的WSL路径转换方案
|
||||
if file_path.startswith("E:"):
|
||||
original_path = file_path
|
||||
file_path = "/mnt/e/" + file_path[3:].replace("\\", "/")
|
||||
logger.info(f"WSL路径转换: {original_path} -> {file_path}")
|
||||
if not file_path:
|
||||
logger.error("文件路径为空")
|
||||
return {}
|
||||
|
||||
return {
|
||||
"type": "file",
|
||||
|
||||
Reference in New Issue
Block a user