Exemplo n.º 1
0
async def __get_image_url(item_info: EntityInfo, items_data: EntitiesData, trainings_data: EntitiesData = None, **kwargs) -> Optional[str]:
    logo_sprite_id = item_info.get('LogoSpriteId')
    image_sprite_id = item_info.get('ImageSpriteId')
    if entity.entity_property_has_value(logo_sprite_id) and logo_sprite_id != image_sprite_id:
        return await sprites.get_download_sprite_link(logo_sprite_id)
    else:
        return None
Exemplo n.º 2
0
def __get_key_for_best_items_sort(item_info: EntityInfo) -> str:
    if item_info.get('EnhancementValue') and item_info.get(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME):
        slot = item_info['ItemSubType']
        rarity_num = lookups.RARITY_ORDER_LOOKUP[item_info['Rarity']]
        enhancement_value = int((1000.0 - float(item_info['EnhancementValue'])) * 10)
        item_name = item_info[ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME]
        result = f'{enhancement_value}{slot}{rarity_num}{item_name}'
        return result
Exemplo n.º 3
0
async def get_image_url(item_info: EntityInfo) -> Optional[str]:
    logo_sprite_id = item_info.get('LogoSpriteId')
    image_sprite_id = item_info.get('ImageSpriteId')
    if entity.entity_property_has_value(logo_sprite_id) and logo_sprite_id != image_sprite_id:
        return await sprites.get_download_sprite_link(logo_sprite_id)
    elif entity.entity_property_has_value(image_sprite_id):
        return await sprites.get_download_sprite_link(image_sprite_id)
    else:
        return None
Exemplo n.º 4
0
def __get_user_name(user_info: EntityInfo, **kwargs) -> Optional[str]:
    result = None
    user_name = user_info.get(USER_DESCRIPTION_PROPERTY_NAME)
    if user_name is not None:
        result = user_name
        current_user_name = user_info.get('CurrentName')
        if current_user_name is not None:
            result += f' (now: {current_user_name})'
    return result
Exemplo n.º 5
0
def __get_key_for_base_items_sort(item_info: EntityInfo, items_data: EntitiesData) -> str:
    result = item_info.get(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME)
    item_sub_type = item_info.get('ItemSubType')
    if entity.entity_property_has_value(item_sub_type) and item_sub_type in lookups.ITEM_SUB_TYPES_TO_GET_PARENTS_FOR:
        parents = __get_parents(item_info, items_data)
        if parents:
            result = parents[0].get(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME)
            result += ''.join([item_info.get(ITEM_DESIGN_KEY_NAME).zfill(4) for item_info in parents])
    return result
Exemplo n.º 6
0
def __get_trophies(user_info: EntityInfo, **kwargs) -> Optional[str]:
    result = None
    trophies = user_info.get('Trophy')
    if trophies is not None:
        result = f'{trophies}'
        highest_trophies = user_info.get('HighestTrophy')
        if highest_trophies is not None:
            result += f' (highest: {highest_trophies})'
    return result
Exemplo n.º 7
0
def __get_tourney_battle_attempts(user_info: EntityInfo, utc_now: datetime) -> int:
    attempts = user_info.get('TournamentBonusScore')
    if attempts:
        attempts = int(attempts)
        last_login_date = utils.parse.pss_datetime(user_info.get('LastLoginDate'))
        if last_login_date:
            if last_login_date.day != utc_now.day:
                attempts = 0
    return attempts
Exemplo n.º 8
0
def __get_league(user_info: EntityInfo, **kwargs) -> Optional[str]:
    result = None
    trophies = user_info.get('Trophy')
    if trophies is not None:
        result = f'{__get_league_from_trophies(int(trophies))}'
        highest_trophies = user_info.get('HighestTrophy')
        if highest_trophies is not None:
            result += f' (highest: {__get_league_from_trophies(int(highest_trophies))})'
    return result
Exemplo n.º 9
0
def __get_user_name(user_info: EntityInfo, **kwargs) -> Optional[str]:
    result = None
    user_name = user_info.get('Name')
    if user_name is not None:
        result = user_name
        current_user_name = user_info.get('CurrentName')
        if current_user_name is not None:
            result += f' (now: {current_user_name})'
    return result
Exemplo n.º 10
0
def __get_name(fleet_info: EntityInfo, fleet_users_data: EntitiesData,
               **kwargs) -> Optional[str]:
    result = None
    fleet_name = fleet_info.get(FLEET_DESCRIPTION_PROPERTY_NAME)
    if fleet_name is not None:
        result = fleet_name
        current_name = fleet_info.get('CurrentAllianceName')
        if current_name is not None:
            result += f' (now: {current_name})'
    return result
Exemplo n.º 11
0
def __get_parents(item_info: EntityInfo, items_data: EntitiesData) -> List[EntityInfo]:
    item_design_id = item_info.get(ITEM_DESIGN_KEY_NAME)
    root_item_design_id = item_info.get('RootItemDesignId')
    result = []
    if entity.entity_property_has_value(root_item_design_id) and item_design_id != root_item_design_id:
        parent_info = items_data.get(root_item_design_id)
        if parent_info:
            result = __get_parents(parent_info, items_data)
            result.append(parent_info)
    return result
Exemplo n.º 12
0
def __get_type(item_info: EntityInfo, items_data: EntitiesData, trainings_data: EntitiesData = None, **kwargs) -> Optional[str]:
    item_sub_type = item_info.get('ItemSubType')
    if entity.entity_property_has_value(item_sub_type) and 'Equipment' not in item_sub_type:
        result = item_sub_type.replace('Equipment', '')
    else:
        item_type = item_info.get('ItemType')
        if entity.entity_property_has_value(item_type):
            result = item_type
        else:
            result = None
    return result
Exemplo n.º 13
0
def get_star_value_from_user_info(user_info: EntityInfo) -> Optional[int]:
    result = None
    trophies = user_info.get('Trophy')
    if trophies:
        trophies = int(trophies)
        stars = user_info.get('AllianceScore')
        if stars:
            stars = int(stars)
        else:
            stars = 0
        result = math.floor(max(trophies/1000, stars*0.15))
    return result
Exemplo n.º 14
0
def __get_division_name_and_ranking(fleet_info: EntityInfo,
                                    fleet_users_data: EntitiesData,
                                    **kwargs) -> Optional[str]:
    result = None
    division_name = get_division_name(
        fleet_info.get(top.DIVISION_DESIGN_KEY_NAME))
    if division_name is not None and division_name != '-':
        result = division_name
        ranking = fleet_info.get('Ranking')
        if ranking is not None and ranking != '0':
            division_ranking = int(
                ranking) - lookups.DIVISION_CUTOFF_LOOKUP[division_name][0] + 1
            result += f' ({utils.format.ranking(division_ranking)})'
    return result
Exemplo n.º 15
0
def get_fleet_search_details(fleet_info: EntityInfo) -> str:
    fleet_name = fleet_info[FLEET_DESCRIPTION_PROPERTY_NAME]
    fleet_name_current = fleet_info.get('CurrentAllianceName', None)
    if fleet_name_current is not None:
        fleet_name += f' (now: {fleet_name_current})'

    details = []
    fleet_trophies = fleet_info.get('Trophy', None)
    fleet_stars = int(fleet_info.get('Score', '0'))
    if fleet_trophies is not None:
        details.append(f'{emojis.trophy} {fleet_trophies}')
    if fleet_stars > 0:
        details.append(f'{emojis.star} {fleet_stars}')
    result = (f'{fleet_name} ' + ' '.join(details)).strip()
    return result
Exemplo n.º 16
0
def __get_user_type(user_info: EntityInfo, **kwargs) -> Optional[str]:
    result = None
    user_type = user_info.get('UserType')
    if user_type is not None:
        result = lookups.get_lookup_value_or_default(lookups.USER_TYPE,
                                                     user_type)
    return result
Exemplo n.º 17
0
def __get_crew_donated(user_info: EntityInfo,
                       fleet_info: EntityInfo = None,
                       **kwargs) -> Optional[str]:
    result = None
    if fleet_info:
        result = user_info.get('CrewDonated')
    return result
Exemplo n.º 18
0
def get_user_search_details(user_info: EntityInfo) -> str:
    user_name = __get_user_name(user_info)
    user_trophies = user_info.get('Trophy', '?')
    user_stars = int(user_info.get('AllianceScore', '0'))

    details = []
    if user_info.get(fleet.FLEET_KEY_NAME, '0') != '0':
        fleet_name = user_info.get(fleet.FLEET_DESCRIPTION_PROPERTY_NAME, None)
        if fleet_name is not None:
            details.append(f'({fleet_name})')

    details.append(f'{emojis.trophy} {user_trophies}')
    if user_stars > 0:
        details.append(f'{emojis.star} {user_stars}')
    result = f'{user_name} ' + ' '.join(details)
    return result
Exemplo n.º 19
0
def __get_prestige_to_title(character_info: EntityInfo, for_embed: bool = None, **kwargs) -> Optional[str]:
    char_name = character_info.get(CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME)
    if for_embed:
        result = f'{char_name} with'
    else:
        result = f'{char_name} with:'
    return result
Exemplo n.º 20
0
def __get_embed_color(collection_info: EntityInfo, collections_data: EntitiesData, characters_data: EntitiesData, **kwargs) -> Colour:
    color_string = collection_info.get('ColorString')
    if entity.entity_property_has_value(color_string):
        result = utils.discord.convert_color_string_to_embed_color(color_string)
    else:
        result = Embed.Empty
    return result
Exemplo n.º 21
0
def __get_ranking(fleet_info: EntityInfo, fleet_users_data: EntitiesData,
                  **kwargs) -> Optional[str]:
    result = None
    ranking = fleet_info.get('Ranking')
    if ranking is not None and ranking != '0':
        result = utils.format.ranking(ranking)
    return result
Exemplo n.º 22
0
def __get_pixel_prestige_hyperlink(character_info: EntityInfo, characters_data: EntitiesData, collections_data: EntitiesData, level: int, **kwargs) -> Optional[str]:
    crew_id: str = character_info.get(CHARACTER_DESIGN_KEY_NAME)
    if crew_id:
        url = f'https://pixel-prestige.com/crew.php?nId={crew_id}'
        return f'<{url}>'
    else:
        return None
Exemplo n.º 23
0
def is_tournament_fleet(fleet_info: EntityInfo) -> bool:
    try:
        division_design_id = int(
            fleet_info.get(top.DIVISION_DESIGN_KEY_NAME, '0'))
        return division_design_id > 0
    except:
        return False
Exemplo n.º 24
0
async def get_sales_history(
        ctx: Context,
        entity_info: EntityInfo,
        reverse: bool = False,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    utc_now = utils.get_utc_now()

    category_type = entity_info.get('entity_type')
    entity_id = entity_info.get('entity_id')
    entity_id = int(entity_id) if entity_id else None
    entity_name = entity_info.get('entity_name')

    db_sales_infos = await __db_get_sales_infos(utc_now=utc_now,
                                                category_type=category_type,
                                                entity_id=entity_id)
    sales_infos = await __process_db_sales_infos(
        db_sales_infos, utc_now, filter_old=(entity_id is None))
    if reverse:
        sales_infos = reversed(sales_infos)

    if sales_infos:
        title = f'{entity_name} has been sold on'
        sales_details = []
        for sales_info in sales_infos:
            sold_on_date = sales_info['expiry_date'] - utils.datetime.ONE_DAY
            sold_on = utils.format.datetime(sold_on_date,
                                            include_time=False,
                                            include_tz=False)
            star_date = utils.datetime.get_star_date(sold_on_date)
            sold_ago = (utc_now - sold_on_date).days
            price = sales_info['original_price']
            currency = sales_info['currency']
            day = 'day' + 's' if sold_ago != 1 else ''
            sales_details.append(
                f'{sold_on} (Star date {star_date}, {sold_ago} {day} ago) for {price} {currency}'
            )

        if as_embed:
            colour = utils.discord.get_bot_member_colour(ctx.bot, ctx.guild)
            result = utils.discord.create_basic_embeds_from_description(
                title, description=sales_details, colour=colour)
        else:
            result = [f'**{title}**']
            result.extend(sales_details)
        return result
    raise Error(f'There is no past sales data available for {entity_name}.')
Exemplo n.º 25
0
def __get_fleet_name_and_rank(user_info: EntityInfo, fleet_info: EntityInfo = None, **kwargs) -> Optional[str]:
    result = None
    if fleet_info:
        fleet_name = fleet_info.get(fleet.FLEET_DESCRIPTION_PROPERTY_NAME, '')
        fleet_membership = user_info.get('AllianceMembership')
        fleet_rank = None
        if fleet_membership:
            fleet_rank = lookups.get_lookup_value_or_default(lookups.ALLIANCE_MEMBERSHIP, fleet_membership, default=fleet_membership)
        if fleet_name:
            result = fleet_name
            if fleet_rank:
                result += f' ({fleet_rank})'
        else:
            result = '<data error>'
    else:
        result = '<no fleet>'
    return result
Exemplo n.º 26
0
async def __get_thumbnail_url(training_info: EntityInfo, trainings_data: EntitiesData, items_data: EntitiesData, researches_data: EntitiesData, **kwargs) -> Optional[str]:
    training_sprite_id = training_info.get('TrainingSpriteId')
    sprite_id = None
    if entity.entity_property_has_value(training_sprite_id) and training_sprite_id != '454':
        sprite_id = training_sprite_id
    else:
        training_id = training_info.get(TRAINING_DESIGN_KEY_NAME)
        item_details = item.get_item_details_by_training_id(training_id, items_data, trainings_data)
        if item_details:
            item_sprite_id = item_details[0].entity_info.get('ImageSpriteId')
            if entity.entity_property_has_value(item_sprite_id):
                sprite_id = item_sprite_id
    if sprite_id:
        result = await sprites.get_download_sprite_link(sprite_id)
    else:
        result = None
    return result
Exemplo n.º 27
0
def __get_description_as_text(fleet_info: EntityInfo,
                              fleet_users_data: EntitiesData,
                              **kwargs) -> Optional[str]:
    result = None
    description = fleet_info.get('AllianceDescription')
    if description is not None:
        result = description.strip()
    return result
Exemplo n.º 28
0
def __convert_to_daily_info(dropship_info: EntityInfo) -> EntityInfo:
    result = {}
    for field_name in DAILY_INFO_FIELDS:
        value = None
        if field_name in dropship_info.keys():
            value = dropship_info[field_name]
        result[field_name] = value
    return result
Exemplo n.º 29
0
def __get_crew_card_hyperlink(character_info: EntityInfo, characters_data: EntitiesData, collections_data: EntitiesData, level: int, **kwargs) -> Optional[str]:
    crew_name: str = character_info.get(CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME)
    if crew_name:
        crew_name_escaped = utils.convert.url_escape(crew_name)
        url = f'https://pixelperfectguide.com/crew/cards/?CrewName={crew_name_escaped}'
        result = f'<{url}>'
        return result
    else:
        return None
Exemplo n.º 30
0
def __get_type(fleet_info: EntityInfo, fleet_users_data: EntitiesData,
               **kwargs) -> Optional[str]:
    result = None
    requires_approval = fleet_info.get('RequiresApproval')
    if requires_approval is not None:
        result = lookups.get_lookup_value_or_default(
            lookups.FLEET_TYPE_LOOKUP,
            requires_approval.lower() == 'true')
    return result