Пример #1
0
async def get_fleet_users_stars_from_info(ctx: commands.Context, fleet_info: dict, fleet_users_infos: dict, retrieved_date: datetime = None, as_embed: bool = settings.USE_EMBEDS) -> list:
    fleet_name = fleet_info[FLEET_DESCRIPTION_PROPERTY_NAME]
    division = lookups.DIVISION_DESIGN_ID_TO_CHAR[fleet_info[top.DIVISION_DESIGN_KEY_NAME]]

    fleet_users_infos = util.sort_entities_by(list(fleet_users_infos.values()), [('AllianceScore', int, True), (user.USER_KEY_NAME, int, False)])
    fleet_users_infos_count = len(fleet_users_infos)

    title = f'{fleet_name} member stars (division {division})'
    lines = []
    for i, user_info in enumerate(fleet_users_infos, 1):
        stars = user_info['AllianceScore']
        user_name = util.escape_markdown(user_info[user.USER_DESCRIPTION_PROPERTY_NAME])
        fleet_membership = user_info.get('AllianceMembership')
        if i < fleet_users_infos_count:
            difference = int(user_info['AllianceScore']) - int(fleet_users_infos[i]['AllianceScore'])
        else:
            difference = 0
        user_rank = lookups.get_lookup_value_or_default(lookups.ALLIANCE_MEMBERSHIP, fleet_membership, default=fleet_membership)
        lines.append(f'**{i}.** {stars} (+{difference}) {emojis.star} {user_name} ({user_rank})')

    footer_text = util.get_historic_data_note(retrieved_date)

    if as_embed:
        colour = util.get_bot_member_colour(ctx.bot, ctx.guild)
        icon_url = await sprites.get_download_sprite_link(fleet_info.get('AllianceSpriteId'))
        result = util.create_basic_embeds(title, description=lines, colour=colour, icon_url=icon_url, footer=footer_text)
        return result
    else:
        if retrieved_date is not None:
            lines.append(f'```{footer_text}```')
        return lines
Пример #2
0
async def get_item_upgrades_from_name(item_name: str,
                                      as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_designs_data = await items_designs_retriever.get_data_dict3()
    item_ids = _get_item_design_ids_from_name(item_name, items_designs_data)

    if not item_ids:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        item_infos = []
        for item_id in item_ids:
            item_infos.extend(_get_upgrades_for(item_id, items_designs_data))
        item_infos = list(
            dict([(item_info[ITEM_DESIGN_KEY_NAME], item_info)
                  for item_info in item_infos]).values())
        item_infos = util.sort_entities_by(
            item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])

        if as_embed:
            return _get_item_upgrades_as_embed(item_name, item_infos,
                                               items_designs_data), True
        else:
            return _get_item_upgrades_as_text(item_name, item_infos,
                                              items_designs_data), True
Пример #3
0
async def get_item_price(item_name: str, as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_designs_data = await items_designs_retriever.get_data_dict3()
    item_infos = _get_item_infos_by_name(item_name, items_designs_data)

    if not item_infos:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        get_best_match = util.is_str_in_list(
            item_name, ALLOWED_ITEM_NAMES, case_sensitive=False
        ) and len(item_name) < settings.MIN_ENTITY_NAME_LENGTH - 1
        if get_best_match:
            item_infos = [item_infos[0]]

        item_infos = util.sort_entities_by(
            item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])
        items_designs_details = __create_price_design_data_list_from_infos(
            item_infos, items_designs_data)

        if as_embed:
            return _get_item_price_as_embed(item_name,
                                            items_designs_details), True
        else:
            return _get_item_price_as_text(item_name,
                                           items_designs_details), True
Пример #4
0
def get_fleet_users_stars_from_info(fleet_info: dict,
                                    fleet_users_infos: dict,
                                    retrieved_date: datetime = None) -> list:
    fleet_name = fleet_info[FLEET_DESCRIPTION_PROPERTY_NAME]
    division = lookups.DIVISION_DESIGN_ID_TO_CHAR[
        fleet_info['DivisionDesignId']]

    fleet_users_infos = util.sort_entities_by(list(
        fleet_users_infos.values()), [('AllianceScore', int, True),
                                      (user.USER_KEY_NAME, int, False)])
    fleet_users_infos_count = len(fleet_users_infos)

    lines = [f'**{fleet_name} member stars (division {division})**']
    for i, user_info in enumerate(fleet_users_infos, 1):
        stars = user_info['AllianceScore']
        user_name = util.escape_markdown(
            user_info[user.USER_DESCRIPTION_PROPERTY_NAME])
        if i < fleet_users_infos_count:
            difference = int(user_info['AllianceScore']) - int(
                fleet_users_infos[i]['AllianceScore'])
        else:
            difference = 0
        lines.append(
            f'**{i}.** {stars} (+{difference}) {emojis.star} {user_name}')

    if retrieved_date is not None:
        lines.append(util.get_historic_data_note(retrieved_date))

    return lines
Пример #5
0
def _get_division_stars_as_text(division_letter: str, fleet_infos: list) -> list:
    lines = [f'__**Division {division_letter.upper()}**__']
    fleet_infos = util.sort_entities_by(fleet_infos, [('Score', int, True)])
    for i, fleet_info in enumerate(fleet_infos, 1):
        fleet_name = fleet_info['AllianceName']
        if 'Trophy' in fleet_info.keys():
            trophies = fleet_info['Trophy']
            trophy_str = f' ({trophies} {emojis.trophy})'
        else:
            trophy_str = ''
        stars = fleet_info['Score']
        if util.should_escape_entity_name(fleet_name):
            fleet_name = f'`{fleet_name}`'
        lines.append(f'**{i:d}.** {stars} {emojis.star} {fleet_name}{trophy_str}')
    return lines
Пример #6
0
def get_item_details(item_name: str, as_embed=False):
    pss_assert.valid_entity_name(item_name,
                                 allowed_values=__allowed_item_names)

    item_infos = _get_item_infos_by_name(item_name)

    if not item_infos:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        item_infos = util.sort_entities_by(
            item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])

        if as_embed:
            return _get_item_info_as_embed(item_name, item_infos), True
        else:
            return _get_item_info_as_text(item_name, item_infos), True
Пример #7
0
def _get_division_stars_as_text(division_letter: str, fleet_infos: list) -> list:
    lines = [f'__**Division {division_letter.upper()}**__']
    fleet_infos = util.sort_entities_by(fleet_infos, [('Score', int, True)])
    fleet_infos_count = len(fleet_infos)
    for i, fleet_info in enumerate(fleet_infos, start=1):
        fleet_name = util.escape_markdown(fleet_info['AllianceName'])
        if 'Trophy' in fleet_info.keys():
            trophies = fleet_info['Trophy']
            trophy_str = f' ({trophies} {emojis.trophy})'
        else:
            trophy_str = ''
        stars = fleet_info['Score']
        if i < fleet_infos_count:
            difference = int(stars) - int(fleet_infos[i]['Score'])
        else:
            difference = 0
        lines.append(f'**{i:d}.** {stars} (+{difference}) {emojis.star} {fleet_name}{trophy_str}')
    return lines
Пример #8
0
async def get_item_details_by_name(item_name: str,
                                   as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_designs_data = await items_designs_retriever.get_data_dict3()
    item_infos = _get_item_infos_by_name(item_name, items_designs_data)

    if not item_infos:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        item_infos = util.sort_entities_by(
            item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])
        items_designs_details = __create_base_design_data_list_from_infos(
            item_infos, items_designs_data)

        if as_embed:
            return _get_item_info_as_embed(item_name,
                                           items_designs_details), True
        else:
            return _get_item_info_as_text(item_name,
                                          items_designs_details), True
Пример #9
0
def get_item_price(item_name: str, as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(item_name,
                                 allowed_values=__allowed_item_names)

    item_infos = _get_item_infos_by_name(item_name)

    if not item_infos:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        get_best_match = util.is_str_in_list(
            item_name, __allowed_item_names, case_sensitive=False
        ) and len(item_name) < settings.MIN_ENTITY_NAME_LENGTH - 1
        if get_best_match:
            item_infos = [item_infos[0]]

        item_infos = util.sort_entities_by(
            item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])

        if as_embed:
            return _get_item_price_as_embed(item_name, item_infos), True
        else:
            return _get_item_price_as_text(item_name, item_infos), True
Пример #10
0
def get_fleet_users_stars_from_info(fleet_info: dict,
                                    fleet_users_infos: dict,
                                    retrieved_date: datetime = None) -> list:
    fleet_name = fleet_info[FLEET_DESCRIPTION_PROPERTY_NAME]
    division = lookups.DIVISION_DESIGN_ID_TO_CHAR[
        fleet_info['DivisionDesignId']]

    fleet_users_infos = util.sort_entities_by(list(
        fleet_users_infos.values()), [('AllianceScore', int, True),
                                      (user.USER_KEY_NAME, int, False)])

    lines = [f'**{fleet_name} member stars (division {division})**']
    for i, user_info in enumerate(fleet_users_infos, 1):
        stars = user_info['AllianceScore']
        user_name = user_info[user.USER_DESCRIPTION_PROPERTY_NAME]
        if util.should_escape_entity_name(user_name):
            user_name = f'`{user_name}`'
        lines.append(f'**{i}.** {stars} {emojis.star} {user_name}')

    if retrieved_date is not None:
        lines.append(util.get_historic_data_note(retrieved_date))

    return lines
Пример #11
0
def get_item_upgrades_from_name(item_name: str,
                                as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(item_name,
                                 allowed_values=__allowed_item_names)

    item_design_data = __item_designs_cache.get_data_dict3()
    item_ids = _get_item_design_ids_from_name(item_name)
    item_infos = _get_item_infos_by_name(item_name)

    if not item_ids:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        item_infos = []
        for item_id in item_ids:
            item_infos.extend(_get_upgrades_for(item_id, item_design_data))
        item_infos = util.sort_entities_by(
            item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])

        if as_embed:
            return _get_item_upgrades_as_embed(item_name, item_infos,
                                               item_design_data), True
        else:
            return _get_item_upgrades_as_text(item_name, item_infos,
                                              item_design_data), True