From 7d02e94e5f87d7288d44eff5267f6ec7b23ad2d9 Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 7 Jul 2026 00:21:46 +0800 Subject: [PATCH] =?UTF-8?q?S-11=20AstrBot=20=E6=96=87=E4=BB=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 60 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index b7f08a6..21c7439 100644 --- a/main.py +++ b/main.py @@ -56,6 +56,7 @@ class JMDownloadPlugin(Star): return await event.send(event.plain_result(f"开始下载 JM {comic_id},任务已进入队列。")) + file_send_message = "" try: async with self.task_semaphore: await event.send(event.plain_result(f"开始执行 JM {comic_id} 下载任务。")) @@ -66,21 +67,17 @@ class JMDownloadPlugin(Star): archive_result = await self.archiver.archive(downloaded) self.downloader.cleanup(downloaded) scan_result = await self.komga.scan_library() + if self.settings.send_archive_file: + file_send_message = await self._send_archive_file(event, archive_result) except Exception as exc: logger.exception(f"JMDownload failed for {comic_id}") yield event.plain_result(f"JMDownload 失败:{exc}") event.stop_event() return - if self.settings.send_archive_file: - yield event.chain_result( - [ - Comp.Plain(self._format_success(archive_result, scan_result)), - Comp.File(name=archive_result.path.name, file=str(archive_result.path)), - ], - ) - else: - yield event.plain_result(self._format_success(archive_result, scan_result)) + yield event.plain_result( + self._format_success(archive_result, scan_result, file_send_message), + ) event.stop_event() @jm.command("status") @@ -122,18 +119,43 @@ class JMDownloadPlugin(Star): self, archive_result: ArchiveResult, scan_result: KomgaScanResult, + file_send_message: str = "", ) -> str: existed = "复用已有归档" if archive_result.existed else "已创建归档" - return "\n".join( - [ - f"JMDownload 完成:{existed}", - f"系列:{archive_result.series_name}", - f"格式:{archive_result.archive_format}", - f"页数:{archive_result.page_count}", - f"文件:{archive_result.path}", - f"Komga: {scan_result.message}", - ], - ) + lines = [ + f"JMDownload 完成:{existed}", + f"系列:{archive_result.series_name}", + f"格式:{archive_result.archive_format}", + f"页数:{archive_result.page_count}", + f"文件:{archive_result.path}", + f"Komga: {scan_result.message}", + ] + if file_send_message: + lines.append(file_send_message) + return "\n".join(lines) + + async def _send_archive_file( + self, + event: AstrMessageEvent, + archive_result: ArchiveResult, + ) -> str: + if not archive_result.path.exists(): + return "文件发送:归档文件不存在,已跳过发送。" + try: + await event.send( + event.chain_result( + [ + Comp.File( + name=archive_result.path.name, + file=str(archive_result.path.resolve()), + ), + ], + ), + ) + return "文件发送:已尝试发送归档文件。" + except Exception as exc: + logger.warning(f"JMDownload: file send failed: {exc}") + return f"文件发送:平台发送失败,归档仍保存在本地。原因:{exc}" async def _send_progress( self,