split main bot lib into multiple smaller libs and improve end game message

This commit is contained in:
andrea
2025-07-26 14:44:16 +02:00
parent 415cdfc123
commit 67804a394d
4 changed files with 72 additions and 55 deletions

23
bot_libs/repeating.py Normal file
View File

@@ -0,0 +1,23 @@
from bot_libs import simulation as _bot_sim
async def _loop_game(context):
chat_id = context.job.chat_id
print(f'_loop_game: run on {chat_id}')
return await _bot_sim.simulate_day(context, chat_id)
async def start_loop_game(update, context, seconds):
await update.message.reply_text(f'Ok capo!! giochero\' per te ogni {seconds}s')
chat_id = update.effective_chat.id
if 'arena' not in context.application.bot_data:
print(f'start_loop_game: {chat_id} Arena not found')
await update.message.reply_text(f'Arena non trovata, avviare con /start')
return
Arena= context.application.bot_data['arena']
if len(Arena.get_players()) < 2:
print(f'start_loop_game: {chat_id} Not enough player to start the match')
await update.message.reply_text(f'Servono almeno 2 giocatori. Ecco i giocatori presenti nel mondo do gioco: \n{Arena.get_players()}')
return
context.job_queue.run_repeating(_loop_game, interval= seconds, first=1, chat_id= chat_id)
print(f'start_loop_game: Repeating Job created for: {chat_id}')