async def stats(self, context, player: typing.Union[discord.Member, str] = None): if not self.exp_values: self.exp_values = utils.get_exp_values(Stats.EXP_VALUES_FILE_PATH, Stats.EXP_VALUES_FILE_URL) player, player_name = utils.parse_player(context, player) player_id, player_name = await Stats.get_player_id( player_name, self.app_id) if not player_id: raise exceptions.UnknownPlayer(player_name) stats_totals = await Stats.get_player_stats_totals( player_id, self.app_id) tank_stats, exp_stat_totals, missing_tanks = await Stats.get_player_tank_stats( player_id, self.exp_values, self.app_id) adjusted_stats_totals = await Stats.deduct_missing_tanks( player_id, stats_totals, missing_tanks, self.app_id) average_tier = await Stats.compute_average_tier( tank_stats, self.app_id) wn8 = await Stats.compute_wn8(adjusted_stats_totals, exp_stat_totals) player_details = { 'name': player_name, 'battles': stats_totals['battles'], 'average_xp': stats_totals['average_xp'], 'rating': stats_totals['rating'], 'win_ratio': (stats_totals['wins'] / stats_totals['battles']) * 100, 'average_tier': average_tier, 'wn8': wn8, } await self.display_stats(context, player, player_details)
async def clan(self, context, clan_search_field: typing.Union[discord.Member, str] = None): clan_id = None if not clan_search_field or isinstance(clan_search_field, discord.Member): _, player_name = utils.parse_player(context.guild, clan_search_field, context.author) _, player_id = wot_utils.get_exact_player_info( player_name, self.app_id) if not player_id: raise exceptions.UnknownPlayer(player_name) _, _, _, clan_id = wot_utils.get_player_details( player_id, self.app_id) if not clan_id: raise exceptions.MissingClan(player_name) elif isinstance(clan_search_field, str): # Remove clan tag delimiters if any replacements = {(re.escape(char)): '' for char in ['[', ']', '(', ')']} pattern = re.compile('|'.join(replacements.keys())) clan_search_field = pattern.sub( lambda m: replacements[re.escape(m.group(0))], clan_search_field) clan_id = wot_utils.get_clan_id(clan_search_field, self.app_id) if not clan_id: raise exceptions.UnknownClan(clan_search_field) clan_infos = wot_utils.get_clan_infos(clan_id, self.app_id) clan_contact = wot_utils.get_clan_contact(clan_id, self.guild.members, self.CLAN_CONTACT_ROLE_NAME, self.app_id) clan_details = {'id': clan_id} clan_details.update(clan_infos) clan_details['contact'] = clan_contact await self.display_clan(context, clan_details)
async def profile(self, context, player: typing.Union[discord.Member, str] = None): player, player_name = utils.parse_player(context.guild, player, context.author) player_name, player_id = wot_utils.get_exact_player_info( player_name, self.app_id) if not player_id: raise exceptions.UnknownPlayer(player_name) creation_timestamp, last_battle_timestamp, logout_timestamp, clan_id = \ wot_utils.get_player_details(player_id, self.app_id) clan_member_infos = wot_utils.get_clan_member_infos( player_id, self.app_id) clan_infos = wot_utils.get_clan_infos(clan_id, self.app_id) player_details = { 'name': player_name, 'id': player_id, 'creation_timestamp': creation_timestamp, 'last_battle_timestamp': last_battle_timestamp, 'logout_timestamp': logout_timestamp, 'clan': False, } if clan_infos: player_details.update({ 'clan': True, 'clan_id': clan_id, 'clan_position': clan_member_infos['position'], 'clan_name': clan_infos['name'], 'clan_tag': clan_infos['tag'], 'clan_emblem_url': clan_infos['emblem_url'], }) await self.display_profile(context, player, player_details)
async def stats(self, context, player: typing.Union[discord.Member, str] = None): if not self.exp_values: self.exp_values = wot_utils.load_exp_values( Stats.EXP_VALUES_FILE_PATH, Stats.EXP_VALUES_FILE_URL) if not self.tank_tiers: self.tank_tiers = wot_utils.load_tank_tiers(self.app_id) compute_start = perf_counter() player, player_name = utils.parse_player(context.guild, player, context.author) player_name, player_id = wot_utils.get_exact_player_info( player_name, self.app_id) if not player_id: raise exceptions.UnknownPlayer(player_name) stats_totals = wot_utils.get_player_stats_totals( player_id, self.app_id) tank_stats, exp_stat_totals, missing_tanks = wot_utils.get_player_tank_stats( player_id, self.exp_values, self.app_id) adjusted_stats_totals = wot_utils.deduct_missing_tanks( player_id, stats_totals, missing_tanks, self.app_id) average_tier = wot_utils.compute_average_tier(tank_stats, self.tank_tiers) wn8 = wot_utils.compute_wn8(adjusted_stats_totals, exp_stat_totals) compute_end = perf_counter() elapsed_time = compute_end - compute_start player_details = { 'name': player_name, 'battles': stats_totals['battles'], 'average_xp': stats_totals['average_xp'], 'rating': stats_totals['rating'], 'win_ratio': stats_totals['win_rate'] * 100, 'average_tier': average_tier, 'wn8': wn8, } await self.display_stats(context, player, player_details, elapsed_time)