forked from Cryz/battle_royale_sim
explicit logs
This commit is contained in:
@@ -6,18 +6,18 @@ from bot_libs import repeating as _bot_repeat
|
||||
### parse user input
|
||||
|
||||
async def get_name_from_input(context, update, chat_id, text):
|
||||
_log.log_info(f'bot_command: {chat_id} Collected Player Name {text}')
|
||||
_log.log_info(f'bot_command: {chat_id} - Collected Player Name {text}')
|
||||
if 'ask_name' in context.application.bot_data:
|
||||
del(context.application.bot_data['ask_name'])
|
||||
players= text.split(',')
|
||||
for player in players:
|
||||
await _bot_player.add_player(update, context, player.strip())
|
||||
await _bot_player.add_player(update, context, chat_id, player.strip())
|
||||
|
||||
elif text == 'Add random Players':
|
||||
await _bot_player.add_random_players(update, context, colors_names= False)
|
||||
await _bot_player.add_random_players(update, context, chat_id, colors_names= False)
|
||||
|
||||
elif text == 'Add random color Players':
|
||||
await _bot_player.add_random_players(update, context, colors_names= True)
|
||||
await _bot_player.add_random_players(update, context, chat_id, colors_names= True)
|
||||
|
||||
Arena= context.application.bot_data['arena']
|
||||
players= [p.get_name_and_stats() for p in Arena.get_players()]
|
||||
@@ -25,7 +25,7 @@ async def get_name_from_input(context, update, chat_id, text):
|
||||
return await update.message.reply_text(f'Ecco i {len(players)} giocatori presenti nel mondo do gioco: \n{players_str}')
|
||||
|
||||
async def get_seconds_from_input(context, update, chat_id, text):
|
||||
_log.log_info(f'bot_command: {chat_id} User Wants to auto-run the game every {text} seconds')
|
||||
_log.log_info(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)
|
||||
@@ -34,34 +34,27 @@ async def get_seconds_from_input(context, update, chat_id, text):
|
||||
### basic commands handling
|
||||
|
||||
async def bot_command_add_player(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Add Player')
|
||||
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)')
|
||||
|
||||
async def bot_command_get_players(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Get Players')
|
||||
return await _bot_player.get_players(update, context)
|
||||
return await _bot_player.get_players(update, context, chat_id)
|
||||
|
||||
async def bot_command_get_alive_players(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Get Alive Players')
|
||||
return await _bot_player.get_alive_players(update, context)
|
||||
return await _bot_player.get_alive_players(update, context, chat_id)
|
||||
|
||||
async def bot_command_get_death_players(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Get Death Players')
|
||||
return await _bot_player.get_death_players(update, context)
|
||||
return await _bot_player.get_death_players(update, context, chat_id)
|
||||
|
||||
async def bot_command_get_ranking_players(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Get Ranking Players')
|
||||
return await _bot_player.get_ranking_players(update, context)
|
||||
return await _bot_player.get_ranking_players(update, context, chat_id)
|
||||
|
||||
async def bot_command_simulate_day(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Simulate Day')
|
||||
return await _bot_simulation.simulate_day(context, chat_id)
|
||||
|
||||
async def bot_command_simulate_day_cron(context, update, chat_id):
|
||||
_log.log_info(f'bot_command: {chat_id} Run Periodically')
|
||||
context.application.bot_data['ask_seconds'] = 1
|
||||
if 'ask_name' in context.application.bot_data:
|
||||
del(context.application.bot_data['ask_name'])
|
||||
|
||||
@@ -2,12 +2,13 @@ import random as _rand
|
||||
from utils import logs as _log
|
||||
from bot_libs import syms as _bot_syms
|
||||
|
||||
async def add_player(update, context, name):
|
||||
_log.log_info(f'add_player: {name}')
|
||||
async def add_player(update, context, chat_id, name):
|
||||
_log.log_info(f'add_player: {chat_id} - {name}')
|
||||
Arena= context.application.bot_data['arena']
|
||||
if len(Arena.get_players()) >= 70: return # prevent message too long error
|
||||
Arena.add_player(name)
|
||||
|
||||
async def add_random_players(update, context, colors_names= False):
|
||||
async def add_random_players(update, context, chat_id, colors_names= False):
|
||||
if colors_names: names= _bot_syms.COLORS_NAMES
|
||||
else: names= _bot_syms.RANDOM_NAMES
|
||||
|
||||
@@ -17,34 +18,34 @@ async def add_random_players(update, context, colors_names= False):
|
||||
players_num= _rand.randint(min_players, max_players)
|
||||
_rand.shuffle(names)
|
||||
lucky_players= _rand.sample(names, players_num)
|
||||
_log.log_info(f'add_random_players: extracting {players_num} random players for the game')
|
||||
for name in lucky_players: await add_player(update, context, name)
|
||||
_log.log_info(f'add_random_players: {chat_id} - extracting {players_num} random players for the game')
|
||||
for name in lucky_players: await add_player(update, context, chat_id, name)
|
||||
|
||||
async def get_players(update, context):
|
||||
async def get_players(update, context, chat_id):
|
||||
Arena= context.application.bot_data['arena']
|
||||
players= [p.get_name_and_stats() for p in Arena.get_players()]
|
||||
players_str= '\n'.join(players)
|
||||
_log.log_info(f'get_players: {players_str}')
|
||||
_log.log_info(f'get_players: {chat_id} - {players_str}')
|
||||
await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{players_str}')
|
||||
|
||||
async def get_alive_players(update, context):
|
||||
async def get_alive_players(update, context, chat_id):
|
||||
Arena= context.application.bot_data['arena']
|
||||
alive= [a.get_name_and_stats() for a in Arena.get_alive_players()]
|
||||
alive_str= '\n'.join(alive)
|
||||
_log.log_info(f'get_alive_players: {alive_str}')
|
||||
_log.log_info(f'get_alive_players: {chat_id} - {alive_str}')
|
||||
await update.message.reply_text(f'Ecco i giocatori ancora vivi: \n{alive_str}')
|
||||
|
||||
async def get_death_players(update, context):
|
||||
async def get_death_players(update, context, chat_id):
|
||||
Arena= context.application.bot_data['arena']
|
||||
death= [d.get_name_and_stats() for d in Arena.get_death_players()]
|
||||
death_str= '\n'.join(death)
|
||||
_log.log_info(f'get_death_players: {death_str}')
|
||||
_log.log_info(f'get_death_players: {chat_id} - {death_str}')
|
||||
await update.message.reply_text(f'Ecco i giocatori morti x.x: \n{death_str}')
|
||||
|
||||
async def get_ranking_players(update, context):
|
||||
async def get_ranking_players(update, context, chat_id):
|
||||
Arena = context.application.bot_data['arena']
|
||||
leaderboard_text = Arena.get_ranking()
|
||||
_log.log_info(f'{leaderboard_text}')
|
||||
_log.log_info(f'get_ranking_players: {chat_id} - {leaderboard_text}')
|
||||
await update.message.reply_text(
|
||||
f'{leaderboard_text}',
|
||||
parse_mode='Markdown'
|
||||
|
||||
@@ -3,22 +3,22 @@ from bot_libs import simulation as _bot_sim
|
||||
|
||||
async def _loop_game(context):
|
||||
chat_id = context.job.chat_id
|
||||
_log.log_info(f'_loop_game: run on {chat_id}')
|
||||
_log.log_info(f'_loop_game: {chat_id} - run game simulation day')
|
||||
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:
|
||||
_log.log_info(f'start_loop_game: {chat_id} Arena not found')
|
||||
_log.log_info(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:
|
||||
_log.log_info(f'start_loop_game: {chat_id} Not enough player to start the match')
|
||||
_log.log_info(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)
|
||||
_log.log_info(f'start_loop_game: Repeating Job created for: {chat_id}')
|
||||
_log.log_info(f'start_loop_game: {chat_id} - Cron job started')
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import debug as _dbg
|
||||
from utils import logs as _log
|
||||
|
||||
def get_winner(context, Arena):
|
||||
|
||||
def get_winner(context, Arena, chat_id):
|
||||
winner= Arena.get_alive_players()[0]
|
||||
try:
|
||||
context.job.schedule_removal()
|
||||
_log.log_info(f'simulate_day: Loop removed')
|
||||
_log.log_info(f'simulate_day: {chat_id} Loop removed')
|
||||
except: pass
|
||||
|
||||
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia '
|
||||
msg+= f'uccidendo {winner.get_kills()} giocatori '
|
||||
msg+= f'e schivando {winner.get_dodges()} colpi nemici, e vive felice e '
|
||||
@@ -18,9 +20,10 @@ def get_winner(context, Arena):
|
||||
msg+= 'content# con Guarino'
|
||||
return msg
|
||||
|
||||
|
||||
async def simulate_day(context, chat_id):
|
||||
if 'arena' not in context.application.bot_data:
|
||||
_log.log_info('Arena not Found')
|
||||
_log.log_info('simulate_day: {chat_id} Arena not Found')
|
||||
await context.bot.send_message(chat_id, 'Che e\' successo? un Guarino ha rubato l\'arena, avvia una nuova partita con /start')
|
||||
return
|
||||
|
||||
@@ -34,5 +37,5 @@ async def simulate_day(context, chat_id):
|
||||
msg= Arena.get_ranking()
|
||||
await context.bot.send_message(chat_id, msg)
|
||||
if len(Arena.get_alive_players()) == 1:
|
||||
msg= get_winner(context, Arena)
|
||||
msg= get_winner(context, Arena, chat_id)
|
||||
return await context.bot.send_message(chat_id, msg)
|
||||
|
||||
Reference in New Issue
Block a user