From a34c9f0bd2df8836460188810409e8355653f984 Mon Sep 17 00:00:00 2001 From: SlyAimer <2289782085@qq.com> Date: Thu, 3 Apr 2025 14:21:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(send=5Femail):=20=E6=9B=BF=E6=8D=A2print?= =?UTF-8?q?=E4=B8=BAlogger=E8=AE=B0=E5=BD=95=E9=94=99=E8=AF=AF=E6=97=A5?= =?UTF-8?q?=E5=BF=97=20refactor(jm=5Fcomic):=20=E4=BC=98=E5=8C=96=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E5=B9=B6=E7=A7=BB=E9=99=A4=E5=86=97?= =?UTF-8?q?=E4=BD=99=E6=97=A5=E5=BF=97=20refactor(jm=5Fdownload):=20?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E8=BE=93=E5=85=A5=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B9=B6=E7=A7=BB=E9=99=A4=E8=B0=83=E8=AF=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/clover_email/send_email.py | 10 +++++----- src/clover_jm/jm_comic.py | 10 +++++----- src/plugins/jm_download.py | 16 ++++++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/clover_email/send_email.py b/src/clover_email/send_email.py index badf441..88564ba 100644 --- a/src/clover_email/send_email.py +++ b/src/clover_email/send_email.py @@ -3,6 +3,7 @@ from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.mime.text import MIMEText import aiosmtplib +from nonebot import logger from src.configs.api_config import google_smtp_server,google_email,google_password from src.configs.api_config import qq_smtp_server,qq_email,qq_password @@ -123,7 +124,7 @@ async def send_email_by_google(receiver_email: str, file_path: str): try: # 验证文件存在性 if not os.path.isfile(file_path): - print(f"文件不存在:{file_path}") + logger.error(f"文件不存在:{file_path}") return False # 添加单个文件附件 @@ -145,11 +146,10 @@ async def send_email_by_google(receiver_email: str, file_path: str): ) as server: await server.login(google_email, google_password) await server.send_message(msg) - print("文件邮件发送成功!") return True except Exception as e: - print(f"邮件发送失败: {str(e)}") + logger.error(f"邮件发送失败:{e}") return False async def send_email_by_qq(receiver_email: str, file_path: str): @@ -162,7 +162,7 @@ async def send_email_by_qq(receiver_email: str, file_path: str): try: if not os.path.exists(file_path): - print(f"文件不存在:{file_path}") + logger.error(f"文件不存在:{file_path}") return False # 添加附件 @@ -187,5 +187,5 @@ async def send_email_by_qq(receiver_email: str, file_path: str): print("QQ文件邮件发送成功!") return True except Exception as e: - print(f"QQ邮件发送失败: {str(e)}") + logger.error(f"QQ邮件发送失败:{e}") return False diff --git a/src/clover_jm/jm_comic.py b/src/clover_jm/jm_comic.py index 8a03e86..675f48c 100644 --- a/src/clover_jm/jm_comic.py +++ b/src/clover_jm/jm_comic.py @@ -1,7 +1,6 @@ import yaml import uuid import jmcomic -from nonebot import logger from datetime import datetime from src.configs.api_config import qrserver_url,qrserver_size,anonfile_download_url from src.clover_jm.disguise_pdf import * @@ -24,9 +23,11 @@ async def download_jm_Pemail(album_id: str| None,receiver_email: str| None): # 还原配置文件 await recover_jm_config(source_path) #调用JM下载api - album_detail,downloader = await asyncio.get_event_loop().run_in_executor(jm_executor,jmcomic.download_album,album_id,option) - if album_detail.title is None: - return "下载失败,请检查JM ID 是否正确" + try: + album_detail,downloader = await asyncio.get_event_loop().run_in_executor(jm_executor,jmcomic.download_album,album_id,option) + except Exception as e: + logger.error(f"下载失败 :{e}") + return "下载失败,请重试" # 创建变量 folder_path = f"{jm_path}{receiver_email}" zip_path = f"{jm_path}{album_detail.title}.zip" @@ -56,7 +57,6 @@ async def download_jm_qr(album_id: str| None): await recover_jm_config(source_path) #调用JM下载api album_detail,downloader = await asyncio.get_event_loop().run_in_executor(jm_executor,jmcomic.download_album,album_id,option) - logger.debug(f"JM下载api调用成功,返回————>{album_detail}") if album_detail.title is None: return { "msg":"下载失败,请检查JM ID 是否正确" diff --git a/src/plugins/jm_download.py b/src/plugins/jm_download.py index d472080..83bd270 100644 --- a/src/plugins/jm_download.py +++ b/src/plugins/jm_download.py @@ -12,7 +12,6 @@ jm = on_command("jm", rule=to_me(), priority=10, block=False) async def handle_email_download(album_id: str, email: str): """处理邮箱发送逻辑""" - logger.debug(f"开始发送文件到邮箱,ID: {album_id}, 邮箱: {email}") if not validate_email(email): await jm.finish("邮箱格式不正确!") await jm.send("正在发送中,请稍等~") @@ -21,7 +20,6 @@ async def handle_email_download(album_id: str, email: str): async def handle_qrcode_download(album_id: str): """处理二维码发送载逻辑""" - logger.debug(f"开始二维码逻辑,ID: {album_id}") await jm.send("正在下载中,请稍等~") msgs = await download_jm_qr(album_id=album_id) if "qr_code" not in msgs: @@ -34,16 +32,14 @@ async def handle_qrcode_download(album_id: str): @jm.handle() async def handle_function(message: MessageEvent): - values = message.get_plaintext().replace("/jm", "").split(" ") - + values = message.get_plaintext().replace("/jm", "").split() try: - if len(values) == 2: - await handle_qrcode_download(values[1]) - elif len(values) == 3: - await handle_email_download(values[1], values[2]) - else: - logger.debug("输入格式不正确") + if len(values) == 0 or not all(values[1:len(values)]): await jm.finish("请输入正确的格式 /jm+id 或 /jm+id+邮箱号") + elif len(values) == 1: + await handle_qrcode_download(values[0]) + elif len(values) == 2: + await handle_email_download(values[0], values[1]) except Exception as e: if isinstance(e, FinishedException): return