def get_league_connection_macro(logger, connection, settings): ''' Parses connection url and port from lockfile of leagu client ''' checkpoint_time = time.time() logger.log('Getting league client connection') connection.get_connection_ft(settings) logger.log('League client connection established, took {}'.format( naturaldelta(time.time() - checkpoint_time)))
def login_macro(logger, connection, account): ''' Logs in to the client ''' checkpoint_time = time.time() logger.log('Logging in...') login(logger, connection, account.username, account.password, account.region, account.locale) logger.log('Logged in, took {}'.format( naturaldelta(time.time() - checkpoint_time)))
async def check_session_macro(logger, connection, account): ''' Checks the session of an account ''' checkpoint_time = time.time() logger.log('Checking session') while True: session = await check_session(connection) if session == 'succeed': break if session == 'new_player': set_summoner_name(logger, connection, account.username) await asyncio.sleep(1) logger.log('Session checking finished, took {}'.format( naturaldelta(time.time() - checkpoint_time)))
async def do_macro(self, options, account): ''' Calls the macro fucntion according to state ''' while True: try: start_time = time.time() get_riot_connection_macro(self.logger, self.riot_connection, self.settings) login_macro(self.logger, self.riot_connection, account) get_league_connection_macro(self.logger, self.league_connection, self.settings) await check_session_macro(self.logger, self.league_connection, account) await check_username_macro(self.logger, self.league_connection, account.username) total_time = time.time() - start_time self.logger.log('Total time taken to login: {}'.format( naturaldelta(total_time))) self.logger.write_line('console', '-' * 75) output = await self.handle_disenchant_tasks(options) self.logger.log('Logging out') kill_league_client(self.settings) kill_riot_client(self.settings) return output except (AccountChangeNeededException, LootRetrieveException, LogoutNeededException): self.logger.log('Logging out') kill_league_client(self.settings) kill_riot_client(self.settings) await asyncio.sleep(5) except LeagueConnectionException: self.logger.log('League client connection failed') kill_league_client(self.settings) except NoSessionException: self.logger.log( 'No session was found. Restarting the client...') kill_league_client(self.settings) except RiotConnectionException: self.logger.log('Riot client connection failed') kill_riot_client(self.settings) except requests.exceptions.RequestException as exp: self.logger.log(str(exp)) finally: self.logger.write_line('console', '-' * 75)
async def check_username_macro(logger, connection, username): ''' Checks if the current logged in account is correct ''' checkpoint_time = time.time() logger.log('Getting username...') for _ in range(20): username_client = await get_username(connection) if username_client is None or username_client == '': await asyncio.sleep(1) continue if username.lower() != username_client.lower(): logger.log(f'Expected username: {username.lower()}. ' 'Current username: {username_client.lower()}') raise AccountChangeNeededException break else: raise LogoutNeededException logger.log('Got username, took {}'.format( naturaldelta(time.time() - checkpoint_time)))