Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,12 @@ async def _send_media_segment(
file_name,
)
except Exception as e:
logger.error("weixin_oc(%s): prepare media failed: %s", self.meta().id, e)
logger.error(
"weixin_oc(%s): prepare media failed: %s",
self.meta().id,
e,
exc_info=True,
)
return False

if text:
Expand Down Expand Up @@ -1608,18 +1613,21 @@ async def send_by_session(
target_user = session.session_id
pending_text = ""
has_supported_segment = False
failed_segments = 0
for segment in message_chain.chain:
if isinstance(segment, Plain):
pending_text += segment.text
continue

if isinstance(segment, (Image, Video, File)):
has_supported_segment = True
await self._send_media_segment(
sent = await self._send_media_segment(
target_user,
segment,
text=pending_text.strip() or None,
)
if not sent:
failed_segments += 1
pending_text = ""
continue

Expand All @@ -1631,13 +1639,20 @@ async def send_by_session(

if pending_text:
has_supported_segment = True
await self._send_to_session(target_user, pending_text.strip())
sent = await self._send_to_session(target_user, pending_text.strip())
if not sent:
failed_segments += 1

if not has_supported_segment:
logger.warning(
"weixin_oc(%s): outbound message ignored, no supported segments",
self.meta().id,
)
if failed_segments:
raise RuntimeError(
f"weixin_oc({self.meta().id}, target_user={target_user}) "
f"failed to send {failed_segments} message segment(s)"
)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
await super().send_by_session(session, message_chain)

def meta(self) -> PlatformMetadata:
Expand Down
Loading