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": []}