Пример #1
0
async def get_event_details(
        ctx: Context,
        situation_id: str = None,
        all_events: bool = False,
        latest_only: bool = False,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    has_situation_id = entity.entity_property_has_value(situation_id)
    if has_situation_id and all_events or has_situation_id and latest_only or all_events and latest_only:
        raise ValueError(
            f'Only one of these parameters may be True: situation_id, all_events, latest_only'
        )
    utc_now = utils.get_utc_now()
    situations_data = await situations_designs_retriever.get_data_dict3()
    situation_infos = sorted(situations_data.values(),
                             key=lambda x:
                             (utils.parse.pss_datetime(x['EndDate']),
                              int(x[SITUATION_DESIGN_KEY_NAME])),
                             reverse=True)

    if situation_id:
        situation_infos = [situations_data[situation_id]]
    elif all_events:
        situation_infos.reverse()
    elif latest_only:
        situation_infos = [situation_infos[0]]
    else:
        situation_infos = __get_current_situations_infos(
            situations_data.values(), utc_now)

    if not situation_infos:
        if all_events:
            raise NotFound(f'There\'s no event data.')
        else:
            raise NotFound(f'There\'s no event running currently.')
    else:
        chars_data = await crew.characters_designs_retriever.get_data_dict3()
        collections_data = await crew.collections_designs_retriever.get_data_dict3(
        )
        items_data = await item.items_designs_retriever.get_data_dict3()
        missions_data = await mission.missions_designs_retriever.get_data_dict3(
        )
        rooms_data = await room.rooms_designs_retriever.get_data_dict3()

        situations_details_collection = __create_situations_details_collection_from_infos(
            situation_infos,
            situations_data,
            chars_data,
            collections_data,
            items_data,
            missions_data,
            rooms_data,
            utc_now=utc_now)
        if as_embed:
            return (await situations_details_collection.
                    get_entities_details_as_embed(ctx))
        else:
            return (
                await
                situations_details_collection.get_entities_details_as_text())
Пример #2
0
async def get_collection_details_by_name(ctx: Context, collection_name: str, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(collection_name, parameter_name='collection_name', allow_none_or_empty=True)

    print_all = not collection_name
    collections_data = await collections_designs_retriever.get_data_dict3()
    characters_data = await characters_designs_retriever.get_data_dict3()
    collections_designs_infos = []
    if print_all:
        collections_designs_infos = collections_data.values()
    else:
        collection_info = await collections_designs_retriever.get_entity_info_by_name(collection_name, collections_data)
        if collection_info:
            collections_designs_infos.append(collection_info)

    if not collections_designs_infos:
        if print_all:
            raise Error(f'An error occured upon retrieving collection info. Please try again later.')
        else:
            raise NotFound(f'Could not find a collection named `{collection_name}`.')
    else:
        collections_designs_infos = sorted(collections_designs_infos, key=lambda x: x[COLLECTION_DESIGN_DESCRIPTION_PROPERTY_NAME])
        collections_designs_infos = collections_designs_infos if print_all else [collections_designs_infos[0]]
        collections_details_collection = __create_collections_details_collection_from_infos(collections_designs_infos, collections_data, characters_data)

        if as_embed:
            return (await collections_details_collection.get_entities_details_as_embed(ctx))
        else:
            return (await collections_details_collection.get_entities_details_as_text())
Пример #3
0
async def get_prestige_to_info(ctx: Context, char_name: str, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(char_name, 'char_name', min_length=2)

    chars_data = await characters_designs_retriever.get_data_dict3()
    char_to_info = await characters_designs_retriever.get_entity_info_by_name(char_name, chars_data)

    if not char_to_info:
        raise NotFound(f'Could not find a crew named `{char_name}`.')
    else:
        rarity = char_to_info.get('Rarity')
        if rarity in ['Common', 'Special']:
            raise PrestigeError(f'{char_to_info[CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME]} can\'t be prestiged into, due to **{rarity}** rarity.')
        prestige_to_ids, recipe_count = await __get_prestige_to_ids_and_recipe_count(char_to_info)
        utils.make_dict_value_lists_unique(prestige_to_ids)
        prestige_to_infos = sorted(__prepare_prestige_infos(chars_data, prestige_to_ids), key=lambda prestige_to_info: prestige_to_info[CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME])
        if prestige_to_infos:
            prestige_to_details_collection = __create_prestige_to_details_collection_from_infos(prestige_to_infos)

            if as_embed:
                title = f'{char_to_info[CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME]} ({recipe_count} prestige recipes)'
                thumbnail_url = await sprites.get_download_sprite_link(char_to_info['ProfileSpriteId'])
                return (await prestige_to_details_collection.get_entities_details_as_embed(ctx, custom_title=title, custom_thumbnail_url=thumbnail_url, display_inline=False))
            else:
                title = f'**{char_to_info[CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME]}** ({recipe_count} prestige recipes)'
                return (await prestige_to_details_collection.get_entities_details_as_text(custom_title=title, big_set_details_type=entity.EntityDetailsType.LONG))
        else:
            raise PrestigeNoResultsError(f'There are no prestige recipes yielding this crew: `{char_to_info.get(CHARACTER_DESIGN_DESCRIPTION_PROPERTY_NAME)}`')
Пример #4
0
async def get_ingredients_for_item(
        ctx: Context,
        item_name: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    item_infos = __get_item_infos_by_name(item_name,
                                          items_data,
                                          return_best_match=True)

    if not item_infos:
        raise NotFound(f'Could not find an item named `{item_name}`.')
    else:
        ingredients_details_collection = __create_ingredients_details_collection_from_infos(
            [item_infos[0]], items_data)
        if as_embed:
            return (
                await
                ingredients_details_collection.get_entities_details_as_embed(
                    ctx,
                    custom_footer_text=resources.get_resource(
                        'PRICE_NOTE_EMBED')))
        else:
            return (
                await
                ingredients_details_collection.get_entities_details_as_text(
                    custom_footer_text=resources.get_resource('PRICE_NOTE')))
Пример #5
0
async def get_item_upgrades_from_name(
        ctx: Context,
        item_name: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    items_ids = __get_item_design_ids_from_name(item_name, items_data)
    items_infos = __filter_destroyed_modules_from_item_infos(
        [items_data[item_id] for item_id in items_ids])

    if not items_ids or not items_infos:
        raise NotFound(
            f'Could not find an item named `{item_name}` that can be upgraded.'
        )
    else:
        upgrades_infos = []
        found_upgrades_for_data = {}
        no_upgrades_for_data = {}
        for item_id in items_ids:
            upgrades_for = __get_upgrades_for(item_id, items_data)
            upgrades_infos.extend(upgrades_for)
            if all(upgrades_for):
                found_upgrades_for_data[item_id] = items_data[item_id]
            else:
                no_upgrades_for_data[item_id] = items_data[item_id]

        if all(item_info is None for item_info in upgrades_infos):
            item_names = '\n'.join(
                sorted(
                    f'{emojis.small_orange_diamond}{item_info[ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME]}'
                    for item_info in items_infos))
            raise Error(
                f'Found the following items that can\'t be upgraded:\n{item_names}'
            )

        # Remove double entries
        upgrades_infos = list(
            dict([(item_info[ITEM_DESIGN_KEY_NAME], item_info)
                  for item_info in upgrades_infos
                  if item_info is not None]).values())
        upgrades_infos = entity.sort_entities_by(
            upgrades_infos,
            [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])
        upgrades_infos_count = len(upgrades_infos)
        upgrade_details_collection = __create_upgrade_details_collection_from_infos(
            upgrades_infos, items_data, found_upgrades_for_data,
            no_upgrades_for_data, len(upgrades_infos))

        if as_embed:
            custom_title = f'Found {upgrades_infos_count} crafting recipes requiring {item_name}'
            return (await
                    upgrade_details_collection.get_entities_details_as_embed(
                        ctx, custom_title=custom_title))
        else:
            custom_title = f'Found {upgrades_infos_count} crafting recipes requiring **{item_name}**:'
            return (await
                    upgrade_details_collection.get_entities_details_as_text(
                        custom_title=custom_title,
                        big_set_details_type=entity.EntityDetailsType.LONG))
Пример #6
0
async def get_training_details_from_name(
        training_name: str,
        ctx: Context,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(training_name)

    trainings_data = await trainings_designs_retriever.get_data_dict3()
    training_infos = await trainings_designs_retriever.get_entities_infos_by_name(
        training_name, trainings_data)

    if not training_infos:
        raise NotFound(f'Could not find a training named **{training_name}**.')
    else:
        items_data = await item.items_designs_retriever.get_data_dict3()
        researches_data = await research.researches_designs_retriever.get_data_dict3(
        )
        trainings_details_collection = __create_trainings_details_collection_from_infos(
            training_infos, trainings_data, items_data, researches_data)
        custom_footer = 'The stats displayed are chances. The actual result may be much lower depending on: max training points, training points used, the training points gained on a particular stat and fatigue.'

        if as_embed:
            return (await
                    trainings_details_collection.get_entities_details_as_embed(
                        ctx,
                        custom_detail_property_separator='\n',
                        custom_footer_text=custom_footer))
        else:
            return (await
                    trainings_details_collection.get_entities_details_as_text(
                        custom_footer_text=custom_footer))
Пример #7
0
async def get_best_items(
        ctx: Context,
        slot: str,
        stat: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_parameter_value(
        slot,
        'slot',
        allowed_values=lookups.EQUIPMENT_SLOTS_LOOKUP.keys(),
        allow_none_or_empty=True)
    pss_assert.valid_parameter_value(
        stat, 'stat', allowed_values=lookups.STAT_TYPES_LOOKUP.keys())

    items_details = await items_designs_retriever.get_data_dict3()
    error = __get_best_items_error(slot, stat)
    if error:
        raise Error(error)

    any_slot = not slot or slot in ANY_SLOT_MARKERS
    slot_filter = __get_slot_filter(slot, any_slot)
    stat_filter = __get_stat_filter(stat)
    best_items = __get_best_items_designs(slot_filter, stat_filter,
                                          items_details)

    if not best_items:
        if not any_slot:
            slot = f' for slot `{slot}`'
        raise NotFound(
            f'Could not find an item{slot} providing bonus `{stat_filter.lower()}`.'
        )
    else:
        groups = await __get_collection_groups(best_items, stat_filter,
                                               as_embed)

        result = []
        if as_embed:
            for title, best_items_collection in groups.items():
                footer = __get_footer_text_for_group(title, as_embed)
                embeds = await best_items_collection.get_entities_details_as_embed(
                    ctx, custom_title=title, custom_footer_text=footer)
                result.extend(embeds)
            return result
        else:
            module_title = None
            for title, best_items_collection in groups.items():
                if 'module' in title.lower():
                    module_title = title
                texts = await best_items_collection.get_entities_details_as_text(
                    custom_title=title)
                result.extend(texts)
                result.append(utils.discord.ZERO_WIDTH_SPACE)
            footer = __get_footer_text_for_group(module_title, as_embed)
            result.append(footer)
            return result
Пример #8
0
async def get_char_details_by_name(ctx: Context, char_name: str, level: int, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(char_name, 'char_name', min_length=2)
    pss_assert.parameter_is_valid_integer(level, 'level', min_value=1, max_value=40, allow_none=True)

    chars_data = await characters_designs_retriever.get_data_dict3()
    char_info = await characters_designs_retriever.get_entity_info_by_name(char_name, chars_data)

    if char_info is None:
        raise NotFound(f'Could not find a crew named `{char_name}`.')
    else:
        collections_data = await collections_designs_retriever.get_data_dict3()
        characters_details_collection = __create_characters_details_collection_from_infos([char_info], chars_data, collections_data, level)
        if as_embed:
            return (await characters_details_collection.get_entities_details_as_embed(ctx))
        else:
            return (await characters_details_collection.get_entities_details_as_text())
Пример #9
0
async def get_item_details_by_name(ctx: Context, item_name: str, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    item_infos = __get_item_infos_by_name(item_name, items_data)

    if not item_infos:
        raise NotFound(f'Could not find an item named `{item_name}`.')
    else:
        trainings_data = await training.trainings_designs_retriever.get_data_dict3()
        items_data_for_sort = {item_info.get(ITEM_DESIGN_KEY_NAME): item_info for item_info in item_infos}
        item_infos = sorted(item_infos, key=lambda item_info: (
            __get_key_for_base_items_sort(item_info, items_data_for_sort)
        ))
        items_details_collection = __create_base_details_collection_from_infos(item_infos, items_data, trainings_data)

        if as_embed:
            return (await items_details_collection.get_entities_details_as_embed(ctx, custom_footer_text=resources.get_resource('PRICE_NOTE_EMBED')))
        else:
            return (await items_details_collection.get_entities_details_as_text(custom_footer_text=resources.get_resource('PRICE_NOTE')))
Пример #10
0
async def get_promotions_infos_by_name(
        promotion_name: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(promotion_name, 'promotion_name')

    promotion_infos = await promotion_designs_retriever.get_entities_infos_by_name(
        promotion_name)
    promotions_details = [
        LegacyPromotionDesignDetails(promotion_info)
        for promotion_info in promotion_infos
        if promotion_info['PromotionType'] == 'FirstPurchase'
    ]

    if not promotions_details:
        raise NotFound(f'Could not find a promotion named `{promotion_name}`.')
    else:
        if as_embed:
            return _get_promotions_details_as_embed(promotions_details)
        else:
            return _get_promotions_details_as_text(promotion_name,
                                                   promotions_details)
Пример #11
0
async def get_entity_details_by_name(
        ctx: Context,
        entity_name: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(entity_name, 'entity_name')

    entities_data = await entities_designs_retriever.get_data_dict3()
    entity_info = await entities_designs_retriever.get_entity_info_by_name(
        entity_name, entities_data)

    if entity_info is None:
        raise NotFound(f'Could not find an entity named `{entity_name}`.')
    else:
        entities_details_collection = __create_entities_details_collection_from_infos(
            [entity_info], entities_data)
        if as_embed:
            return (
                await
                entities_details_collection.get_entities_details_as_embed(ctx))
        else:
            return (await
                    entities_details_collection.get_entities_details_as_text())
Пример #12
0
async def get_item_price(ctx: Context, item_name: str, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    item_infos = __get_item_infos_by_name(item_name, items_data)

    if not item_infos:
        raise NotFound(f'Could not find an item named `{item_name}`.')
    else:
        get_best_match = utils.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 = entity.sort_entities_by(item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])
        items_details_collection = __create_price_details_collection_from_infos(item_infos, items_data)

        if as_embed:
            custom_footer = '\n'.join([resources.get_resource('MARKET_FAIR_PRICE_NOTE_EMBED'), resources.get_resource('PRICE_NOTE_EMBED')])
            return (await items_details_collection.get_entities_details_as_embed(ctx, custom_footer_text=custom_footer))
        else:
            custom_footer = '\n'.join([resources.get_resource('MARKET_FAIR_PRICE_NOTE'), resources.get_resource('PRICE_NOTE')])
            return (await items_details_collection.get_entities_details_as_text())
Пример #13
0
async def get_research_infos_by_name(research_name: str, ctx: Context, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(research_name)

    researches_data = await researches_designs_retriever.get_data_dict3()
    researches_designs_infos = await researches_designs_retriever.get_entities_infos_by_name(research_name, entities_data=researches_data, sorted_key_function=__get_key_for_research_sort)

    if not researches_designs_infos:
        raise NotFound(f'Could not find a research named **{research_name}**.')
    else:
        exact_match_details = None
        exact_research_info = None
        big_set_threshold = BIG_SET_THRESHOLD
        if len(researches_designs_infos) >= big_set_threshold:
            lower_research_name = research_name.strip().lower()
            for research_design_info in researches_designs_infos:
                if research_design_info.get(RESEARCH_DESIGN_DESCRIPTION_PROPERTY_NAME, '').lower() == lower_research_name:
                    exact_research_info = research_design_info
                    break

        if exact_research_info:
            researches_designs_infos = [research_design_info for research_design_info in researches_designs_infos if research_design_info[RESEARCH_DESIGN_KEY_NAME] != exact_research_info[RESEARCH_DESIGN_KEY_NAME]]
            exact_match_details = __create_research_details_from_info(exact_research_info, researches_data)
            big_set_threshold -= 1
        researches_details = __create_researches_details_collection_from_infos(researches_designs_infos, researches_data)

        result = []
        if as_embed:
            if exact_match_details:
                result.append(await exact_match_details.get_details_as_embed(ctx))
            result.extend(await researches_details.get_entities_details_as_embed(ctx, big_set_threshold=big_set_threshold))
        else:
            if exact_match_details:
                result.extend(await exact_match_details.get_details_as_text(details_type=entity.EntityDetailsType.LONG))
                result.append(utils.discord.ZERO_WIDTH_SPACE)
            result.extend(await researches_details.get_entities_details_as_text(big_set_threshold=big_set_threshold))
        return result