From 907740172beec20a786a40b912766212e8826c62 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Tue, 23 Jul 2024 15:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=98=8E=E5=87=8F=E5=B0=91=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A0=E9=99=A4=E9=9A=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trimo_plugin_msctconverter/msctexec.py | 24 ++++++++++++++--- .../trimo_plugin_msctconverter/mspvexec.py | 26 +++++++++++-------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/plugins/trimo_plugin_msctconverter/msctexec.py b/src/plugins/trimo_plugin_msctconverter/msctexec.py index ba2b95e..6de8ad7 100644 --- a/src/plugins/trimo_plugin_msctconverter/msctexec.py +++ b/src/plugins/trimo_plugin_msctconverter/msctexec.py @@ -204,11 +204,23 @@ async def _(): nonebot.logger.success("删除临时文件目录完成") +file_to_delete = [] + @scheduler.scheduled_job("interval", seconds=30) async def _(): nonebot.logger.info( "-删除文件检测-", ) + global file_to_delete + for path_d in file_to_delete.copy(): + try: + if os.path.exists(path_d): + os.remove(path_d) + file_to_delete.remove(path_d) + nonebot.logger.success("删除临时文件:{}".format(path_d)) + except: + nonebot.logger.warning("跳过临时文件删除:{}".format(path_d)) + global filesaves qqidlist = list(filesaves.keys()).copy() save_file = False for qqid in qqidlist: @@ -577,7 +589,7 @@ async def _( if (qres := query_convert_points(usr_id, "music"))[0] is False: await linglun_convert.finish( UniMessage.text( - "转换点数不足,当前剩余:{}|{}点".format( + "转换点数不足,当前剩余:⌊p⌋≈{:.2f}|{}".format( qres[1], configdict["maxPersonConvert"]["music"], ) @@ -728,6 +740,8 @@ async def _( return True # return res, pnt + await linglun_convert.send(UniMessage.text("转换开始……")) + try: progress_bar_style = ( @@ -1024,11 +1038,13 @@ async def _( event=event, ) - os.remove(fp) + global file_to_delete + file_to_delete.append(fp) + # os.remove(fp) await linglun_convert.finish( UniMessage.text( - "转换结束,当前剩余转换点数: {}|{}".format( + "转换结束,当前剩余转换点数:⌊p⌋≈{:.2f}|{}".format( query_convert_points(usr_id, "music", 0, None)[1], configdict["maxPersonConvert"]["music"], ) @@ -1103,7 +1119,7 @@ async def _( await linglun_convert.finish( UniMessage.text( - "重置转换状况并修改点数成功!当前{}的{}点数为:{}|{}".format( + "重置转换状况并修改点数成功!当前{}的{}点数为:⌊p⌋≈{:.2f}|{}".format( to_change, v_item, query_convert_points(to_change, v_item, -cd_value, None)[1], diff --git a/src/plugins/trimo_plugin_msctconverter/mspvexec.py b/src/plugins/trimo_plugin_msctconverter/mspvexec.py index d9d7cda..98df364 100644 --- a/src/plugins/trimo_plugin_msctconverter/mspvexec.py +++ b/src/plugins/trimo_plugin_msctconverter/mspvexec.py @@ -5,7 +5,7 @@ import shutil import random from io import StringIO -from pathlib import Path +# from pathlib import Path # import nonebot.rule @@ -24,15 +24,15 @@ from nonebot.adapters.onebot.v11.event import ( ) from nonebot_plugin_alconna import ( Alconna, - AlconnaQuery, + # AlconnaQuery, Args, - Image, + # Image, Option, - Query, - Text, + # Query, + # Text, UniMessage, on_alconna, - Voice, + # Voice, Arparma, Args, store_true, @@ -42,12 +42,13 @@ from src.utils.base.ly_typing import T_Bot, T_MessageEvent from src.utils.message.message import MarkdownMessage from .msctexec import ( - people_convert_point, + # people_convert_point, query_convert_points, filesaves, configdict, database_dir, temporary_dir, + file_to_delete, ) mspv_sync = on_alconna( @@ -111,7 +112,7 @@ async def _( if (qres := query_convert_points(usr_id, "music"))[0] is False: await mspv_sync.finish( UniMessage.text( - "转换点数不足,当前剩余:{}|{}点".format( + "转换点数不足,当前剩余:⌊p⌋≈{:.2f}|{}".format( qres[1], configdict["maxPersonConvert"]["music"], ) @@ -240,6 +241,8 @@ async def _( else: return True + await mspv_sync.send(UniMessage.text("转换开始……")) + try: all_files = [] @@ -407,7 +410,8 @@ async def _( except nonebot.adapters.onebot.v11.exception.NetworkError as E: buffer.write("文件上传发生网络错误:\n{}".format(E)) - os.remove(fp) + global file_to_delete + file_to_delete.append(fp) await MarkdownMessage.send_md( "##{}\n\n```\n{}\n```".format( @@ -420,13 +424,13 @@ async def _( # nonebot.logger.info(buffer.getvalue()) - await mspv_sync.send(UniMessage.text("成功转换:{}".format("、".join(all_files)))) shutil.rmtree(usr_temp_path) await mspv_sync.finish( UniMessage.text( - "转换结束,当前剩余转换点数: {}|{}".format( + "成功转换:{}\n当前剩余转换点数:⌊p⌋≈{:.2f}|{}".format( + "、".join(all_files), query_convert_points(usr_id, "music", 0, None)[1], configdict["maxPersonConvert"]["music"], )