|
import os |
|
from telegram.ext import Application, CommandHandler |
|
from threading import Thread |
|
import schedule |
|
import time |
|
|
|
|
|
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_scheduler).start() |
|
|
|
|
|
main() |