more logs

This commit is contained in:
andrea
2025-07-26 19:30:13 +02:00
parent 72ec279036
commit ffbaa1c3b5
4 changed files with 17 additions and 14 deletions

4
bot.py
View File

@@ -38,7 +38,7 @@ async def update_bot(update, context):
await update.message.reply_text('Sto aggiornando il Bot...')
chat_id = update.effective_chat.id
if update.message.chat.id not in _botsyms.SUPER_USERS: return _log.log_warning(f'update_bot: user {chat_id} not allowed')
_log.log_debug(f'update_bot: {chat_id} bot is updating...')
_log.log_info(f'update_bot: {chat_id} bot is updating...')
err= _os.system(f'cd {_botsyms.BOT_PATH}; /usr/bin/git pull')
if err:
_log.log_error(f'update_bot: {chat_id} error {err} while trying to update the app')
@@ -47,7 +47,7 @@ async def update_bot(update, context):
if err:
_log.log_error(f'update_bot: {chat_id} error {err} while trying to upstart the app')
return await update.message.reply_text('Errore durante il riavvio del Bot')
_log.log_debug(f'update_bot: {chat_id} bot successfully updated')
_log.log_info(f'update_bot: {chat_id} bot successfully updated')
await update.message.reply_text('Bot aggiornato e riavviato!')
async def bot_commands(update, context):

View File

@@ -1,8 +1,9 @@
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):
print(f'add_player: {name}')
_log.log_info(f'add_player: {name}')
Arena= context.application.bot_data['arena']
Arena.add_player(name)
@@ -16,34 +17,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)
print(f'add_random_players: extracting {players_num} random players for the game')
_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)
async def get_players(update, context):
Arena= context.application.bot_data['arena']
players= [p.get_name_and_stats() for p in Arena.get_players()]
players_str= '\n'.join(players)
print(f'get_players: {players_str}')
_log.log_info(f'get_players: {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):
Arena= context.application.bot_data['arena']
alive= [a.get_name_and_stats() for a in Arena.get_alive_players()]
alive_str= '\n'.join(alive)
print(f'get_alive_players: {alive_str}')
_log.log_info(f'get_alive_players: {alive_str}')
await update.message.reply_text(f'Ecco i giocatori ancora vivi: \n{alive_str}')
async def get_death_players(update, context):
Arena= context.application.bot_data['arena']
death= [d.get_name_and_stats() for d in Arena.get_death_players()]
death_str= '\n'.join(death)
print(f'get_death_players: {death_str}')
_log.log_info(f'get_death_players: {death_str}')
await update.message.reply_text(f'Ecco i giocatori morti x.x: \n{death_str}')
async def get_ranking_players(update, context):
Arena = context.application.bot_data['arena']
leaderboard_text = Arena.get_ranking()
print(f'{leaderboard_text}')
_log.log_info(f'{leaderboard_text}')
await update.message.reply_text(
f'{leaderboard_text}',
parse_mode='Markdown'

View File

@@ -1,23 +1,24 @@
from utils import logs as _log
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}')
_log.log_info(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')
_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:
print(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)
print(f'start_loop_game: Repeating Job created for: {chat_id}')
_log.log_info(f'start_loop_game: Repeating Job created for: {chat_id}')

View File

@@ -1,10 +1,11 @@
from utils import logs as _log
import debug as _dbg
def get_winner(Arena):
winner= Arena.get_alive_players()[0]
try:
context.job.schedule_removal()
print(f'simulate_day: Loop removed')
_log.log_info(f'simulate_day: Loop removed')
except: pass
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia '
msg+= f'uccidendo {winner.get_kills()} giocatori '
@@ -19,7 +20,7 @@ def get_winner(Arena):
async def simulate_day(context, chat_id):
if 'arena' not in context.application.bot_data:
print('Arena not Found')
_log.log_info('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