File size: 1,287 Bytes
a527a94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from telegram.ext import Application, CommandHandler
from threading import Thread
import schedule
import time

# Função de exemplo para o comando /start
async def start(update, context):
    await update.message.reply_text('Hello! I am Hypercycle Bot.')

# Função para tarefas agendadas
def scheduled_task():
    print("Running scheduled task...")  # Substitua por sua lógica

# Função principal do bot
def main():
    # Obtém o token do Telegram das variáveis de ambiente
    TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN')
    if not TELEGRAM_TOKEN:
        raise ValueError("TELEGRAM_TOKEN not set in environment variables")

    # Configura o bot
    application = Application.builder().token(TELEGRAM_TOKEN).build()

    # Adiciona handlers de comandos
    application.add_handler(CommandHandler("start", start))

    # Inicia o bot
    print("Bot is starting...")
    application.run_polling()

# Função para rodar o agendador em uma thread separada
def run_scheduler():
    schedule.every(10).seconds.do(scheduled_task)  # Exemplo: tarefa a cada 10s
    while True:
        schedule.run_pending()
        time.sleep(1)

if __name__ == '__main__':
    # Inicia o agendador em uma thread
    Thread(target=run_scheduler).start()

    # Inicia o bot
    main()