mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
fix(send_email): 替换print为logger记录错误日志
refactor(jm_comic): 优化异常处理并移除冗余日志 refactor(jm_download): 简化输入处理逻辑并移除调试日志
This commit is contained in:
parent
e119bc3268
commit
a34c9f0bd2
3 changed files with 16 additions and 20 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
try:
|
||||
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 是否正确"
|
||||
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 是否正确"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue