more logs
This commit is contained in:
4
bot.py
4
bot.py
@@ -38,7 +38,7 @@ async def update_bot(update, context):
|
|||||||
await update.message.reply_text('Sto aggiornando il Bot...')
|
await update.message.reply_text('Sto aggiornando il Bot...')
|
||||||
chat_id = update.effective_chat.id
|
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')
|
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')
|
err= _os.system(f'cd {_botsyms.BOT_PATH}; /usr/bin/git pull')
|
||||||
if err:
|
if err:
|
||||||
_log.log_error(f'update_bot: {chat_id} error {err} while trying to update the app')
|
_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:
|
if err:
|
||||||
_log.log_error(f'update_bot: {chat_id} error {err} while trying to upstart the app')
|
_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')
|
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!')
|
await update.message.reply_text('Bot aggiornato e riavviato!')
|
||||||
|
|
||||||
async def bot_commands(update, context):
|
async def bot_commands(update, context):
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import random as _rand
|
import random as _rand
|
||||||
|
from utils import logs as _log
|
||||||
from bot_libs import syms as _bot_syms
|
from bot_libs import syms as _bot_syms
|
||||||
|
|
||||||
async def add_player(update, context, name):
|
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= context.application.bot_data['arena']
|
||||||
Arena.add_player(name)
|
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)
|
players_num= _rand.randint(min_players, max_players)
|
||||||
_rand.shuffle(names)
|
_rand.shuffle(names)
|
||||||
lucky_players= _rand.sample(names, players_num)
|
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)
|
for name in lucky_players: await add_player(update, context, name)
|
||||||
|
|
||||||
async def get_players(update, context):
|
async def get_players(update, context):
|
||||||
Arena= context.application.bot_data['arena']
|
Arena= context.application.bot_data['arena']
|
||||||
players= [p.get_name_and_stats() for p in Arena.get_players()]
|
players= [p.get_name_and_stats() for p in Arena.get_players()]
|
||||||
players_str= '\n'.join(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}')
|
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):
|
||||||
Arena= context.application.bot_data['arena']
|
Arena= context.application.bot_data['arena']
|
||||||
alive= [a.get_name_and_stats() for a in Arena.get_alive_players()]
|
alive= [a.get_name_and_stats() for a in Arena.get_alive_players()]
|
||||||
alive_str= '\n'.join(alive)
|
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}')
|
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):
|
||||||
Arena= context.application.bot_data['arena']
|
Arena= context.application.bot_data['arena']
|
||||||
death= [d.get_name_and_stats() for d in Arena.get_death_players()]
|
death= [d.get_name_and_stats() for d in Arena.get_death_players()]
|
||||||
death_str= '\n'.join(death)
|
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}')
|
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):
|
||||||
Arena = context.application.bot_data['arena']
|
Arena = context.application.bot_data['arena']
|
||||||
leaderboard_text = Arena.get_ranking()
|
leaderboard_text = Arena.get_ranking()
|
||||||
print(f'{leaderboard_text}')
|
_log.log_info(f'{leaderboard_text}')
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
f'{leaderboard_text}',
|
f'{leaderboard_text}',
|
||||||
parse_mode='Markdown'
|
parse_mode='Markdown'
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
|
from utils import logs as _log
|
||||||
from bot_libs import simulation as _bot_sim
|
from bot_libs import simulation as _bot_sim
|
||||||
|
|
||||||
async def _loop_game(context):
|
async def _loop_game(context):
|
||||||
chat_id = context.job.chat_id
|
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)
|
return await _bot_sim.simulate_day(context, chat_id)
|
||||||
|
|
||||||
async def start_loop_game(update, context, seconds):
|
async def start_loop_game(update, context, seconds):
|
||||||
await update.message.reply_text(f'Ok capo!! giochero\' per te ogni {seconds}s')
|
await update.message.reply_text(f'Ok capo!! giochero\' per te ogni {seconds}s')
|
||||||
chat_id = update.effective_chat.id
|
chat_id = update.effective_chat.id
|
||||||
if 'arena' not in context.application.bot_data:
|
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')
|
await update.message.reply_text(f'Arena non trovata, avviare con /start')
|
||||||
return
|
return
|
||||||
|
|
||||||
Arena= context.application.bot_data['arena']
|
Arena= context.application.bot_data['arena']
|
||||||
if len(Arena.get_players()) < 2:
|
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()}')
|
await update.message.reply_text(f'Servono almeno 2 giocatori. Ecco i giocatori presenti nel mondo do gioco: \n{Arena.get_players()}')
|
||||||
return
|
return
|
||||||
|
|
||||||
context.job_queue.run_repeating(_loop_game, interval= seconds, first=1, chat_id= chat_id)
|
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}')
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
from utils import logs as _log
|
||||||
import debug as _dbg
|
import debug as _dbg
|
||||||
|
|
||||||
def get_winner(Arena):
|
def get_winner(Arena):
|
||||||
winner= Arena.get_alive_players()[0]
|
winner= Arena.get_alive_players()[0]
|
||||||
try:
|
try:
|
||||||
context.job.schedule_removal()
|
context.job.schedule_removal()
|
||||||
print(f'simulate_day: Loop removed')
|
_log.log_info(f'simulate_day: Loop removed')
|
||||||
except: pass
|
except: pass
|
||||||
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia '
|
msg= f'{winner.get_name_and_stats()} Vince la cruenta battaglia '
|
||||||
msg+= f'uccidendo {winner.get_kills()} giocatori '
|
msg+= f'uccidendo {winner.get_kills()} giocatori '
|
||||||
@@ -19,7 +20,7 @@ def get_winner(Arena):
|
|||||||
|
|
||||||
async def simulate_day(context, chat_id):
|
async def simulate_day(context, chat_id):
|
||||||
if 'arena' not in context.application.bot_data:
|
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')
|
await context.bot.send_message(chat_id, 'Che e\' successo? un Guarino ha rubato l\'arena, avvia una nuova partita con /start')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user