From f2467b9377cc337531743251e5e80742bf2377c1 Mon Sep 17 00:00:00 2001 From: EillesWan Date: Tue, 22 Oct 2024 02:08:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8Fbug=E5=BF=AB=E5=BF=AB=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command_structure.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py b/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py index 9e9240c..d2a35c7 100644 --- a/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py +++ b/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py @@ -292,16 +292,20 @@ async def _( if len(whole_texts) < 2: await write_2_file.finish(ulang.get("writefile.no_text")) - - cmd_arg = whole_texts[0].split(" ",2) - - file_2_write = (cmd_arg[1]+ ".txt") if len(cmd_arg) > 1 else "新建文本文档.txt" - file_path = get_stored_path(usr_id, file_2_write, superuser=False) + cmd_arg = whole_texts[0].split(" ", 2) + + file_2_write = (cmd_arg[1] + ".txt") if len(cmd_arg) > 1 else "新建文本文档.txt" + + (file_path := get_stored_path(usr_id, file_2_write, superuser=False)).parent.mkdir( + parents=True, exist_ok=True + ) if "-a" in whole_texts[0]: if file_2_write in filesaves[usr_id].keys(): - await write_file(file_path,content=whole_texts[1], mode="a", encoding="utf-8") + await write_file( + file_path, content=whole_texts[1], mode="a", encoding="utf-8" + ) file_size = os.path.getsize(file_path) filesaves[usr_id]["totalSize"] += ( file_size - filesaves[usr_id][file_2_write]["size"] @@ -318,7 +322,7 @@ async def _( else: await write_2_file.finish(ulang.get("writefile.file_not_exist")) else: - await write_file(file_path,content=whole_texts[1], mode="w", encoding="utf-8") + await write_file(file_path, content=whole_texts[1], mode="w", encoding="utf-8") now = zhDateTime.DateTime.now() file_size = os.path.getsize(file_path) try: