Fix traffic data
This commit is contained in:
@ -90,7 +90,8 @@ def process_show_user(message):
|
|||||||
username = message.text.strip()
|
username = message.text.strip()
|
||||||
command = f"python3 {CLI_PATH} get-user -u {username}"
|
command = f"python3 {CLI_PATH} get-user -u {username}"
|
||||||
user_result = run_cli_command(command)
|
user_result = run_cli_command(command)
|
||||||
user_json_match = re.search(r'(\{.*?\})\n(\{.*?\})', user_result, re.DOTALL)
|
|
||||||
|
user_json_match = re.search(r'(\{.*?\})\n?(\{.*?\})?', user_result, re.DOTALL)
|
||||||
|
|
||||||
if not user_json_match:
|
if not user_json_match:
|
||||||
bot.reply_to(message, "Failed to parse user details. The command output format may be incorrect.")
|
bot.reply_to(message, "Failed to parse user details. The command output format may be incorrect.")
|
||||||
@ -101,13 +102,17 @@ def process_show_user(message):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
user_details = json.loads(user_json)
|
user_details = json.loads(user_json)
|
||||||
traffic_data = json.loads(traffic_data_section)
|
|
||||||
traffic_message = (
|
if traffic_data_section:
|
||||||
f"**Traffic Data:**\n"
|
traffic_data = json.loads(traffic_data_section)
|
||||||
f"Upload: {traffic_data.get('upload_bytes', 0) / (1024 ** 2):.2f} MB\n"
|
traffic_message = (
|
||||||
f"Download: {traffic_data.get('download_bytes', 0) / (1024 ** 2):.2f} MB\n"
|
f"**Traffic Data:**\n"
|
||||||
f"Status: {traffic_data.get('status', 'Unknown')}"
|
f"Upload: {traffic_data.get('upload_bytes', 0) / (1024 ** 2):.2f} MB\n"
|
||||||
)
|
f"Download: {traffic_data.get('download_bytes', 0) / (1024 ** 2):.2f} MB\n"
|
||||||
|
f"Status: {traffic_data.get('status', 'Unknown')}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
traffic_message = "**Traffic Data:**\nNo traffic data available. The user might not have connected yet."
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
bot.reply_to(message, "Failed to parse JSON data. The command output may be malformed.")
|
bot.reply_to(message, "Failed to parse JSON data. The command output may be malformed.")
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user