_state
_state
¶
Polling state storage for the event system.
PollingState
¶
PollingState()
In-memory state for polled resources with optional JSON persistence.
Source code in cocapi/events/_state.py
28 29 30 31 32 33 34 | |
get_clan
¶
get_clan(tag: str) -> dict[str, Any] | None
Return the last-polled clan snapshot, or None if not yet polled.
Source code in cocapi/events/_state.py
38 39 40 | |
set_clan
¶
set_clan(tag: str, data: dict[str, Any]) -> None
Store the latest clan snapshot for diffing on the next poll.
Source code in cocapi/events/_state.py
42 43 44 | |
get_members
¶
get_members(tag: str) -> list[dict[str, Any]] | None
Return the last-polled member list for a clan, or None.
Source code in cocapi/events/_state.py
48 49 50 | |
set_members
¶
set_members(
tag: str, members: list[dict[str, Any]]
) -> None
Store the latest member list snapshot for a clan.
Source code in cocapi/events/_state.py
52 53 54 | |
get_war
¶
get_war(tag: str) -> dict[str, Any] | None
Return the last-polled war snapshot, or None if not yet polled.
Source code in cocapi/events/_state.py
58 59 60 | |
set_war
¶
set_war(tag: str, data: dict[str, Any]) -> None
Store the latest war snapshot for diffing on the next poll.
Source code in cocapi/events/_state.py
62 63 64 | |
get_war_fsm
¶
get_war_fsm(tag: str) -> WarStateMachine
Return the war state machine for a clan, creating one if needed.
Source code in cocapi/events/_state.py
66 67 68 69 70 | |
get_player
¶
get_player(tag: str) -> dict[str, Any] | None
Return the last-polled player snapshot, or None if not yet polled.
Source code in cocapi/events/_state.py
74 75 76 | |
set_player
¶
set_player(tag: str, data: dict[str, Any]) -> None
Store the latest player snapshot for diffing on the next poll.
Source code in cocapi/events/_state.py
78 79 80 | |
should_poll
¶
should_poll(resource_key: str, interval: float) -> bool
Check if enough time has passed since the last poll.
Source code in cocapi/events/_state.py
84 85 86 87 | |
mark_polled
¶
mark_polled(resource_key: str) -> None
Record the current time as the last poll time for a resource.
Source code in cocapi/events/_state.py
89 90 91 | |
save
¶
save(path: Path) -> None
Persist state to JSON file for restart recovery.
Source code in cocapi/events/_state.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
load
¶
load(path: Path) -> bool
Load state from JSON file. Returns True if loaded successfully.
Source code in cocapi/events/_state.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |