forked from Cryz/battle_royale_sim
cleanings
This commit is contained in:
55
bot.py
55
bot.py
@@ -15,6 +15,32 @@ from bot_libs import upstart as _bot_upstart
|
||||
from bot_libs import syms as _botsyms
|
||||
|
||||
|
||||
async def _get_name_from_input(context, update, chat_id, 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())
|
||||
|
||||
elif text == 'Add random Players':
|
||||
await _bot_player.add_random_players(update, context, colors_names= False)
|
||||
|
||||
elif text == 'Add random color Players':
|
||||
await _bot_player.add_random_players(update, context, colors_names= True)
|
||||
|
||||
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}')
|
||||
|
||||
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')
|
||||
try: text= int(text)
|
||||
except: return
|
||||
seconds= max(1, text)
|
||||
return await _bot_repeat.start_loop_game(update, context, seconds)
|
||||
|
||||
async def bot_start(update, context):
|
||||
await update.message.reply_text(_botsyms.START_MSG)
|
||||
|
||||
@@ -47,21 +73,27 @@ async def bot_commands(update, context):
|
||||
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)')
|
||||
|
||||
if text == 'Get Players':
|
||||
_log.log_info(f'bot_command: {chat_id} Get Players')
|
||||
return await _bot_player.get_players(update, context)
|
||||
|
||||
if text == 'Get Alive Players':
|
||||
_log.log_info(f'bot_command: {chat_id} Get Alive Players')
|
||||
return await _bot_player.get_alive_players(update, context)
|
||||
|
||||
if text == 'Get Death Players':
|
||||
_log.log_info(f'bot_command: {chat_id} Get Death Players')
|
||||
return await _bot_player.get_death_players(update, context)
|
||||
|
||||
if text == 'Get Ranking Players':
|
||||
_log.log_info(f'bot_command: {chat_id} Get Ranking Players')
|
||||
return await _bot_player.get_ranking_players(update, context)
|
||||
|
||||
if text == 'Simulate Day':
|
||||
_log.log_info(f'bot_command: {chat_id} Simulate Day')
|
||||
return await _bot_sim.simulate_day(context, chat_id)
|
||||
|
||||
if text == 'Run Periodically':
|
||||
_log.log_info(f'bot_command: {chat_id} Run Periodically')
|
||||
context.application.bot_data['ask_seconds'] = 1
|
||||
@@ -71,31 +103,14 @@ async def bot_commands(update, context):
|
||||
|
||||
waiting_for_name= context.application.bot_data.get('ask_name')
|
||||
if waiting_for_name or text in ['Add random Players', 'Add random color Players']:
|
||||
_log.log_debug(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())
|
||||
elif text == 'Add random Players':
|
||||
await _bot_player.add_random_players(update, context, colors_names= False)
|
||||
elif text == 'Add random color Players':
|
||||
await _bot_player.add_random_players(update, context, colors_names= True)
|
||||
|
||||
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}')
|
||||
return await _get_name_from_input(context, update, chat_id, text)
|
||||
|
||||
waiting_for_seconds= context.application.bot_data.get('ask_seconds')
|
||||
if waiting_for_seconds:
|
||||
_log.log_debug(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 _bot_repeat.start_loop_game(update, context, seconds)
|
||||
return await _get_seconds_from_input(context, update, chat_id, text)
|
||||
|
||||
if text == 'upstart': return await _bot_upstart.update_bot(update, context)
|
||||
|
||||
_log.log_debug(f'bot_command: {chat_id} sent this text: {text}')
|
||||
await update.message.reply_text(_botsyms.WIP_MSG)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user