# utils/state.py — إدارة حالات المستخدم بشكل معزول تماماً # كل section لها مفتاحها الخاص لمنع أي تداخل # مفاتيح الحالات STATE_KEY = "bot_mode" # القيم: None | "wall" | "specs" | "igdb_game" | "igdb_char" WALL_KEY = "wall_active" # True عندما يكون في قسم الخلفيات SPECS_KEY = "specs_active" # True عندما يكون في قسم المواصفات IGDB_KEY = "igdb_await" # "game" | "char" SEARCH_KEY = "search_platform" # "pc" | "ps" | "all" def clear_all(ctx) -> None: """مسح كل الحالات — يُستدعى قبل تعيين حالة جديدة.""" for key in (STATE_KEY, WALL_KEY, SPECS_KEY, IGDB_KEY, SEARCH_KEY): ctx.user_data.pop(key, None) def set_wall_mode(ctx) -> None: clear_all(ctx) ctx.user_data[WALL_KEY] = True def set_specs_mode(ctx) -> None: clear_all(ctx) ctx.user_data[SPECS_KEY] = True def set_igdb_mode(ctx, mode: str) -> None: """mode: 'game' | 'char'""" clear_all(ctx) ctx.user_data[IGDB_KEY] = mode def set_search_mode(ctx, platform: str) -> None: """platform: 'pc' | 'ps'""" clear_all(ctx) ctx.user_data[SEARCH_KEY] = platform def get_mode(ctx) -> str | None: """ يُعيد الوضع الحالي للمستخدم. القيم: 'wall' | 'specs' | 'igdb_game' | 'igdb_char' | 'search_pc' | 'search_ps' | None """ if ctx.user_data.get(WALL_KEY): return "wall" if ctx.user_data.get(SPECS_KEY): return "specs" ig = ctx.user_data.get(IGDB_KEY) if ig: return f"igdb_{ig}" sp = ctx.user_data.get(SEARCH_KEY) if sp: return f"search_{sp}" return None