Exemplo n.º 1
0
Arquivo: admin.py Projeto: Zedd7/ZBot
 async def check_contacts_recruiting_permissions(context, contacts_by_clan,
                                                 app_id):
     """Check that all clan contacts still have recruiting permissions."""
     disbanded_members, demoted_members = [], []
     for clan_tag, contacts in contacts_by_clan.items():
         for member in contacts:
             result = utils.PLAYER_NAME_PATTERN.match(member.display_name)
             if result:  # Malformed member names handled by check_players_matching_name
                 player_name = result.group(1)
                 _, player_id = wot_utils.get_exact_player_info(
                     player_name, app_id)
                 if player_id:  # Non-matching name handled by Admin.check_players_matching_name
                     clan_member_infos = wot_utils.get_clan_member_infos(
                         player_id, app_id)
                     real_clan_tag = clan_member_infos and clan_member_infos[
                         'tag']
                     clan_position = clan_member_infos and clan_member_infos[
                         'position']
                     if not clan_member_infos or real_clan_tag != clan_tag.upper(
                     ):
                         disbanded_members.append((member, clan_tag))
                     elif clan_position not in [
                             "Commandant", "Commandant en second",
                             "Officier du personnel", "Recruteur"
                     ]:
                         demoted_members.append((member, real_clan_tag))
     if disbanded_members:
         for block in utils.make_message_blocks([
                 f"Le joueur {member.mention} a quitté le clan [{clan_tag}]."
                 for member, clan_tag in disbanded_members
         ]):
             await context.send(block)
     if demoted_members:
         for block in utils.make_message_blocks([
                 f"Le joueur {member.mention} n'a pas les permissions de recrutement au sein du "
                 f"clan [{real_clan_tag}]."
                 for member, real_clan_tag in demoted_members
         ]):
             await context.send(block)
     if not disbanded_members and not demoted_members:
         await context.send(
             "Tous les contacts de clan ont encore leurs permissions de recrutement. :ok_hand: "
         )
     return disbanded_members, demoted_members
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)