S-11 AstrBot 文件发送

这个提交存在于:
Codex 2026-07-07 00:21:46 +08:00
父节点 f1b2e90703
当前提交 7d02e94e5f

60
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,