forked from Cryz/battle_royale_sim
		
	
		
			
				
	
	
		
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import os as _os
 | |
| from utils import logs as _log
 | |
| from bot_libs import syms as _botsyms
 | |
| 
 | |
| async def _pull_repo(update):
 | |
|   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')
 | |
|     await update.message.reply_text('Errore durante l\'aggiornamento del Bot')
 | |
|   return err
 | |
| 
 | |
| async def _upstart_service(update):
 | |
|   err= _os.system(_botsyms.BOT_EXEC_CMD)
 | |
|   # this error is fake, probably due to systemd restart that make the bot istance broke
 | |
|   #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')
 | |
| 
 | |
| async def update_bot(update, context):
 | |
|   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')
 | |
| 
 | |
|   await update.message.reply_text('Sto aggiornando il Bot...')
 | |
|   _log.log_info(f'update_bot: {chat_id} bot is updating...')
 | |
| 
 | |
|   err= await _pull_repo(update)
 | |
|   if err: return
 | |
|   err= await _upstart_service(update)
 | |
|   if err: return
 | |
| 
 | |
|   _log.log_info(f'update_bot: {chat_id} bot successfully updated')
 | |
|   await update.message.reply_text('Bot aggiornato e riavviato!')
 | |
| 
 | |
| async def show_logs(update, context):
 | |
|   chat_id = update.effective_chat.id
 | |
|   if update.message.chat.id not in _botsyms.SUPER_USERS:
 | |
|     return _log.log_warning(f'open_logs: user {chat_id} not allowed')
 | |
| 
 | |
|   await update.message.reply_text('Sto provando ad aprire i log...')
 | |
|   _log.log_debug(f'open_logs: {chat_id} trying opening logs...')
 | |
|   try:
 | |
|     game_log= _os.path.expanduser(f'{_log.get_log_name()}')
 | |
|     with open(game_log, 'r') as _log_file:
 | |
|       lines= _log_file.readlines()[-30:]
 | |
|       log_content= '\n'.join(lines)
 | |
|       await update.message.reply_text(f"Contenuto del log:\n{log_content}")
 | |
|   except Exception as e:
 | |
|     await update.message.reply_text(f"Errore nella lettura del file di log: {str(e)}")
 | 
