RXTIME commited on
Commit
6567f77
·
verified ·
1 Parent(s): 737478a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from telegram.ext import Application, CommandHandler
3
+ from threading import Thread
4
+ import schedule
5
+ import time
6
+
7
+ # Função de exemplo para o comando /start
8
+ async def start(update, context):
9
+ await update.message.reply_text('Hello! I am Hypercycle Bot.')
10
+
11
+ # Função para tarefas agendadas
12
+ def scheduled_task():
13
+ print("Running scheduled task...") # Substitua por sua lógica
14
+
15
+ # Função principal do bot
16
+ def main():
17
+ # Obtém o token do Telegram das variáveis de ambiente
18
+ TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN')
19
+ if not TELEGRAM_TOKEN:
20
+ raise ValueError("TELEGRAM_TOKEN not set in environment variables")
21
+
22
+ # Configura o bot
23
+ application = Application.builder().token(TELEGRAM_TOKEN).build()
24
+
25
+ # Adiciona handlers de comandos
26
+ application.add_handler(CommandHandler("start", start))
27
+
28
+ # Inicia o bot
29
+ print("Bot is starting...")
30
+ application.run_polling()
31
+
32
+ # Função para rodar o agendador em uma thread separada
33
+ def run_scheduler():
34
+ schedule.every(10).seconds.do(scheduled_task) # Exemplo: tarefa a cada 10s
35
+ while True:
36
+ schedule.run_pending()
37
+ time.sleep(1)
38
+
39
+ if __name__ == '__main__':
40
+ # Inicia o agendador em uma thread
41
+ Thread(target=run_scheduler).start()
42
+
43
+ # Inicia o bot
44
+ main()