Exemplo n.º 1
0
def get_level_costs(ctx: commands.Context, from_level: int, to_level: int = None, as_embed: bool = settings.USE_EMBEDS) -> Union[List[str], List[discord.Embed]]:
    # If to_level: assert that to_level > from_level and <= 41
    # Else: swap both, set from_level = 1
    if to_level:
        pss_assert.parameter_is_valid_integer(from_level, 'from_level', 1, to_level - 1)
        pss_assert.parameter_is_valid_integer(to_level, 'to_level', from_level + 1, 40)
    else:
        pss_assert.parameter_is_valid_integer(from_level, 'from_level', 2, 40)
        to_level = from_level
        from_level = 1

    crew_costs = _get_crew_costs(from_level, to_level, lookups.GAS_COSTS_LOOKUP, lookups.XP_COSTS_LOOKUP)
    legendary_crew_costs = _get_crew_costs(from_level, to_level, lookups.GAS_COSTS_LEGENDARY_LOOKUP, lookups.XP_COSTS_LEGENDARY_LOOKUP)

    crew_cost_txt = _get_crew_cost_txt(from_level, to_level, crew_costs)
    legendary_crew_cost_txt = _get_crew_cost_txt(from_level, to_level, legendary_crew_costs)

    if as_embed:
        embed_color = util.get_bot_member_colour(ctx.bot, ctx.guild)
        fields = [
            ('Non-legendary crew', '\n'.join(crew_cost_txt), False),
            ('Legendary crew', '\n'.join(legendary_crew_cost_txt), False)
        ]
        result = [util.create_embed(title='Level costs', fields=fields, colour=embed_color, footer='Note: Gas costs are higher, if "Advanced Training 7" hasn\'t been reseached, yet.')]
    else:
        result = ['**Level costs** (non-legendary crew, max research)']
        result.extend(crew_cost_txt)
        result.append(settings.EMPTY_LINE)
        result.append('**Level costs** (legendary crew, max research)')
        result.extend(legendary_crew_cost_txt)
        result.append(settings.EMPTY_LINE)
        result.append('**Note:** Gas costs are higher, if **Advanced Training 7** hasn\'t been reseached, yet.')
    return result, True
Exemplo n.º 2
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
Exemplo n.º 3
0
    async def __create_base_embed(self,
                                  ctx: commands.Context) -> discord.Embed:
        title = await self._get_title(details_type=EntityDetailsType.EMBED)
        description = await self._get_description(
            details_type=EntityDetailsType.EMBED)

        embed_settings = await self.get_embed_settings()
        colour = embed_settings.get(
            'color',
            embed_settings.get('colour',
                               util.get_bot_member_colour(ctx.bot, ctx.guild)))
        author_url = embed_settings.get('author_url')
        icon_url = embed_settings.get('icon_url')
        image_url = embed_settings.get('image_url')
        thumbnail_url = embed_settings.get('thumbnail_url')
        timestamp = embed_settings.get('timestamp')
        footer = embed_settings.get('footer')
        result = util.create_embed(title=title,
                                   description=description,
                                   colour=colour,
                                   footer=footer,
                                   thumbnail_url=thumbnail_url,
                                   image_url=image_url,
                                   icon_url=icon_url,
                                   author_url=author_url,
                                   timestamp=timestamp)
        return result
Exemplo n.º 4
0
async def tournament_next(ctx):
    """Get information about the time of next month's tournament."""
    async with ctx.typing():
        utc_now = util.get_utcnow()
        start_of_tourney = tourney.get_next_tourney_start()
        embed_colour = util.get_bot_member_colour(bot, ctx.guild)
        embed = tourney.embed_tourney_start(start_of_tourney, utc_now,
                                            embed_colour)
    await ctx.send(embed=embed)
Exemplo n.º 5
0
async def _get_news_details_as_embed(ctx: commands.Context, news_info: dict) -> discord.Embed:
    title = news_info['Title']
    description = util.escape_escape_sequences(news_info['Description'])
    while '\n\n' in description:
        description = description.replace('\n\n', '\n')
    sprite_url = await sprites.get_download_sprite_link(news_info['SpriteId'])
    timestamp = util.parse_pss_datetime(news_info['UpdateDate'])
    colour = util.get_bot_member_colour(ctx.bot, ctx.guild)
    link = news_info['Link'].strip()
    if link:
        fields = [('Link', link, False)]
    else:
        fields = []
    result = util.create_embed(title, description=description, image_url=sprite_url, colour=colour, footer='PSS News', timestamp=timestamp, fields=fields)
    return result
Exemplo n.º 6
0
async def get_dropship_text(bot: commands.Bot = None, guild: discord.Guild = None, daily_info: dict = None, utc_now: datetime = None, language_key: str = 'en') -> Tuple[List[str], List[discord.Embed], bool]:
    utc_now = utc_now or util.get_utcnow()
    if not daily_info:
        daily_info = await core.get_latest_settings(language_key=language_key)

    collections_designs_data = await crew.collections_designs_retriever.get_data_dict3()
    chars_designs_data = await crew.characters_designs_retriever.get_data_dict3()
    items_designs_data = await item.items_designs_retriever.get_data_dict3()
    rooms_designs_data = await room.rooms_designs_retriever.get_data_dict3()
    trainings_designs_data = await training.trainings_designs_retriever.get_data_dict3()

    try:
        daily_msg = _get_daily_news_from_data_as_text(daily_info)
        dropship_msg = await _get_dropship_msg_from_data_as_text(daily_info, chars_designs_data, collections_designs_data)
        merchantship_msg = await _get_merchantship_msg_from_data_as_text(daily_info, items_designs_data, trainings_designs_data)
        shop_msg = await _get_shop_msg_from_data_as_text(daily_info, chars_designs_data, collections_designs_data, items_designs_data, rooms_designs_data, trainings_designs_data)
        sale_msg = await _get_sale_msg_from_data_as_text(daily_info, chars_designs_data, collections_designs_data, items_designs_data, rooms_designs_data, trainings_designs_data)
        daily_reward_msg = await _get_daily_reward_from_data_as_text(daily_info, items_designs_data, trainings_designs_data)
    except Exception as e:
        pp = pprint.PrettyPrinter(indent=4)
        pp.pprint(daily_info)
        print(e)
        return [], False

    parts = [dropship_msg, merchantship_msg, shop_msg, sale_msg, daily_reward_msg]

    lines = list(daily_msg)
    for part in parts:
        lines.append(settings.EMPTY_LINE)
        lines.extend(part)

    title = 'Pixel Starships Dropships'
    footer = f'Star date {util.get_star_date(utc_now)}'
    description = ''.join(daily_msg)
    fields = [(part[0], '\n'.join(part[1:]), False) for part in parts]
    sprite_url = await sprites.get_download_sprite_link(daily_info['NewsSpriteId'])
    colour = util.get_bot_member_colour(bot, guild)
    embed = util.create_embed(title, description=description, fields=fields, image_url=sprite_url, colour=colour, footer=footer)

    return lines, [embed], True
Exemplo n.º 7
0
async def get_top_captains(ctx: commands.Context,
                           take: int = 100,
                           as_embed: bool = settings.USE_EMBEDS):
    skip = 0
    data = await __get_top_captains_dict(skip, take)

    if data:
        title = f'Top {take} captains'
        prepared_data = __prepare_top_captains(data, skip, take)
        body_lines = __create_body_lines_top_captains(prepared_data)

        if as_embed:
            colour = util.get_bot_member_colour(ctx.bot, ctx.guild)
            result = __create_top_embeds(title, body_lines, colour)
        else:
            result = [f'**{title}**']
            result.extend(body_lines)
        return result, True
    else:
        return [
            'An unknown error occured while retrieving the top captains. Please contact the bot\'s author!'
        ], False
Exemplo n.º 8
0
async def get_top_fleets(ctx: commands.Context,
                         take: int = 100,
                         as_embed: bool = settings.USE_EMBEDS):
    tourney_running = tourney.is_tourney_running()
    raw_data = await core.get_data_from_path(TOP_FLEETS_BASE_PATH + str(take))
    data = core.xmltree_to_dict3(raw_data)
    if data:
        title = f'Top {take} fleets'
        prepared_data = __prepare_top_fleets(data)
        body_lines = __create_body_lines_top_fleets(prepared_data,
                                                    tourney_running)

        if as_embed:
            colour = util.get_bot_member_colour(ctx.bot, ctx.guild)
            return __create_top_embeds(title, body_lines, colour), True
        else:
            result = [f'**{title}**']
            result.extend(body_lines)
            return result, True
    else:
        return [
            'An unknown error occured while retrieving the top fleets. Please contact the bot\'s author!'
        ], False
Exemplo n.º 9
0
    async def get_entity_details_as_embed(
            self,
            ctx: commands.Context,
            custom_detail_property_separator: str = None,
            custom_title: str = None,
            custom_footer_text: str = None,
            custom_thumbnail_url: str = None,
            display_inline: bool = True) -> List[discord.Embed]:
        """
        custom_title: only relevant for big sets
        """
        result = []
        display_names = []
        if self.__is_big_set:
            detail_property_separator = custom_detail_property_separator if custom_detail_property_separator is not None else DEFAULT_DETAILS_PROPERTIES_SEPARATOR
            title = custom_title or discord.Embed.Empty
            colour = util.get_bot_member_colour(ctx.bot, ctx.guild)
            display_names = await self.__entities_details[0].get_display_names(
                True, EntityDetailsType.SHORT)
            fields = []
            for entity_details in self.__entities_details:
                entity_title, _, entity_details_properties = await entity_details.get_full_details(
                    True, EntityDetailsType.SHORT)
                details = detail_property_separator.join([
                    detail.get_text(DEFAULT_DETAIL_PROPERTY_SHORT_SEPARATOR,
                                    suppress_display_name=True,
                                    force_value=True)
                    for detail in entity_details_properties
                ])
                fields.append((entity_title, details, display_inline))

            footer = ''
            if display_names:
                footer = 'Properties displayed:   '
                footer += DEFAULT_DETAILS_PROPERTIES_SEPARATOR.join(
                    display_names)
            if custom_footer_text:
                if footer:
                    footer += '\n\n'
                footer += custom_footer_text

            while (len(fields) > 25):
                embed = util.create_embed(title,
                                          colour=colour,
                                          fields=fields[:25],
                                          footer=footer)
                result.append(embed)
                fields = fields[25:]

            embed = util.create_embed(title,
                                      colour=colour,
                                      fields=fields,
                                      footer=footer,
                                      thumbnail_url=custom_thumbnail_url)
            result.append(embed)
        else:
            for entity_details in self.__entities_details:
                embed = await entity_details.get_details_as_embed(ctx)
                if custom_footer_text:
                    embed.set_footer(text=custom_footer_text)
                result.append(embed)
        return result
Exemplo n.º 10
0
async def get_division_stars(ctx: commands.Context,
                             division: str = None,
                             fleet_data: dict = None,
                             retrieved_date: datetime = None,
                             as_embed: bool = settings.USE_EMBEDS):
    if division:
        pss_assert.valid_parameter_value(
            division,
            'division',
            min_length=1,
            allowed_values=ALLOWED_DIVISION_LETTERS)
        if division == '-':
            division = None
    else:
        division = None

    if fleet_data is None or retrieved_date is None:
        data = await core.get_data_from_path(STARS_BASE_PATH)
        fleet_infos = core.xmltree_to_dict3(data)
    else:
        fleet_infos = fleet_data

    divisions_designs_infos = await divisions_designs_retriever.get_data_dict3(
    )

    divisions = {}
    if division:
        division_design_id = lookups.DIVISION_CHAR_TO_DESIGN_ID[
            division.upper()]
        divisions[division_design_id] = [
            fleet_info for fleet_info in fleet_infos.values()
            if fleet_info[DIVISION_DESIGN_KEY_NAME] == division_design_id
        ]
        pass
    else:
        for division_design_id in lookups.DIVISION_DESIGN_ID_TO_CHAR.keys():
            if division_design_id != '0':
                divisions[division_design_id] = [
                    fleet_info for fleet_info in fleet_infos.values() if
                    fleet_info[DIVISION_DESIGN_KEY_NAME] == division_design_id
                ]

    if divisions:
        divisions_texts = []
        for division_design_id, fleet_infos in divisions.items():
            divisions_texts.append(
                (division_design_id, _get_division_stars_as_text(fleet_infos)))

        result = []
        footer = util.get_historic_data_note(retrieved_date)
        colour = util.get_bot_member_colour(ctx.bot, ctx.guild)
        for division_design_id, division_text in divisions_texts:
            if as_embed:
                division_title = _get_division_title(division_design_id,
                                                     divisions_designs_infos,
                                                     False)
                thumbnail_url = await sprites.get_download_sprite_link(
                    divisions_designs_infos[division_design_id]
                    ['BackgroundSpriteId'])
                embed_bodies = util.create_posts_from_lines(
                    division_text,
                    settings.MAXIMUM_CHARACTERS_EMBED_DESCRIPTION)
                for i, embed_body in enumerate(embed_bodies):
                    thumbnail_url = thumbnail_url if i == 0 else None
                    embed = util.create_embed(division_title,
                                              description=embed_body,
                                              footer=footer,
                                              thumbnail_url=thumbnail_url,
                                              colour=colour)
                    result.append(embed)
            else:
                division_title = _get_division_title(division_design_id,
                                                     divisions_designs_infos,
                                                     True)
                result.append(division_title)
                result.extend(division_text)
                result.append(settings.EMPTY_LINE)

        if not as_embed:
            result = result[:-1]
            if footer:
                result.append(f'```{footer}```')

        return result, True
    else:
        return [
            f'An unknown error occured while retrieving division info. Please contact the bot\'s author!'
        ], False