From e67c1173487784c60b579eca1d0ca2eddffc1f6d Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sun, 15 May 2022 21:12:39 +0800 Subject: [PATCH] fix bug --- Guess_voice/__init__.py | 8 +++++--- Guess_voice/download_data.py | 2 +- Guess_voice/handler.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Guess_voice/__init__.py b/Guess_voice/__init__.py index 53dcb0e..8b2f731 100644 --- a/Guess_voice/__init__.py +++ b/Guess_voice/__init__.py @@ -25,9 +25,11 @@ update_ys_voice = on_command('更新原神语音资源', priority=12, permission async def download_voice(bot: Bot, event: Union[PrivateMessageEvent, GroupMessageEvent]): - await bot.send(event, '资源尚未初始化,现在开始下载资源,这需要较长的时间,请耐心等待') - await download_data.update_voice_data() - await bot.send(event, '资源下载完成,请重新发送指令开始游戏') + if not dir_name.exists(): + dir_name.mkdir(parents=True, exist_ok=True) + await bot.send(event, '资源尚未初始化,现在开始下载资源,这需要较长的时间,请耐心等待') + await download_data.update_voice_data() + await bot.send(event, '资源下载完成,请重新发送指令开始游戏') @guess_game.handle() diff --git a/Guess_voice/download_data.py b/Guess_voice/download_data.py index 2db4350..ac5dfbf 100644 --- a/Guess_voice/download_data.py +++ b/Guess_voice/download_data.py @@ -36,7 +36,7 @@ dir_data.mkdir(parents=True, exist_ok=True) ############ def init_db(db_dir, db_name='db.sqlite') -> SqliteDict: - return SqliteDict(get_path(db_dir, db_name), + return SqliteDict(str(get_path(db_dir, db_name)), encode=json.dumps, decode=json.loads, autocommit=True) diff --git a/Guess_voice/handler.py b/Guess_voice/handler.py index a431a4e..fa59b2a 100644 --- a/Guess_voice/handler.py +++ b/Guess_voice/handler.py @@ -35,7 +35,7 @@ def init_db(db_dir, db_name='db.sqlite', tablename='unnamed') -> SqliteDict: db_cache_key = db_name + tablename if db.get(db_cache_key): return db[db_cache_key] - db[db_cache_key] = SqliteDict(get_path(db_dir, db_name), + db[db_cache_key] = SqliteDict(str(get_path(db_dir, db_name)), tablename=tablename, encode=json.dumps, decode=json.loads,