2025-07-26 20:58:35 +02:00
from utils import logs as _log
2025-07-28 22:29:27 +02:00
from bot_libs import syms as _bot_syms
2025-07-26 20:58:35 +02:00
from bot_libs import player_handling as _bot_player
from bot_libs import simulation as _bot_simulation
from bot_libs import repeating as _bot_repeat
### parse user input
2025-07-27 08:17:12 +02:00
async def _cmd_list_of_players ( context , update , chat_id ) :
2025-07-26 20:58:35 +02:00
Arena = context . application . bot_data [ ' arena ' ]
players = [ p . get_name_and_stats ( ) for p in Arena . get_players ( ) ]
players_str = ' \n ' . join ( players )
return await update . message . reply_text ( f ' Ecco i { len ( players ) } giocatori presenti nel mondo do gioco: \n { players_str } ' )
2025-07-27 08:17:12 +02:00
async def cmd_get_player_name ( context , update , chat_id , text ) :
_log . log_info ( f ' cmd_get_player_name: { chat_id } - Collected Player Name { text } ' )
if not ' ask_name ' in context . application . bot_data : return
del ( context . application . bot_data [ ' ask_name ' ] )
players = text . split ( ' , ' )
for player in players :
await _bot_player . add_player ( update , context , chat_id , player . strip ( ) )
return await _cmd_list_of_players ( context , update , chat_id )
async def cmd_get_cron_time ( context , update , chat_id , text ) :
_log . log_info ( f ' cmd_get_cron_time: { chat_id } - User Wants to auto-run the game every { text } seconds ' )
2025-07-26 20:58:35 +02:00
try : text = int ( text )
except : return
seconds = max ( 1 , text )
2025-07-26 22:41:24 +02:00
if ' ask_seconds ' in context . application . bot_data :
del ( context . application . bot_data [ ' ask_seconds ' ] )
2025-07-26 20:58:35 +02:00
return await _bot_repeat . start_loop_game ( update , context , seconds )
### basic commands handling
2025-07-27 08:17:12 +02:00
async def cmd_add_random_players ( context , update , chat_id ) :
await _bot_player . add_random_players ( update , context , chat_id , colors_names = False )
return await _cmd_list_of_players ( context , update , chat_id )
async def cmd_add_random_color_players ( context , update , chat_id ) :
await _bot_player . add_random_players ( update , context , chat_id , colors_names = True )
return await _cmd_list_of_players ( context , update , chat_id )
async def cmd_add_player ( context , update , chat_id ) :
2025-07-26 20:58:35 +02:00
context . application . bot_data [ ' ask_name ' ] = 1
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 (o piu \' nomi separati da virgola) ' )
2025-07-27 08:17:12 +02:00
async def cmd_get_players ( context , update , chat_id ) :
2025-07-26 21:25:38 +02:00
return await _bot_player . get_players ( update , context , chat_id )
2025-07-26 20:58:35 +02:00
2025-07-27 08:17:12 +02:00
async def cmd_get_alive_players ( context , update , chat_id ) :
2025-07-26 21:25:38 +02:00
return await _bot_player . get_alive_players ( update , context , chat_id )
2025-07-26 20:58:35 +02:00
2025-07-27 08:17:12 +02:00
async def cmd_get_death_players ( context , update , chat_id ) :
2025-07-26 21:25:38 +02:00
return await _bot_player . get_death_players ( update , context , chat_id )
2025-07-26 20:58:35 +02:00
2025-07-27 08:17:12 +02:00
async def cmd_get_ranking_players ( context , update , chat_id ) :
2025-07-26 21:25:38 +02:00
return await _bot_player . get_ranking_players ( update , context , chat_id )
2025-07-26 20:58:35 +02:00
2025-07-27 08:17:12 +02:00
async def cmd_simulate_day ( context , update , chat_id ) :
2025-07-26 20:58:35 +02:00
return await _bot_simulation . simulate_day ( context , chat_id )
2025-07-28 22:29:27 +02:00
async def cmd_show_game_map_unicode ( context , update , chat_id ) :
2025-07-28 20:45:42 +02:00
Arena = context . application . bot_data [ ' arena ' ]
Gamemap = Arena . get_map ( )
rendered_map = Gamemap . get_renderized_map ( )
2025-07-28 22:29:27 +02:00
await update . message . reply_text ( rendered_map )
return await update . message . reply_text ( _bot_syms . MAP_UTF8_LEGEND , parse_mode = ' MarkdownV2 ' )
async def cmd_show_game_map_image ( context , update , chat_id ) :
Arena = context . application . bot_data [ ' arena ' ]
Gamemap = Arena . get_map ( )
image_map = Gamemap . get_image_map ( )
bot = update . get_bot ( )
await bot . send_photo ( chat_id = chat_id , photo = image_map )
return await update . message . reply_text ( _bot_syms . MAP_IMAGE_LEGEND , parse_mode = ' MarkdownV2 ' )
2025-07-28 20:45:42 +02:00
2025-07-27 08:17:12 +02:00
async def cmd_simulate_day_cron ( context , update , chat_id ) :
2025-07-26 20:58:35 +02:00
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) ' )