|
import os |
|
import telegram |
|
from telegram.ext import Application, CommandHandler |
|
from flask import Flask |
|
from threading import Thread |
|
import schedule |
|
import time |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
@app.route('/') |
|
def home(): |
|
return "Hypercycle Bot is running!" |
|
|
|
|
|
def run_flask(): |
|
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 5000))) |
|
|
|
|
|
async def start(update, context): |
|
await update.message.reply_text('Hello! I am Hypercycle Bot.') |
|
|
|
|
|
def scheduled_task(): |
|
print("Running scheduled task...") |
|
|
|
|
|
def main(): |
|
|
|
TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN') |
|
if not TELEGRAM_TOKEN: |
|
raise ValueError("TELEGRAM_TOKEN not set in environment variables") |
|
|
|
|
|
application = Application.builder().token(TELEGRAM_TOKEN).build() |
|
|
|
|
|
application.add_handler(CommandHandler("start", start)) |
|
|
|
|
|
print("Bot is starting...") |
|
application.run_polling() |
|
|
|
|
|
def run_scheduler(): |
|
schedule.every(10).seconds.do(scheduled_task) |
|
while True: |
|
schedule.run_pending() |
|
time.sleep(1) |
|
|
|
if __name__ == '__main__': |
|
|
|
Thread(target=run_flask).start() |
|
|
|
|
|
Thread(target=run_scheduler).start() |
|
|
|
|
|
main() |