mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 00:22:31 +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 pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any, Literal
|
from typing import TYPE_CHECKING, Any, Literal
|
||||||
|
|
||||||
from loguru import logger
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
from nanobot.bus.events import OutboundMessage
|
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)
|
fallback = "\n".join(f"[attachment: {name} - send failed]" for name in failed_media)
|
||||||
return split_message(fallback, MAX_MESSAGE_LEN)
|
return split_message(fallback, MAX_MESSAGE_LEN)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _build_reply_context(
|
def _build_reply_context(
|
||||||
|
self,
|
||||||
channel: Messageable,
|
channel: Messageable,
|
||||||
reply_to: str | None,
|
reply_to: str | None,
|
||||||
) -> tuple[discord.PartialMessage | None, discord.AllowedMentions]:
|
) -> tuple[discord.PartialMessage | None, discord.AllowedMentions]:
|
||||||
@ -321,7 +320,7 @@ if DISCORD_AVAILABLE:
|
|||||||
try:
|
try:
|
||||||
message_id = int(reply_to)
|
message_id = int(reply_to)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warning("Invalid reply target: {}", reply_to)
|
self._channel.logger.warning("Invalid reply target: {}", reply_to)
|
||||||
return None, mention_settings
|
return None, mention_settings
|
||||||
|
|
||||||
return channel.get_partial_message(message_id), mention_settings
|
return channel.get_partial_message(message_id), mention_settings
|
||||||
|
|||||||
@ -1089,8 +1089,8 @@ class WebSocketChannel(BaseChannel):
|
|||||||
finally:
|
finally:
|
||||||
self._cleanup_connection(connection)
|
self._cleanup_connection(connection)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _save_envelope_media(
|
def _save_envelope_media(
|
||||||
|
self,
|
||||||
media: list[Any],
|
media: list[Any],
|
||||||
) -> tuple[list[str], str | None]:
|
) -> tuple[list[str], str | None]:
|
||||||
"""Decode and persist ``media`` items from a ``message`` envelope.
|
"""Decode and persist ``media`` items from a ``message`` envelope.
|
||||||
@ -1125,7 +1125,7 @@ class WebSocketChannel(BaseChannel):
|
|||||||
try:
|
try:
|
||||||
Path(p).unlink(missing_ok=True)
|
Path(p).unlink(missing_ok=True)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
logger.warning(
|
self.logger.warning(
|
||||||
"failed to unlink partial media {}: {}", p, exc
|
"failed to unlink partial media {}: {}", p, exc
|
||||||
)
|
)
|
||||||
return [], reason
|
return [], reason
|
||||||
@ -1150,7 +1150,7 @@ class WebSocketChannel(BaseChannel):
|
|||||||
except FileSizeExceeded:
|
except FileSizeExceeded:
|
||||||
return _abort("size")
|
return _abort("size")
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning("media decode failed: {}", exc)
|
self.logger.warning("media decode failed: {}", exc)
|
||||||
return _abort("decode")
|
return _abort("decode")
|
||||||
if saved is None:
|
if saved is None:
|
||||||
return _abort("decode")
|
return _abort("decode")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user