-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (47 loc) · 1.49 KB
/
app.py
File metadata and controls
59 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import logging
import threading
from flask import Flask, jsonify
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Import bot components
from bot.main import setup_bot
from bot.database import init_db
# Flask app for health checks (required by Render)
app = Flask(__name__)
@app.route('/')
def health_check():
return jsonify({
"status": "healthy",
"service": "DegenCred Bot",
"message": "Bot is running successfully"
})
@app.route('/health')
def health():
return jsonify({"status": "ok"})
def run_bot():
"""Run the Telegram bot"""
try:
logger.info("🎯 Starting DegenCred Bot...")
# Initialize database
init_db()
logger.info("✅ Database initialized")
# Setup and run bot
application = setup_bot()
logger.info("✅ Bot setup complete")
# Start polling
application.run_polling(drop_pending_updates=True)
except Exception as e:
logger.error(f"❌ Bot startup failed: {e}")
if __name__ == '__main__':
# Start bot in a separate thread
bot_thread = threading.Thread(target=run_bot, daemon=True)
bot_thread.start()
# Start Flask server (main thread)
logger.info("🌐 Starting Flask health server...")
port = int(os.environ.get('PORT', 10000))
app.run(host='0.0.0.0', port=port, debug=False)