mc5-api-client 1.0.15__py3-none-any.whl → 1.0.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mc5_api_client/__init__.py +107 -2
- mc5_api_client/account.py +352 -0
- mc5_api_client/account_quick.py +246 -0
- mc5_api_client/alerts.py +336 -0
- mc5_api_client/alerts_quick.py +210 -0
- mc5_api_client/cli.py +1 -1
- mc5_api_client/client.py +875 -34
- mc5_api_client/debug.py +259 -0
- mc5_api_client/federation.py +257 -0
- mc5_api_client/federation_quick.py +198 -0
- mc5_api_client/platform.py +109 -0
- mc5_api_client/simple_client.py +563 -19
- mc5_api_client/squad_battle.py +439 -0
- mc5_api_client/squad_battle_quick.py +223 -0
- mc5_api_client/telemetry.py +344 -0
- mc5_api_client/transfer.py +348 -0
- mc5_api_client/transfer_quick.py +280 -0
- {mc5_api_client-1.0.15.dist-info → mc5_api_client-1.0.17.dist-info}/METADATA +581 -7
- mc5_api_client-1.0.17.dist-info/RECORD +28 -0
- mc5_api_client-1.0.15.dist-info/RECORD +0 -15
- {mc5_api_client-1.0.15.dist-info → mc5_api_client-1.0.17.dist-info}/WHEEL +0 -0
- {mc5_api_client-1.0.15.dist-info → mc5_api_client-1.0.17.dist-info}/entry_points.txt +0 -0
- {mc5_api_client-1.0.15.dist-info → mc5_api_client-1.0.17.dist-info}/licenses/LICENSE +0 -0
- {mc5_api_client-1.0.15.dist-info → mc5_api_client-1.0.17.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# ────────────[ CHIZOBA ]────────────────────────────
|
|
3
|
+
# | Email : chizoba2026@hotmail.com
|
|
4
|
+
# | File : alerts_quick.py
|
|
5
|
+
# | License | MIT License © 2026 Chizoba
|
|
6
|
+
# | Brief | Quick functions for real-time alerts
|
|
7
|
+
# ────────────────★─────────────────────────────────
|
|
8
|
+
|
|
9
|
+
from typing import Optional, Dict, Any, List, Callable
|
|
10
|
+
from .simple_client import SimpleMC5Client
|
|
11
|
+
from .telemetry import report_usage
|
|
12
|
+
from .debug import debug_function, debug_print
|
|
13
|
+
|
|
14
|
+
@debug_function
|
|
15
|
+
def quick_start_alert_stream(username: str, password: str,
|
|
16
|
+
webhook_url: Optional[str] = None,
|
|
17
|
+
alert_types: Optional[List[str]] = None,
|
|
18
|
+
callback: Optional[Callable] = None) -> Optional[Dict[str, Any]]:
|
|
19
|
+
"""
|
|
20
|
+
Quick function to start real-time alert streaming.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
username: MC5 username
|
|
24
|
+
password: MC5 password
|
|
25
|
+
webhook_url: Optional Discord webhook URL for alert forwarding
|
|
26
|
+
alert_types: List of alert types to subscribe to
|
|
27
|
+
callback: Optional callback function for handling alerts
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Stream session information or None if failed
|
|
31
|
+
"""
|
|
32
|
+
try:
|
|
33
|
+
with SimpleMC5Client(username, password) as client:
|
|
34
|
+
if client.connect():
|
|
35
|
+
session = client.client.start_alert_stream(
|
|
36
|
+
webhook_url=webhook_url,
|
|
37
|
+
alert_types=alert_types,
|
|
38
|
+
callback=callback
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
debug_print(f"✅ Alert stream started on {session.get('server')}", "success")
|
|
42
|
+
return session
|
|
43
|
+
return None
|
|
44
|
+
except Exception as e:
|
|
45
|
+
debug_print(f"❌ Failed to start alert stream: {e}", "error")
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
@debug_function
|
|
49
|
+
def quick_test_alert_connection(username: str, password: str) -> Optional[Dict[str, Any]]:
|
|
50
|
+
"""
|
|
51
|
+
Quick function to test alert server connections.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
username: MC5 username
|
|
55
|
+
password: MC5 password
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Connection test results or None if failed
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
with SimpleMC5Client(username, password) as client:
|
|
62
|
+
if client.connect():
|
|
63
|
+
results = client.client.test_alert_connection()
|
|
64
|
+
|
|
65
|
+
connected_count = results.get('connected_count', 0)
|
|
66
|
+
total_tested = results.get('total_tested', 0)
|
|
67
|
+
|
|
68
|
+
debug_print(f"✅ Alert connection test: {connected_count}/{total_tested} servers connected", "success")
|
|
69
|
+
|
|
70
|
+
best_server = results.get('best_server')
|
|
71
|
+
if best_server and best_server.get('connected'):
|
|
72
|
+
debug_print(f"🎯 Best server: {best_server.get('server')} ({best_server.get('response_time', 0):.2f}s)", "info")
|
|
73
|
+
|
|
74
|
+
return results
|
|
75
|
+
return None
|
|
76
|
+
except Exception as e:
|
|
77
|
+
debug_print(f"❌ Failed to test alert connection: {e}", "error")
|
|
78
|
+
return None
|
|
79
|
+
|
|
80
|
+
@debug_function
|
|
81
|
+
def quick_start_alerts_with_discord(username: str, password: str,
|
|
82
|
+
discord_webhook: str,
|
|
83
|
+
alert_types: Optional[List[str]] = None) -> Optional[Dict[str, Any]]:
|
|
84
|
+
"""
|
|
85
|
+
Quick function to start alerts with Discord webhook forwarding.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
username: MC5 username
|
|
89
|
+
password: MC5 password
|
|
90
|
+
discord_webhook: Discord webhook URL for alert forwarding
|
|
91
|
+
alert_types: List of alert types to subscribe to
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
Stream session information or None if failed
|
|
95
|
+
"""
|
|
96
|
+
try:
|
|
97
|
+
# Default alert types if not provided
|
|
98
|
+
if alert_types is None:
|
|
99
|
+
alert_types = ["connection", "message", "connection_request", "connection_request_accepted"]
|
|
100
|
+
|
|
101
|
+
debug_print(f"🔔 Starting alerts with Discord forwarding", "info")
|
|
102
|
+
debug_print(f"📋 Alert types: {', '.join(alert_types)}", "info")
|
|
103
|
+
debug_print(f"🔗 Webhook: {discord_webhook[:50]}...", "info")
|
|
104
|
+
|
|
105
|
+
return quick_start_alert_stream(
|
|
106
|
+
username=username,
|
|
107
|
+
password=password,
|
|
108
|
+
webhook_url=discord_webhook,
|
|
109
|
+
alert_types=alert_types
|
|
110
|
+
)
|
|
111
|
+
except Exception as e:
|
|
112
|
+
debug_print(f"❌ Failed to start alerts with Discord: {e}", "error")
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
def create_alert_callback(print_alerts: bool = True, save_to_file: Optional[str] = None) -> Callable:
|
|
116
|
+
"""
|
|
117
|
+
Create a callback function for handling alerts.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
print_alerts: Whether to print alerts to console
|
|
121
|
+
save_to_file: Optional file path to save alerts
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Callback function
|
|
125
|
+
"""
|
|
126
|
+
def alert_callback(alert_data: Dict[str, Any]):
|
|
127
|
+
"""Handle incoming alert data."""
|
|
128
|
+
try:
|
|
129
|
+
alert_type = alert_data.get('type', 'unknown')
|
|
130
|
+
timestamp = alert_data.get('timestamp', 0)
|
|
131
|
+
|
|
132
|
+
# Format timestamp
|
|
133
|
+
import time
|
|
134
|
+
formatted_time = time.strftime("%H:%M:%S", time.localtime(timestamp))
|
|
135
|
+
|
|
136
|
+
# Print alert if requested
|
|
137
|
+
if print_alerts:
|
|
138
|
+
debug_print(f"🔔 [{formatted_time}] {alert_type.upper()}", "info")
|
|
139
|
+
|
|
140
|
+
# Print additional data if available
|
|
141
|
+
alert_info = alert_data.get('data', {})
|
|
142
|
+
if alert_info:
|
|
143
|
+
for key, value in list(alert_info.items())[:3]: # Show first 3 items
|
|
144
|
+
debug_print(f" {key}: {value}", "info")
|
|
145
|
+
|
|
146
|
+
# Save to file if requested
|
|
147
|
+
if save_to_file:
|
|
148
|
+
import json
|
|
149
|
+
with open(save_to_file, 'a', encoding='utf-8') as f:
|
|
150
|
+
f.write(json.dumps({
|
|
151
|
+
'timestamp': timestamp,
|
|
152
|
+
'type': alert_type,
|
|
153
|
+
'data': alert_data
|
|
154
|
+
}) + '\n')
|
|
155
|
+
|
|
156
|
+
except Exception as e:
|
|
157
|
+
debug_print(f"❌ Error in alert callback: {e}", "error")
|
|
158
|
+
|
|
159
|
+
return alert_callback
|
|
160
|
+
|
|
161
|
+
@debug_function
|
|
162
|
+
def quick_monitor_alerts(username: str, password: str,
|
|
163
|
+
duration: int = 60,
|
|
164
|
+
discord_webhook: Optional[str] = None,
|
|
165
|
+
save_file: Optional[str] = None) -> int:
|
|
166
|
+
"""
|
|
167
|
+
Quick function to monitor alerts for a specific duration.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
username: MC5 username
|
|
171
|
+
password: MC5 password
|
|
172
|
+
duration: Duration in seconds to monitor
|
|
173
|
+
discord_webhook: Optional Discord webhook URL
|
|
174
|
+
save_file: Optional file to save alerts
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
Number of alerts received
|
|
178
|
+
"""
|
|
179
|
+
try:
|
|
180
|
+
import time
|
|
181
|
+
|
|
182
|
+
# Create callback
|
|
183
|
+
callback = create_alert_callback(print_alerts=True, save_to_file=save_file)
|
|
184
|
+
|
|
185
|
+
# Start alert stream
|
|
186
|
+
session = quick_start_alert_stream(
|
|
187
|
+
username=username,
|
|
188
|
+
password=password,
|
|
189
|
+
webhook_url=discord_webhook,
|
|
190
|
+
alert_types=["connection", "message", "connection_request", "connection_request_accepted"],
|
|
191
|
+
callback=callback
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
if not session:
|
|
195
|
+
return 0
|
|
196
|
+
|
|
197
|
+
debug_print(f"⏰ Monitoring alerts for {duration} seconds...", "info")
|
|
198
|
+
|
|
199
|
+
# Monitor for specified duration
|
|
200
|
+
time.sleep(duration)
|
|
201
|
+
|
|
202
|
+
debug_print(f"⏹️ Alert monitoring completed", "info")
|
|
203
|
+
|
|
204
|
+
# Note: In a real implementation, you'd want to track alert count
|
|
205
|
+
# For now, return a placeholder
|
|
206
|
+
return 0
|
|
207
|
+
|
|
208
|
+
except Exception as e:
|
|
209
|
+
debug_print(f"❌ Failed to monitor alerts: {e}", "error")
|
|
210
|
+
return 0
|
mc5_api_client/cli.py
CHANGED
|
@@ -447,7 +447,7 @@ class MC5CLI:
|
|
|
447
447
|
|
|
448
448
|
def _print_version(self):
|
|
449
449
|
"""Print version information."""
|
|
450
|
-
self._print("MC5 API Client v1.0.
|
|
450
|
+
self._print("MC5 API Client v1.0.16", "cyan")
|
|
451
451
|
self._print("The ultimate Modern Combat 5 API library", "green")
|
|
452
452
|
self._print("Author: Chizoba", "blue")
|
|
453
453
|
self._print("Email: chizoba2026@hotmail.com", "blue")
|