S-11 AstrBot 文件发送
这个提交存在于:
父节点
f1b2e90703
当前提交
7d02e94e5f
共有 1 个文件被更改,包括 41 次插入 和 19 次删除
42
main.py
42
main.py
|
|
@ -56,6 +56,7 @@ class JMDownloadPlugin(Star):
|
||||||
return
|
return
|
||||||
|
|
||||||
await event.send(event.plain_result(f"开始下载 JM {comic_id},任务已进入队列。"))
|
await event.send(event.plain_result(f"开始下载 JM {comic_id},任务已进入队列。"))
|
||||||
|
file_send_message = ""
|
||||||
try:
|
try:
|
||||||
async with self.task_semaphore:
|
async with self.task_semaphore:
|
||||||
await event.send(event.plain_result(f"开始执行 JM {comic_id} 下载任务。"))
|
await event.send(event.plain_result(f"开始执行 JM {comic_id} 下载任务。"))
|
||||||
|
|
@ -66,21 +67,17 @@ class JMDownloadPlugin(Star):
|
||||||
archive_result = await self.archiver.archive(downloaded)
|
archive_result = await self.archiver.archive(downloaded)
|
||||||
self.downloader.cleanup(downloaded)
|
self.downloader.cleanup(downloaded)
|
||||||
scan_result = await self.komga.scan_library()
|
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:
|
except Exception as exc:
|
||||||
logger.exception(f"JMDownload failed for {comic_id}")
|
logger.exception(f"JMDownload failed for {comic_id}")
|
||||||
yield event.plain_result(f"JMDownload 失败:{exc}")
|
yield event.plain_result(f"JMDownload 失败:{exc}")
|
||||||
event.stop_event()
|
event.stop_event()
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.settings.send_archive_file:
|
yield event.plain_result(
|
||||||
yield event.chain_result(
|
self._format_success(archive_result, scan_result, file_send_message),
|
||||||
[
|
|
||||||
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))
|
|
||||||
event.stop_event()
|
event.stop_event()
|
||||||
|
|
||||||
@jm.command("status")
|
@jm.command("status")
|
||||||
|
|
@ -122,18 +119,43 @@ class JMDownloadPlugin(Star):
|
||||||
self,
|
self,
|
||||||
archive_result: ArchiveResult,
|
archive_result: ArchiveResult,
|
||||||
scan_result: KomgaScanResult,
|
scan_result: KomgaScanResult,
|
||||||
|
file_send_message: str = "",
|
||||||
) -> str:
|
) -> str:
|
||||||
existed = "复用已有归档" if archive_result.existed else "已创建归档"
|
existed = "复用已有归档" if archive_result.existed else "已创建归档"
|
||||||
return "\n".join(
|
lines = [
|
||||||
[
|
|
||||||
f"JMDownload 完成:{existed}",
|
f"JMDownload 完成:{existed}",
|
||||||
f"系列:{archive_result.series_name}",
|
f"系列:{archive_result.series_name}",
|
||||||
f"格式:{archive_result.archive_format}",
|
f"格式:{archive_result.archive_format}",
|
||||||
f"页数:{archive_result.page_count}",
|
f"页数:{archive_result.page_count}",
|
||||||
f"文件:{archive_result.path}",
|
f"文件:{archive_result.path}",
|
||||||
f"Komga: {scan_result.message}",
|
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(
|
async def _send_progress(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
正在加载…
添加表格
在新工单中引用