diff --git a/bot.py b/bot.py index f25f5f6..311498e 100644 --- a/bot.py +++ b/bot.py @@ -1,5 +1,3 @@ -#import datetime -#import pytz from telegram.ext import Application from telegram.ext import CommandHandler from telegram.ext import MessageHandler @@ -45,7 +43,8 @@ async def bot_start(update, context): await update.message.reply_text('Ho creato il mondo di gioco', reply_markup=reply_markup) context.application.bot_data['arena'] = Arena -async def start_loop_game(update, context): +async def start_loop_game(update, context, seconds): + await update.message.reply_text(f'Ok capo!! giochero\' per te ogni {seconds}secondi') chat_id = update.effective_chat.id if 'arena' not in context.application.bot_data: print(f'{chat_id}: Arena non trovata') @@ -58,14 +57,7 @@ async def start_loop_game(update, context): 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=86400, first=1, chat_id= chat_id) - #timezone = pytz.timezone('Europe/Rome') - #context.job_queue.run_daily( - #loop_game, - #time=datetime.time(hour=23, minute=40, second=0, tzinfo= timezone), - #chat_id=chat_id, - #name=str(chat_id) - #) + context.job_queue.run_repeating(loop_game, interval= seconds, first=1, chat_id= chat_id) print(f'Job giornaliero creato per la chat {chat_id}') async def bot_commands(update, context): @@ -79,7 +71,9 @@ async def bot_commands(update, context): if text == 'Add Player': print(f'bot_command: {chat_id} Add Player') context.application.bot_data['ask_name'] = 1 - return + if 'ask_seconds' in context.application.bot_data: + del(context.application.bot_data['ask_seconds']) + return await update.message.reply_text('Inserisci il Nome del giocatore') if text == 'Get Players': print(f'bot_command: {chat_id} Get Players') return await _bot_player.get_players(update, context) @@ -94,9 +88,19 @@ async def bot_commands(update, context): return await simulate_day(context, chat_id) if text == 'Run Periodically': print(f'bot_command: {chat_id} Run Periodically') - return await update.message.reply_text(_botsyms.WIP_MSG) + context.application.bot_data['ask_seconds'] = 1 + if 'ask_name' in context.application.bot_data: + del(context.application.bot_data['ask_name']) + return await update.message.reply_text('Inserisci il numero di secondi, ad esempio \n(60 = 1 minuto)(600 = 10 minuti)\n(3600 = 1 ora)\n(86400 = 1 giorno)') #return await simulate_day(context, chat_id) + waiting_for_seconds= context.application.bot_data.get('ask_seconds') + if waiting_for_seconds: + print(f'bot_command: {chat_id} User Wants to auto-run the game every {text} seconds') + try: text= int(text) + except: return + seconds= max(1, text) + return await start_loop_game(update, context, seconds) waiting_for_name= context.application.bot_data.get('ask_name') if waiting_for_name: print(f'bot_command: {chat_id} Collected Player Name {text}') diff --git a/requirements/requirements.txt b/requirements/requirements.txt index ccc6d4e..d8fe6b9 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,2 +1 @@ python-telegram-bot[job-queue]==22.3 -pytz==2025.2