Ejemplo n.º 1
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
Ejemplo n.º 2
0
async def get_promotions_designs_info_by_name(
        promotion_name: str, as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(promotion_name, 'promotion_name')

    promotion_design_infos = await promotion_designs_retriever.get_entities_designs_infos_by_name(
        promotion_name)
    promotions_designs_details = [
        LegacyPromotionDesignDetails(promotion_design_info)
        for promotion_design_info in promotion_design_infos
        if promotion_design_info['PromotionType'] == 'FirstPurchase'
    ]

    if not promotions_designs_details:
        return [f'Could not find a promotion named **{promotion_name}**.'
                ], False
    else:
        if as_embed:
            return _get_promotions_details_as_embed(
                promotions_designs_details), True
        else:
            return _get_promotions_details_as_text(
                promotion_name, promotions_designs_details), True
Ejemplo n.º 3
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())
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
async def get_room_details_from_name(
        room_name: str,
        as_embed: bool = settings.USE_EMBEDS
) -> Union[List[str], discord.Embed]:
    pss_assert.valid_entity_name(room_name,
                                 allowed_values=__allowed_room_names)

    rooms_designs_data = await rooms_designs_retriever.get_data_dict3()
    room_infos = _get_room_infos(room_name, rooms_designs_data)

    if not room_infos:
        return [f'Could not find a room named **{room_name}**.'], False
    else:
        items_designs_data = await item.items_designs_retriever.get_data_dict3(
        )
        if as_embed:
            return _get_room_info_as_embed(room_name, room_infos,
                                           rooms_designs_data,
                                           items_designs_data), True
        else:
            return (await _get_room_info_as_text(room_name, room_infos,
                                                 rooms_designs_data,
                                                 items_designs_data)), True
Ejemplo n.º 6
0
async def get_ingredients_for_item(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,
                                         return_best_match=True)

    if not item_infos:
        return [f'Could not find an item named **{item_name}**.'], False
    else:
        item_info = item_infos[0]
        item_name = item_info[ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME]
        ingredients_tree = _parse_ingredients_tree(item_info['Ingredients'],
                                                   items_designs_data)
        ingredients_dicts = _flatten_ingredients_tree(ingredients_tree)
        if as_embed:
            return _get_item_ingredients_as_embed(item_name, ingredients_dicts,
                                                  items_designs_data), True
        else:
            return _get_item_ingredients_as_text(item_name, ingredients_dicts,
                                                 items_designs_data), True
Ejemplo n.º 7
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
Ejemplo n.º 8
0
async def get_training_details_from_name(training_name: str,
                                         as_embed: bool = settings.USE_EMBEDS):
    pss_assert.valid_entity_name(training_name)

    training_infos = await trainings_designs_retriever.get_entities_designs_infos_by_name(
        training_name)
    items_designs_data = await item.items_designs_retriever.get_data_dict3()
    researches_designs_data = await research.researches_designs_retriever.get_data_dict3(
    )
    trainings_details = [
        LegacyTrainingDetails(training_info, items_designs_data,
                              researches_designs_data)
        for training_info in training_infos
    ]

    if not training_infos:
        return [f'Could not find a training named **{training_name}**.'], False
    else:
        if as_embed:
            return _get_training_info_as_embed(training_name,
                                               trainings_details), True
        else:
            return _get_training_info_as_text(training_name,
                                              trainings_details), True
Ejemplo n.º 9
0
async def get_research_infos_by_name(
    research_name: str,
    ctx: commands.Context,
    as_embed: bool = settings.USE_EMBEDS
) -> Union[List[str], List[discord.Embed]]:
    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:
        return [f'Could not find a research named **{research_name}**.'], False
    else:
        researches_details = __create_researches_details_collection_from_infos(
            researches_designs_infos, researches_data)
        if as_embed:
            return (await
                    researches_details.get_entity_details_as_embed(ctx)), True
        else:
            return (await
                    researches_details.get_entity_details_as_text()), True
Ejemplo n.º 10
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')
                    ))
Ejemplo n.º 11
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
Ejemplo n.º 12
0
def get_promotions_details_by_name(
        promotion_name: str) -> entity.EntityDetailsCollection:
    pss_assert.valid_entity_name(promotion_name, 'promotion_name')