nvd commited on
Update main.py
Browse files
main.py
CHANGED
|
@@ -99,33 +99,39 @@ async def handler(event):
|
|
| 99 |
|
| 100 |
@asynccontextmanager
|
| 101 |
async def lifespan(app: FastAPI):
|
| 102 |
-
# Setup Mongo TTL (Auto-delete after 7 days)
|
| 103 |
await messages_collection.create_index("timestamp", expireAfterSeconds=604800)
|
| 104 |
|
| 105 |
-
# Connect Telegram
|
| 106 |
try:
|
| 107 |
print("Connecting to Telegram...")
|
| 108 |
await tg_client.connect()
|
| 109 |
if not await tg_client.is_user_authorized():
|
| 110 |
-
print("❌ TELEGRAM NOT AUTHORIZED!
|
| 111 |
else:
|
| 112 |
print("✅ Telegram Connected!")
|
| 113 |
asyncio.create_task(tg_client.run_until_disconnected())
|
| 114 |
except Exception as e:
|
| 115 |
print(f"❌ Telegram Fail: {e}")
|
| 116 |
|
| 117 |
-
# Rubika Bot
|
| 118 |
if rub_bot:
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
yield
|
|
|
|
| 122 |
# Graceful shutdown
|
| 123 |
await tg_client.disconnect()
|
| 124 |
if rub_bot:
|
|
|
|
|
|
|
| 125 |
await rub_bot.disconnect()
|
| 126 |
|
| 127 |
-
app = FastAPI(lifespan=lifespan)
|
| 128 |
-
|
| 129 |
@app.get("/")
|
| 130 |
async def health():
|
| 131 |
return {"status": "running", "monitoring": TARGET_CHANNELS}
|
|
|
|
| 99 |
|
| 100 |
@asynccontextmanager
|
| 101 |
async def lifespan(app: FastAPI):
|
| 102 |
+
# 1. Setup Mongo TTL (Auto-delete after 7 days)
|
| 103 |
await messages_collection.create_index("timestamp", expireAfterSeconds=604800)
|
| 104 |
|
| 105 |
+
# 2. Connect Telegram
|
| 106 |
try:
|
| 107 |
print("Connecting to Telegram...")
|
| 108 |
await tg_client.connect()
|
| 109 |
if not await tg_client.is_user_authorized():
|
| 110 |
+
print("❌ TELEGRAM NOT AUTHORIZED!")
|
| 111 |
else:
|
| 112 |
print("✅ Telegram Connected!")
|
| 113 |
asyncio.create_task(tg_client.run_until_disconnected())
|
| 114 |
except Exception as e:
|
| 115 |
print(f"❌ Telegram Fail: {e}")
|
| 116 |
|
| 117 |
+
# 3. Connect Rubika Bot (FIXED PART)
|
| 118 |
if rub_bot:
|
| 119 |
+
try:
|
| 120 |
+
print("Connecting to Rubika Bot...")
|
| 121 |
+
await rub_bot.start() # THIS IS THE MISSING LINE
|
| 122 |
+
print("✅ Rubika Bot Connected and Ready!")
|
| 123 |
+
except Exception as e:
|
| 124 |
+
print(f"❌ Rubika Startup Error: {e}")
|
| 125 |
|
| 126 |
yield
|
| 127 |
+
|
| 128 |
# Graceful shutdown
|
| 129 |
await tg_client.disconnect()
|
| 130 |
if rub_bot:
|
| 131 |
+
# rubpy uses disconnect() or close() depending on version
|
| 132 |
+
# disconnect() is usually standard
|
| 133 |
await rub_bot.disconnect()
|
| 134 |
|
|
|
|
|
|
|
| 135 |
@app.get("/")
|
| 136 |
async def health():
|
| 137 |
return {"status": "running", "monitoring": TARGET_CHANNELS}
|