nexus3rd commited on
Commit
9a8fec6
·
1 Parent(s): 0fffae5
Files changed (1) hide show
  1. bot.py +10 -6
bot.py CHANGED
@@ -36,7 +36,6 @@ user_api_keys = {}
36
  def fetch_ngrok_data(user_id):
37
  api_key = user_api_keys.get(user_id, default_api_key)
38
  if not api_key:
39
- # Return explicit error instead of raising
40
  return None, "Ngrok API key not found. Please set your Ngrok API key."
41
  headers = {
42
  "Authorization": f"Bearer {api_key}",
@@ -50,12 +49,17 @@ def fetch_ngrok_data(user_id):
50
  return response.json().get("tunnels", []), None
51
  except requests.RequestException as e:
52
  return None, f"Error fetching Ngrok data: {str(e)}"
53
-
54
  def get_ngrok_tunnels(user_id):
55
- tunnels = fetch_ngrok_data(user_id)
56
- endpoints = [tunnel.get("public_url", "").replace("tcp://", "")
57
- for tunnel in tunnels if tunnel.get("proto") == "tcp"]
58
- return endpoints
 
 
 
 
 
59
 
60
  def get_ngrok_runtime(user_id):
61
  tunnels, error = fetch_ngrok_data(user_id)
 
36
  def fetch_ngrok_data(user_id):
37
  api_key = user_api_keys.get(user_id, default_api_key)
38
  if not api_key:
 
39
  return None, "Ngrok API key not found. Please set your Ngrok API key."
40
  headers = {
41
  "Authorization": f"Bearer {api_key}",
 
49
  return response.json().get("tunnels", []), None
50
  except requests.RequestException as e:
51
  return None, f"Error fetching Ngrok data: {str(e)}"
52
+
53
  def get_ngrok_tunnels(user_id):
54
+ tunnels, error = fetch_ngrok_data(user_id)
55
+ if error:
56
+ return [error]
57
+ endpoints = [
58
+ tunnel.get("public_url", "").replace("tcp://", "")
59
+ for tunnel in tunnels if tunnel.get("proto") == "tcp"
60
+ ]
61
+ return endpoints if endpoints else ["No TCP endpoints available."]
62
+
63
 
64
  def get_ngrok_runtime(user_id):
65
  tunnels, error = fetch_ngrok_data(user_id)