diff --git a/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py b/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py index 1a5eba2..dcbf9e3 100644 --- a/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py +++ b/src/nonebot_plugins/trimo_plugin_msctconverter/command_structure.py @@ -226,7 +226,7 @@ async def read_file_into_command_lines( cdt = False note = "" functionList = [] - for lines in (await read_file(file_path=file_, mode="r")).split("\n\n"): # type: ignore + for lines in (await read_file(file_path=file_, mode="r", encoding="utf-8")).split("\n\n"): # type: ignore funcGroup = [] for line in lines.split("\n"): if line.strip().startswith("#"): diff --git a/src/nonebot_plugins/trimo_plugin_msctconverter/msctexec.py b/src/nonebot_plugins/trimo_plugin_msctconverter/msctexec.py index 67c5bbc..041b31a 100644 --- a/src/nonebot_plugins/trimo_plugin_msctconverter/msctexec.py +++ b/src/nonebot_plugins/trimo_plugin_msctconverter/msctexec.py @@ -322,7 +322,7 @@ async def _(): "-删除临时内容-", ) global something_temporary - for index_, stuff_component in something_temporary.items(): + for index_, stuff_component in something_temporary.copy().items(): if stuff_component["time"] <= 0: # type: ignore if isinstance(stuff_component["stuff"], (str, Path, os.PathLike)): try: diff --git a/src/utils/io/file.py b/src/utils/io/file.py index c25a9c7..234db34 100644 --- a/src/utils/io/file.py +++ b/src/utils/io/file.py @@ -4,7 +4,8 @@ import aiofiles async def write_file( file_path: str, content: str | bytes, - mode: str = "w" + mode: str = "w", + **kws, ): """ 写入文件 @@ -13,11 +14,11 @@ async def write_file( file_path: 文件路径 content: 内容 """ - async with aiofiles.open(file_path, mode) as f: + async with aiofiles.open(file_path, mode, **kws) as f: await f.write(content) -async def read_file(file_path: str, mode: str = "r") -> str: +async def read_file(file_path: str, mode: str = "r", **kws) -> str: """ 读取文件 Args: @@ -25,5 +26,5 @@ async def read_file(file_path: str, mode: str = "r") -> str: mode: 读取模式 Returns: """ - async with aiofiles.open(file_path, mode) as f: + async with aiofiles.open(file_path, mode, **kws) as f: return await f.read()