shashwatIDR commited on
Commit
aabefe6
·
verified ·
1 Parent(s): 0ba95d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -2,6 +2,7 @@ import requests
2
  import time
3
  import threading
4
  from flask import Flask
 
5
 
6
  # ==== CONFIG ====
7
  BOT_TOKEN = "7316836080:AAEv7wRHNmgCb707ppG6rpTV0mhEBC4n26A"
@@ -43,21 +44,26 @@ def send_telegram_message(text):
43
  except Exception as e:
44
  print(f"[ERROR] Failed to send message: {e}")
45
 
 
 
 
 
 
 
 
 
 
 
 
46
  def monitor_status():
47
  """Background thread to monitor Uma health status."""
48
  global last_health, current_status_text
49
- first_run = True
50
-
51
  while True:
52
  health = get_health_status()
53
  if health:
54
  msg = STATUS_MESSAGES.get(health, f"Unknown status: {health}")
55
  current_status_text = msg
56
 
57
- if first_run:
58
- send_telegram_message(f"Hi from Stato\nCurrent Uma status:\n{msg}")
59
- first_run = False
60
-
61
  if health != last_health:
62
  send_telegram_message(msg)
63
  print(f"[UPDATE] Uma status changed to: {health} - {msg}")
@@ -70,5 +76,6 @@ def home():
70
  return current_status_text
71
 
72
  if __name__ == "__main__":
 
73
  threading.Thread(target=monitor_status, daemon=True).start()
74
  app.run(host="0.0.0.0", port=7860)
 
2
  import time
3
  import threading
4
  from flask import Flask
5
+ from datetime import datetime
6
 
7
  # ==== CONFIG ====
8
  BOT_TOKEN = "7316836080:AAEv7wRHNmgCb707ppG6rpTV0mhEBC4n26A"
 
44
  except Exception as e:
45
  print(f"[ERROR] Failed to send message: {e}")
46
 
47
+ def send_startup_message():
48
+ """Send bot startup message with current status."""
49
+ health = get_health_status()
50
+ if health:
51
+ msg = STATUS_MESSAGES.get(health, f"Unknown status: {health}")
52
+ else:
53
+ msg = "Unable to fetch Uma status at startup."
54
+
55
+ start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
56
+ send_telegram_message(f"🔔 Bot started at {start_time}\nCurrent Uma status:\n{msg}")
57
+
58
  def monitor_status():
59
  """Background thread to monitor Uma health status."""
60
  global last_health, current_status_text
 
 
61
  while True:
62
  health = get_health_status()
63
  if health:
64
  msg = STATUS_MESSAGES.get(health, f"Unknown status: {health}")
65
  current_status_text = msg
66
 
 
 
 
 
67
  if health != last_health:
68
  send_telegram_message(msg)
69
  print(f"[UPDATE] Uma status changed to: {health} - {msg}")
 
76
  return current_status_text
77
 
78
  if __name__ == "__main__":
79
+ send_startup_message() # Send startup message no matter what
80
  threading.Thread(target=monitor_status, daemon=True).start()
81
  app.run(host="0.0.0.0", port=7860)