-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconst.py
More file actions
163 lines (150 loc) · 6.23 KB
/
Copy pathconst.py
File metadata and controls
163 lines (150 loc) · 6.23 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""Constants for the Torn City integration."""
DOMAIN = "torn"
# API Configuration
API_BASE_URL = "https://api.torn.com"
API_TIMEOUT = 10
API_RATE_LIMIT = 100 # requests per minute
# Configuration
CONF_API_KEY = "api_key"
CONF_UPDATE_INTERVAL = "update_interval"
CONF_THROTTLE_API = "throttle_api"
CONF_ENABLE_MONEY = "enable_money"
CONF_ENABLE_TRAVEL = "enable_travel"
CONF_ENABLE_COOLDOWNS = "enable_cooldowns"
CONF_ENABLE_STATS = "enable_stats"
CONF_ENABLE_SKILLS = "enable_skills"
CONF_ENABLE_COMPANY = "enable_company"
CONF_ENABLE_STOCKS = "enable_stocks"
CONF_ENABLE_REFILLS = "enable_refills"
CONF_ENABLE_LOG = "enable_log"
# Default values
DEFAULT_SCAN_INTERVAL = 1
# Cache durations for different endpoint types (in seconds)
CACHE_DURATION_SHORT = 5
CACHE_DURATION_MEDIUM = 60
CACHE_DURATION_LONG = 600
# Endpoint categories and their mapping
# Each category can be enabled/disabled in options
ENDPOINT_CATEGORIES = {
"core": {
"name": "Profile & Bars",
"description": "Essential player information (always enabled)",
"enabled_by_default": True,
"can_disable": False,
"endpoints": [
{"path": "/v2/user/basic", "key": "profile", "cache_for": CACHE_DURATION_SHORT},
{"path": "/v2/user/bars", "key": "bars", "cache_for": CACHE_DURATION_SHORT},
],
},
CONF_ENABLE_MONEY: {
"name": "Money & Banking",
"description": "Wallet, vault, banks, faction funds",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/user/money", "key": "money", "cache_for": CACHE_DURATION_SHORT},
],
},
CONF_ENABLE_TRAVEL: {
"name": "Travel",
"description": "Travel status and destination",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/user/travel", "key": "travel", "cache_for": CACHE_DURATION_SHORT},
],
},
CONF_ENABLE_COOLDOWNS: {
"name": "Cooldowns",
"description": "Drug, medical, booster cooldowns",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/user/cooldowns", "key": "cooldowns", "cache_for": CACHE_DURATION_MEDIUM},
],
},
CONF_ENABLE_STATS: {
"name": "Personal Stats",
"description": "Personal statistics",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/user/personalstats", "key": "personalstats", "params": {"cat": "all"}, "cache_for": CACHE_DURATION_MEDIUM},
],
},
CONF_ENABLE_SKILLS: {
"name": "Skills",
"description": "Player skills",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/user/skills", "key": "skills", "cache_for": CACHE_DURATION_LONG},
],
},
CONF_ENABLE_COMPANY: {
"name": "Company",
"description": "Company information and stats",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/company", "key": "company", "response_key": "profile", "cache_for": CACHE_DURATION_MEDIUM},
],
},
CONF_ENABLE_STOCKS: {
"name": "Stocks",
"description": "Stock market data and holdings",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/torn", "key": "torn_stocks", "params": {"selections": "stocks"}, "cache_for": CACHE_DURATION_MEDIUM},
{"path": "/user", "key": "user_stocks", "params": {"selections": "stocks"}, "cache_for": CACHE_DURATION_MEDIUM},
],
},
CONF_ENABLE_REFILLS: {
"name": "Refills",
"description": "Refill information",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/user", "key": "refills", "params": {"selections": "refills"}, "cache_for": CACHE_DURATION_LONG},
],
},
CONF_ENABLE_LOG: {
"name": "Activity Log",
"description": "Recent activity log",
"enabled_by_default": True,
"can_disable": True,
"endpoints": [
{"path": "/v2/user/log", "key": "log", "params": {"limit": "10"}, "cache_for": CACHE_DURATION_SHORT},
],
},
}
# API Endpoints to fetch (built from enabled categories)
# This is now dynamically built based on enabled categories
API_ENDPOINTS = [
{"path": "/v2/user/basic", "key": "profile", "cache_for": CACHE_DURATION_SHORT},
{"path": "/v2/user/bars", "key": "bars", "cache_for": CACHE_DURATION_SHORT},
{"path": "/v2/user/money", "key": "money", "cache_for": CACHE_DURATION_SHORT},
{"path": "/v2/user/travel", "key": "travel", "cache_for": CACHE_DURATION_SHORT},
{"path": "/v2/user/log", "key": "log", "params": {"limit": "10"}, "cache_for": CACHE_DURATION_SHORT},
{"path": "/v2/user/cooldowns", "key": "cooldowns", "cache_for": CACHE_DURATION_MEDIUM},
{"path": "/v2/user/personalstats", "key": "personalstats", "params": {"cat": "all"}, "cache_for": CACHE_DURATION_MEDIUM},
{"path": "/v2/company", "key": "company", "response_key": "profile", "cache_for": CACHE_DURATION_MEDIUM},
{"path": "/v2/user/skills", "key": "skills", "cache_for": CACHE_DURATION_LONG},
{"path": "/user", "key": "refills", "params": {"selections": "refills"}, "cache_for": CACHE_DURATION_LONG},
{"path": "/torn", "key": "torn_stocks", "params": {"selections": "stocks"}, "cache_for": CACHE_DURATION_MEDIUM},
{"path": "/user", "key": "user_stocks", "params": {"selections": "stocks"}, "cache_for": CACHE_DURATION_MEDIUM},
]
def get_enabled_endpoints(options: dict) -> list[dict]:
"""Get list of enabled endpoints based on options."""
enabled_endpoints = []
for category_key, category_config in ENDPOINT_CATEGORIES.items():
# Core endpoints are always enabled
if category_key == "core":
enabled_endpoints.extend(category_config["endpoints"])
continue
# Check if category is enabled in options (default to enabled_by_default)
is_enabled = options.get(category_key, category_config["enabled_by_default"])
if is_enabled:
enabled_endpoints.extend(category_config["endpoints"])
return enabled_endpoints