From 08ba1399ef4a3c1c3d2c2ff388dcd5d3d0e8e6c6 Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Sun, 5 Apr 2026 21:35:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=86=E6=8A=BD=E5=8D=A1?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E9=81=97=E7=95=99=E8=BF=81=E7=A7=BB=E6=AD=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 claim_achievement_reward 中不可达的 _migrate_data() 调用 - 删除 _migrate_data() 方法(JSON→SQLite 迁移已完成,不再需要) - 删除 config 中 DAILY_DRAWS_FILE / USER_STATS_FILE 遗留配置 --- danding_bot/plugins/onmyoji_gacha/config.py | 2 - .../plugins/onmyoji_gacha/data_manager.py | 68 +------------------ 2 files changed, 2 insertions(+), 68 deletions(-) diff --git a/danding_bot/plugins/onmyoji_gacha/config.py b/danding_bot/plugins/onmyoji_gacha/config.py index bf9f01a..561c7f3 100644 --- a/danding_bot/plugins/onmyoji_gacha/config.py +++ b/danding_bot/plugins/onmyoji_gacha/config.py @@ -17,8 +17,6 @@ class Config(BaseSettings): # 数据文件路径 DB_FILE: str = "data/onmyoji_gacha/gacha.db" - DAILY_DRAWS_FILE: str = "data/onmyoji_gacha/daily_draws.json" # 保留用于迁移 - USER_STATS_FILE: str = "data/onmyoji_gacha/user_stats.json" # 保留用于迁移 # 式神图片目录 SHIKIGAMI_IMG_DIR: str = "data/chouka/" diff --git a/danding_bot/plugins/onmyoji_gacha/data_manager.py b/danding_bot/plugins/onmyoji_gacha/data_manager.py index c010aa5..361b69d 100644 --- a/danding_bot/plugins/onmyoji_gacha/data_manager.py +++ b/danding_bot/plugins/onmyoji_gacha/data_manager.py @@ -277,72 +277,8 @@ class DataManager: conn.commit() return cursor.rowcount > 0 - - # 迁移现有JSON数据到SQLite - self._migrate_data() - - def _migrate_data(self): - """迁移JSON数据到SQLite""" - try: - # 迁移每日抽卡记录 - if os.path.exists(config.DAILY_DRAWS_FILE): - with open(config.DAILY_DRAWS_FILE, 'r', encoding='utf-8') as f: - daily_draws = json.load(f) - - with sqlite3.connect(config.DB_FILE) as conn: - cursor = conn.cursor() - - for date, users in daily_draws.items(): - for user_id, draws in users.items(): - for draw in draws: - # 查找式神ID - cursor.execute( - "SELECT id FROM shikigami WHERE name=? AND rarity=?", - (draw["name"], draw["rarity"]) - ) - shikigami_id = cursor.fetchone() - - if shikigami_id: - cursor.execute( - "INSERT INTO daily_draws (date, user_id, rarity, shikigami_id, timestamp) VALUES (?, ?, ?, ?, ?)", - (date, user_id, draw["rarity"], shikigami_id[0], draw["timestamp"]) - ) - - conn.commit() - - # 迁移用户统计数据 - if os.path.exists(config.USER_STATS_FILE): - with open(config.USER_STATS_FILE, 'r', encoding='utf-8') as f: - user_stats = json.load(f) - - with sqlite3.connect(config.DB_FILE) as conn: - cursor = conn.cursor() - - for user_id, stats in user_stats.items(): - cursor.execute( - "INSERT OR REPLACE INTO user_stats (user_id, total_draws, R_count, SR_count, SSR_count, SP_count) VALUES (?, ?, ?, ?, ?, ?)", - (user_id, stats["total_draws"], stats["R_count"], stats["SR_count"], stats["SSR_count"], stats["SP_count"]) - ) - - # 迁移抽卡历史 - for draw in stats.get("draw_history", []): - cursor.execute( - "SELECT id FROM shikigami WHERE name=? AND rarity=?", - (draw["name"], draw["rarity"]) - ) - shikigami_id = cursor.fetchone() - - if shikigami_id: - cursor.execute( - "INSERT INTO draw_history (user_id, date, rarity, shikigami_id) VALUES (?, ?, ?, ?)", - (user_id, draw["date"], draw["rarity"], shikigami_id[0]) - ) - - conn.commit() - - except Exception as e: - logging.error(f"数据迁移失败: {e}") - + + def _load_shikigami_data(self) -> Dict[str, List[Dict[str, str]]]: """加载式神数据到数据库""" result = {"R": [], "SR": [], "SSR": [], "SP": []}