feat(bot): add operating hours window configuration and enforcement
Adds HORA_INICIO and HORA_FIM environment variables to define the daily operating window for order sending. Implements dentro_do_horario() function to validate if current time falls within the configured range. The bot now pauses order sending outside the operating window and sends a notification to the chat, resuming automatically at HORA_INICIO. Includes DEPLOY.md documentation with Debian 12 deployment instructions and systemd service configuration for auto-start and auto-restart.
This commit is contained in:
@@ -24,6 +24,13 @@ SEXO = os.getenv("SEXO", "masculino").strip().lower()
|
||||
IDADE = int(os.getenv("IDADE", "30"))
|
||||
INTERVALO = int(os.getenv("INTERVALO_MINUTOS", "5"))
|
||||
|
||||
HORA_INICIO = os.getenv("HORA_INICIO", "00:00").strip()
|
||||
HORA_FIM = os.getenv("HORA_FIM", "23:59").strip()
|
||||
|
||||
def dentro_do_horario() -> bool:
|
||||
agora = datetime.now().strftime("%H:%M")
|
||||
return HORA_INICIO <= agora <= HORA_FIM
|
||||
|
||||
ORDENS_PATH = os.path.join(os.path.dirname(__file__), "ordens.json")
|
||||
|
||||
# ─── Substituições para sexo feminino ──────────────────────────────────────────
|
||||
@@ -108,10 +115,25 @@ async def loop_principal():
|
||||
bot = Bot(token=TOKEN)
|
||||
|
||||
await cmd_start(ordens)
|
||||
|
||||
agora = datetime.now().strftime("%H:%M")
|
||||
if not dentro_do_horario():
|
||||
log.info("Horário atual %s fora da janela %s-%s. Aguardando...", agora, HORA_INICIO, HORA_FIM)
|
||||
await bot.send_message(
|
||||
chat_id=CHAT_ID,
|
||||
text=f"Horário atual ({agora}) fora da janela de ordens ({HORA_INICIO}-{HORA_FIM}).\n"
|
||||
f"As ordens serão retomadas automaticamente às {HORA_INICIO}."
|
||||
)
|
||||
|
||||
await asyncio.sleep(INTERVALO * 60)
|
||||
|
||||
ordem_index = 0
|
||||
while True:
|
||||
if not dentro_do_horario():
|
||||
log.info("Fora do horário de funcionamento (%s-%s). Aguardando...", HORA_INICIO, HORA_FIM)
|
||||
await asyncio.sleep(60)
|
||||
continue
|
||||
|
||||
ordem = ordens[ordem_index % len(ordens)]
|
||||
ordem_adaptada = adaptar_ordem(ordem)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user