Esempio n. 1
0
async def get_ship_builder_links(
        ctx: Context,
        user_info: entity.EntityInfo,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    user_info, user_ship_info = await get_inspect_ship_for_user(
        user_info[user.USER_KEY_NAME])
    ship_design_id = user_ship_info[SHIP_DESIGN_KEY_NAME]
    ships_designs_data = await ships_designs_retriever.get_data_dict3()
    ship_design_info = ships_designs_data[ship_design_id]
    rooms = '-'.join([
        ','.join((ship_room_info['Column'], ship_room_info['Row'],
                  ship_room_info[room.ROOM_DESIGN_KEY_NAME]))
        for ship_room_info in user_ship_info['Rooms'].values()
    ])
    query_params = f'ship={ship_design_id}&rooms={rooms}'
    pixel_prestige_link = f'{SHIP_BUILDER_PIXEL_PRESTIGE_BASE_PATH}{query_params}'
    pixyship_link = f'{SHIP_BUILDER_PIXYSHIP_BASE_PATH}{query_params}'
    ship_builder_links = [('Pixel Prestige builder', pixel_prestige_link),
                          ('Pixyship builder', pixyship_link)]
    fields = []
    fleet_name = user_info.get(fleet.FLEET_DESCRIPTION_PROPERTY_NAME)
    if entity.entity_property_has_value(fleet_name):
        fields.append(('Fleet', escape_markdown(fleet_name), False))
    fields += [
        ('Trophies', user_info['Trophy'], None),
        ('Ship',
         f'{ship_design_info["ShipDesignName"]} (level {ship_design_info["ShipLevel"]})',
         None),
    ]
    post_title = user_info[user.USER_DESCRIPTION_PROPERTY_NAME]
    if as_embed:
        miniship_sprite_url = await sprites.get_download_sprite_link(
            ship_design_info.get('MiniShipSpriteId'))
        user_pin_sprite_url = await sprites.get_download_sprite_link(
            user_info.get('IconSpriteId'))
        colour = utils.discord.get_bot_member_colour(ctx.bot, ctx.guild)
        result = utils.discord.create_basic_embeds_from_fields(
            post_title,
            fields=fields,
            colour=colour,
            thumbnail_url=miniship_sprite_url,
            icon_url=user_pin_sprite_url)
        for title, link in ship_builder_links:
            result.append(
                utils.discord.create_embed(post_title,
                                           description=f'[{title}]({link})',
                                           colour=colour,
                                           thumbnail_url=miniship_sprite_url,
                                           icon_url=user_pin_sprite_url))
    else:
        for title, link in ship_builder_links:
            fields.append((title, f'<{link}>', None))
        result = [
            f'{key}{entity.DEFAULT_DETAIL_PROPERTY_LONG_SEPARATOR}{value}'
            for key, value, _ in fields
        ]
        result.insert(
            0, f'**Ship builder links for {escape_markdown(post_title)}**')
    return result
Esempio n. 2
0
def __get_trophies_as_text(user_info: entity.EntityInfo) -> 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
Esempio n. 3
0
def __get_name(fleet_info: entity.EntityInfo) -> 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
Esempio n. 4
0
def __get_tourney_battle_attempts(user_info: entity.EntityInfo, utc_now: datetime) -> int:
    attempts = user_info.get('TournamentBonusScore')
    if attempts:
        attempts = int(attempts)
        last_login_date = util.parse_pss_datetime(user_info.get('LastLoginDate'))
        if last_login_date:
            if last_login_date.day != utc_now.day:
                attempts = 0
    return attempts
Esempio n. 5
0
def __get_league_as_text(user_info: entity.EntityInfo) -> 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
Esempio n. 6
0
def __get_user_name_as_text(user_info: entity.EntityInfo) -> 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
Esempio n. 7
0
def get_division_name_as_text(fleet_info: entity.EntityInfo) -> str:
    result = None
    if fleet_info:
        division_design_id = fleet_info.get(top.DIVISION_DESIGN_KEY_NAME)
        if division_design_id is not None and division_design_id != '0':
            result = lookups.get_lookup_value_or_default(lookups.DIVISION_DESIGN_ID_TO_CHAR, division_design_id, default='-')
    return result
Esempio n. 8
0
def __get_prestige_to_title(character_info: entity.EntityInfo, for_embed: bool = None, **kwargs) -> 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
Esempio n. 9
0
def __get_embed_color(collection_info: entity.EntityInfo, collections_data: entity.EntitiesData, characters_data: entity.EntitiesData, **kwargs) -> discord.Color:
    color_string = collection_info.get('ColorString')
    if entity.has_value(color_string):
        result = util.convert_color_string_to_embed_color(color_string)
    else:
        result = discord.Embed.Empty
    return result
Esempio n. 10
0
def __get_pixel_prestige_hyperlink(character_info: entity.EntityInfo, characters_data: entity.EntitiesData, collections_data: entity.EntitiesData, level: int, **kwargs) -> 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
Esempio n. 11
0
def __get_stars_as_text(user_info: entity.EntityInfo, is_in_tourney_fleet: bool, attempts_left: int = None) -> str:
    result = None
    stars = user_info.get('AllianceScore')
    if is_in_tourney_fleet or (stars is not None and stars != '0'):
        result = stars
        if attempts_left is not None and is_in_tourney_fleet:
            result += f' ({attempts_left} attempts left)'
    return result
Esempio n. 12
0
def __get_fleet_name_and_rank_as_text(user_info: entity.EntityInfo, fleet_info: entity.EntityInfo) -> 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
Esempio n. 13
0
def __get_trophies(fleet_info: entity.EntityInfo, fleet_users_infos: entity.EntitiesData) -> str:
    result = None
    member_count = fleet_info.get('Trophy')
    if member_count is not None:
        result = member_count
    else:
        result = sum(int(user_info.get('Trophy', '0')) for user_info in fleet_users_infos.values())
    return result
Esempio n. 14
0
def __get_member_count(fleet_info: entity.EntityInfo, fleet_users_infos: entity.EntitiesData) -> str:
    result = None
    member_count = fleet_info.get('NumberOfMembers')
    if member_count is not None:
        result = member_count
    else:
        result = len(fleet_users_infos)
    return result
Esempio n. 15
0
def __get_crew_card_hyperlink(character_info: entity.EntityInfo, characters_data: entity.EntitiesData, collections_data: entity.EntitiesData, level: int, **kwargs) -> str:
    crew_name: str = character_info.get(CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME)
    if crew_name:
        crew_name_escaped = util.url_escape(crew_name)
        url = f'https://pixelperfectguide.com/crew/cards/?CrewName={crew_name_escaped}'
        result = f'<{url}>'
        return result
    else:
        return None
Esempio n. 16
0
def __get_stars(fleet_info: entity.EntityInfo, fleet_users_infos: dict = None, max_tourney_battle_attempts: int = None, retrieved_at: datetime = None) -> str:
    result = None
    stars = fleet_info.get('Score')
    if stars is not None and stars != '0':
        result = stars
        if max_tourney_battle_attempts is not None and fleet_users_infos and retrieved_at:
            attempts_left = sum([max_tourney_battle_attempts - user.__get_tourney_battle_attempts(user_info, retrieved_at) for user_info in fleet_users_infos.values()])
            result += f' ({attempts_left} attempts left)'
    return result
Esempio n. 17
0
def __get_division_name_and_ranking_as_text(fleet_info: entity.EntityInfo) -> str:
    result = None
    division_name = get_division_name_as_text(fleet_info)
    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' ({util.get_ranking(division_ranking)})'
    return result
Esempio n. 18
0
File: pss_raw.py Progetto: Lnic/YaDc
def __flatten_raw_entity(entity_info: entity.EntityInfo) -> dict:
    result = {}
    for field_name, field in entity_info.items():
        if __should_include_raw_field(field):
            if isinstance(field, dict):
                for sub_field_name, sub_field in field.items():
                    result[f'{field_name}.{sub_field_name}'] = sub_field
            else:
                result[field_name] = field
    return result
Esempio n. 19
0
async def __get_thumbnail_url(training_info: entity.EntityInfo,
                              trainings_data: entity.EntitiesData,
                              items_data: entity.EntitiesData,
                              researches_data: entity.EntitiesData,
                              **kwargs) -> str:
    training_sprite_id = training_info.get('TrainingSpriteId')
    sprite_id = None
    if entity.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.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
Esempio n. 20
0
async def make_ship_layout_sprite(file_name_prefix: str, user_ship_info: entity.EntityInfo, ship_design_info: entity.EntityInfo, rooms_designs_data: entity.EntitiesData, rooms_designs_sprites_ids: Dict[str, str]) -> str:
    user_id = user_ship_info['UserId']

    brightness_value = float(user_ship_info.get('BrightnessValue', '0'))
    hue_value = float(user_ship_info.get('HueValue', '0'))
    saturation_value = float(user_ship_info.get('SaturationValue', '0'))

    interior_sprite_id = ship_design_info['InteriorSpriteId']
    interior_sprite = await sprites.load_sprite(interior_sprite_id)
    interior_sprite = sprites.enhance_sprite(interior_sprite, brightness=brightness_value, hue=hue_value, saturation=saturation_value)

    interior_grid_sprite = await sprites.load_sprite_from_disk(interior_sprite_id, suffix='grids')
    if not interior_grid_sprite:
        interior_grid_sprite = make_interior_grid_sprite(ship_design_info, interior_sprite.width, interior_sprite.height)
    interior_sprite.paste(interior_grid_sprite, (0, 0), interior_grid_sprite)

    room_frame_sprite_id = ship_design_info.get('RoomFrameSpriteId')
    door_frame_left_sprite_id = ship_design_info.get('DoorFrameLeftSpriteId')
    door_frame_right_sprite_id = ship_design_info.get('DoorFrameRightSpriteId')

    rooms_sprites_cache = {}
    rooms_decorations_sprites_cache = {}
    for ship_room_info in user_ship_info['Rooms'].values():
        room_design_id = ship_room_info[room.ROOM_DESIGN_KEY_NAME]
        room_under_construction = 1 if ship_room_info.get('RoomStatus') == 'Upgrading' or entity.entity_property_has_value(ship_room_info.get('ConstructionStartDate')) else 0

        room_sprite = rooms_sprites_cache.get(room_design_id, {}).get(room_under_construction)

        if not room_sprite:
            room_design_info = rooms_designs_data[room_design_id]
            room_size = (int(room_design_info['Columns']), int(room_design_info['Rows']))

            if room_size == (1, 1):
                room_decoration_sprite = None
            else:
                room_decoration_sprite = rooms_decorations_sprites_cache.get(room_frame_sprite_id, {}).get(door_frame_left_sprite_id, {}).get(room_size)
                if not room_decoration_sprite:
                    room_decoration_sprite = await room.get_room_decoration_sprite(room_frame_sprite_id, door_frame_left_sprite_id, door_frame_right_sprite_id, room_size[0], room_size[1])
                    rooms_decorations_sprites_cache.setdefault(room_frame_sprite_id, {}).setdefault(door_frame_left_sprite_id, {}).setdefault(door_frame_right_sprite_id, {})[room_size] = room_decoration_sprite

            room_sprite_id = room.get_room_sprite_id(room_design_info, room_under_construction, room_decoration_sprite is not None, rooms_designs_sprites_ids)
            room_sprite = await room.create_room_sprite(room_sprite_id, room_decoration_sprite, room_design_info, brightness_value, hue_value, saturation_value)
            rooms_sprites_cache.setdefault(room_design_id, {})[room_under_construction] = room_sprite
        interior_sprite.paste(room_sprite, (int(ship_room_info['Column']) * sprites.TILE_SIZE, int(ship_room_info['Row']) * sprites.TILE_SIZE))

    file_path = sprites.save_sprite(interior_sprite, f'{file_name_prefix}_{user_id}_layout')
    return file_path
Esempio n. 21
0
def __parse_timestamp(user_info: entity.EntityInfo, field_name: str) -> str:
    result = None
    timestamp = user_info.get(field_name)
    if timestamp is not None:
        result = util.parse_pss_datetime(timestamp)
    return result
Esempio n. 22
0
def __get_user_type_as_text(user_info: entity.EntityInfo) -> 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
Esempio n. 23
0
def __get_ranking_as_text(fleet_info: entity.EntityInfo) -> str:
    result = None
    ranking = fleet_info.get('Ranking')
    if ranking is not None and ranking != '0':
        result = util.get_ranking(ranking)
    return result
Esempio n. 24
0
def __get_type_as_text(fleet_info: entity.EntityInfo) -> 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
Esempio n. 25
0
def is_tournament_fleet(fleet_info: entity.EntityInfo) -> bool:
    try:
        division_design_id = int(fleet_info.get(top.DIVISION_DESIGN_KEY_NAME, '0'))
        return division_design_id > 0
    except:
        return False
Esempio n. 26
0
def __get_ship_status_as_text(ship_info: entity.EntityInfo) -> str:
    result = None
    ship_status = ship_info.get('ShipStatus')
    if ship_status is not None:
        result = lookups.get_lookup_value_or_default(lookups.USER_STATUS, ship_status, default=ship_status)
    return result
Esempio n. 27
0
def __get_description_as_text(fleet_info: entity.EntityInfo) -> str:
    result = None
    description = fleet_info.get('AllianceDescription')
    if description is not None:
        result = description.strip()
    return result
Esempio n. 28
0
async def __get_fleet_info_by_user_info(user_info: entity.EntityInfo) -> entity.EntityInfo:
    result = {}
    fleet_id = user_info.get('AllianceId', '0')
    if fleet_id != '0':
        result = await fleet._get_fleet_info_by_id(fleet_id)
    return result
Esempio n. 29
0
def __get_crew_donated_as_text(user_info: entity.EntityInfo, fleet_info: entity.EntityInfo) -> str:
    result = None
    if fleet_info:
        result = user_info.get('CrewDonated')
    return result
Esempio n. 30
0
def __get_crew_borrowed_as_text(user_info: entity.EntityInfo, fleet_info: entity.EntityInfo) -> str:
    result = None
    if fleet_info:
        result = user_info.get('CrewReceived')
    return result