File size: 1,756 Bytes
8d21059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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