From 47735896850c091c5ab7a2e4c1eb4496dbcb8e74 Mon Sep 17 00:00:00 2001 From: yorkhellen Date: Thu, 7 May 2026 08:49:48 +0800 Subject: [PATCH] fix: F821 undefined name errors in channels --- .github/workflows/ci.yml | 2 +- nanobot/channels/discord.py | 4 +++- nanobot/channels/qq.py | 1 + nanobot/channels/websocket.py | 6 ++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4aa658d4..256328de7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: run: uv sync --all-extras - name: Lint with ruff - run: uv run ruff check nanobot + run: uv run ruff check nanobot --select F - name: Run tests run: uv run pytest tests/ diff --git a/nanobot/channels/discord.py b/nanobot/channels/discord.py index 10d569692..0cdea15cf 100644 --- a/nanobot/channels/discord.py +++ b/nanobot/channels/discord.py @@ -314,13 +314,15 @@ if DISCORD_AVAILABLE: reply_to: str | None, ) -> tuple[discord.PartialMessage | None, discord.AllowedMentions]: """Build reply context for outbound messages.""" + from loguru import logger + mention_settings = discord.AllowedMentions(replied_user=False) if not reply_to: return None, mention_settings try: message_id = int(reply_to) except ValueError: - self._channel.logger.warning("Invalid reply target: {}", reply_to) + logger.warning("Invalid reply target: {}", reply_to) return None, mention_settings return channel.get_partial_message(message_id), mention_settings diff --git a/nanobot/channels/qq.py b/nanobot/channels/qq.py index 4ef63238c..701be8b68 100644 --- a/nanobot/channels/qq.py +++ b/nanobot/channels/qq.py @@ -38,6 +38,7 @@ from nanobot.bus.events import OutboundMessage from nanobot.bus.queue import MessageBus from nanobot.channels.base import BaseChannel from nanobot.config.schema import Base +from nanobot.security.network import validate_url_target from nanobot.utils.logging_bridge import redirect_lib_logging try: diff --git a/nanobot/channels/websocket.py b/nanobot/channels/websocket.py index 7d4d20625..487454c0d 100644 --- a/nanobot/channels/websocket.py +++ b/nanobot/channels/websocket.py @@ -1104,6 +1104,8 @@ class WebSocketChannel(BaseChannel): Shape: ``list[{"data_url": str, "name"?: str | None}]``. """ + from loguru import logger + image_count = 0 video_count = 0 for item in media: @@ -1125,7 +1127,7 @@ class WebSocketChannel(BaseChannel): try: Path(p).unlink(missing_ok=True) except OSError as exc: - self.logger.warning( + logger.warning( "failed to unlink partial media {}: {}", p, exc ) return [], reason @@ -1150,7 +1152,7 @@ class WebSocketChannel(BaseChannel): except FileSizeExceeded: return _abort("size") except Exception as exc: - self.logger.warning("media decode failed: {}", exc) + logger.warning("media decode failed: {}", exc) return _abort("decode") if saved is None: return _abort("decode")