mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-19 16:12:30 +00:00
fix(channels): restore bound logger in discord and websocket
PR introduced module-level logger in static methods, which drops the channel context bound by BaseChannel.__init__. Revert to self._channel.logger / self.logger to preserve log labels. Also remove @staticmethod since these methods legitimately need instance access (F821 was the real issue, not the logger source).
This commit is contained in:
parent
a2f5de6838
commit
536c456e5e
@ -10,7 +10,6 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from loguru import logger
|
||||
from pydantic import Field
|
||||
|
||||
from nanobot.bus.events import OutboundMessage
|
||||
@ -309,8 +308,8 @@ if DISCORD_AVAILABLE:
|
||||
fallback = "\n".join(f"[attachment: {name} - send failed]" for name in failed_media)
|
||||
return split_message(fallback, MAX_MESSAGE_LEN)
|
||||
|
||||
@staticmethod
|
||||
def _build_reply_context(
|
||||
self,
|
||||
channel: Messageable,
|
||||
reply_to: str | None,
|
||||
) -> tuple[discord.PartialMessage | None, discord.AllowedMentions]:
|
||||
@ -321,7 +320,7 @@ if DISCORD_AVAILABLE:
|
||||
try:
|
||||
message_id = int(reply_to)
|
||||
except ValueError:
|
||||
logger.warning("Invalid reply target: {}", reply_to)
|
||||
self._channel.logger.warning("Invalid reply target: {}", reply_to)
|
||||
return None, mention_settings
|
||||
|
||||
return channel.get_partial_message(message_id), mention_settings
|
||||
|
||||
@ -1089,8 +1089,8 @@ class WebSocketChannel(BaseChannel):
|
||||
finally:
|
||||
self._cleanup_connection(connection)
|
||||
|
||||
@staticmethod
|
||||
def _save_envelope_media(
|
||||
self,
|
||||
media: list[Any],
|
||||
) -> tuple[list[str], str | None]:
|
||||
"""Decode and persist ``media`` items from a ``message`` envelope.
|
||||
@ -1125,7 +1125,7 @@ class WebSocketChannel(BaseChannel):
|
||||
try:
|
||||
Path(p).unlink(missing_ok=True)
|
||||
except OSError as exc:
|
||||
logger.warning(
|
||||
self.logger.warning(
|
||||
"failed to unlink partial media {}: {}", p, exc
|
||||
)
|
||||
return [], reason
|
||||
@ -1150,7 +1150,7 @@ class WebSocketChannel(BaseChannel):
|
||||
except FileSizeExceeded:
|
||||
return _abort("size")
|
||||
except Exception as exc:
|
||||
logger.warning("media decode failed: {}", exc)
|
||||
self.logger.warning("media decode failed: {}", exc)
|
||||
return _abort("decode")
|
||||
if saved is None:
|
||||
return _abort("decode")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user