Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions astrbot/core/pipeline/respond/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import astrbot.core.message.components as Comp
from astrbot.core import logger
from astrbot.core.message.components import BaseMessageComponent, ComponentType
from astrbot.core.message.message_event_result import MessageChain, ResultContentType
from astrbot.core.message.message_event_result import ResultContentType
from astrbot.core.platform.astr_message_event import AstrMessageEvent
from astrbot.core.star.star_handler import EventType
from astrbot.core.utils.path_util import path_Mapping
Expand Down Expand Up @@ -278,8 +278,9 @@ async def process(
header_comps.clear()
except Exception as e:
logger.error(
"Failed to send the message chain: "
f"chain = {MessageChain([comp])}, error = {e}",
"Failed to send a message component: type=%s, error=%s",
comp.type,
e,
exc_info=True,
)
else:
Expand All @@ -304,8 +305,10 @@ async def process(
await event.send(chain)
except Exception as e:
logger.error(
f"Failed to send the message chain: chain = {chain}, "
f"error = {e}",
"Failed to send a separated message component: "
"type=%s, error=%s",
comp.type,
e,
exc_info=True,
)
chain = result.derive(result.chain)
Expand All @@ -314,8 +317,10 @@ async def process(
await event.send(chain)
except Exception as e:
logger.error(
f"Failed to send the message chain: chain = {chain}, "
f"error = {e}",
"Failed to send a message chain: component_count=%d, "
"error=%s",
len(result.chain),
e,
exc_info=True,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from typing import Any

import aiohttp
from botpy.http import BotHttp, Route
from botpy.http import Route
from botpy.types.message import Media

from astrbot.api import logger

from .qqofficial_http import QQOfficialHttp

QQOFFICIAL_CHUNKED_UPLOAD_THRESHOLD = 10 * 1024 * 1024

_MD5_10M_BYTES = 10_002_432
Expand Down Expand Up @@ -125,7 +127,7 @@ def _read_file_part(file_path: Path, offset: int, length: int) -> bytes:
class QQOfficialChunkedUploader:
"""Upload one local file with the QQ Official multipart protocol."""

def __init__(self, http: BotHttp) -> None:
def __init__(self, http: QQOfficialHttp) -> None:
"""Initialize the uploader with qq-botpy's authenticated HTTP client.

Args:
Expand Down Expand Up @@ -474,19 +476,20 @@ async def _put_part(
last_error: Exception | None = None
for attempt in range(_PART_PUT_ATTEMPTS):
try:
async with http_session.request(
"PUT",
url,
data=data,
headers={"Content-Length": str(len(data))},
timeout=aiohttp.ClientTimeout(total=_API_TIMEOUT_SECONDS),
) as response:
if 200 <= response.status < 300:
return
response_text = (await response.text(errors="replace"))[:200]
last_error = RuntimeError(
f"COS returned HTTP {response.status}: {response_text}"
)
async with self._http.request_slot():
async with http_session.request(
Comment thread
whatevertogo marked this conversation as resolved.
"PUT",
url,
data=data,
headers={"Content-Length": str(len(data))},
timeout=aiohttp.ClientTimeout(total=_API_TIMEOUT_SECONDS),
) as response:
if 200 <= response.status < 300:
return
response_text = (await response.text(errors="replace"))[:200]
last_error = RuntimeError(
f"COS returned HTTP {response.status}: {response_text}"
)
except (aiohttp.ClientError, asyncio.TimeoutError, OSError) as exc:
last_error = exc
if attempt < _PART_PUT_ATTEMPTS - 1:
Expand Down Expand Up @@ -573,13 +576,16 @@ async def _request_json(
path,
is_sandbox=self._http.is_sandbox,
)
async with http_session.request(
method,
route.url,
headers=self._http._headers,
json=dict(body),
timeout=aiohttp.ClientTimeout(total=_API_TIMEOUT_SECONDS),
) as response:
async with (
self._http.request_slot(),
http_session.request(
method,
route.url,
headers=self._http._headers,
json=dict(body),
timeout=aiohttp.ClientTimeout(total=_API_TIMEOUT_SECONDS),
) as response,
):
try:
raw: object = await response.json(content_type=None)
except ValueError:
Expand Down
Loading
Loading