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
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
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
def __get_user_type_as_text(user_info: entity.EntityDesignInfo) -> 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
def get_division_name(division_design_id: time.strftime) -> str: result = None 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
def __get_type_as_text(fleet_info: entity.EntityDesignInfo) -> 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
def __get_ship_status_as_text(ship_info: entity.EntityDesignInfo) -> 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
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
async def __get_merchantship_msg_from_info_as_text( daily_info: EntityInfo, items_data: EntitiesData, trainings_data: EntitiesData) -> List[str]: result = [f'{emojis.pss_merchantship} **Merchant ship**'] if daily_info: cargo_items = daily_info['CargoItems'].split('|') cargo_prices = daily_info['CargoPrices'].split('|') for i, cargo_info in enumerate(cargo_items): _, item_id, amount, _ = utils.parse.entity_string(cargo_info) if item_id: item_details = item.get_item_details_by_id( item_id, items_data, trainings_data) item_details = ''.join(await item_details.get_details_as_text( entity.EntityDetailsType.SHORT)) currency_type, currency_id, currency_amount, _ = utils.parse.entity_string( cargo_prices[i]) currency_type = currency_type.lower() if 'item' in currency_type: key = f'item{currency_id}' currency = lookups.get_lookup_value_or_default( lookups.CURRENCY_EMOJI_LOOKUP, key) if not currency: currency_item_details = item.get_item_details_by_id( currency_id, items_data, trainings_data) currency = ''.join( await currency_item_details.get_details_as_text( entity.EntityDetailsType.MINI)) else: currency_amount = currency_id currency = lookups.get_lookup_value_or_default( lookups.CURRENCY_EMOJI_LOOKUP, currency_type, default=currency_type) result.append( f'{amount} x {item_details}: {currency_amount} {currency}') else: result.append('-') return result
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
async def get_fleet_users_stars_from_info( ctx: Context, fleet_info: EntityInfo, fleet_users_infos: EntitiesData, max_tourney_battle_attempts: int, retrieved_at: datetime = None, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]: utc_now = utils.get_utc_now() 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 = entity.sort_entities_by( list(fleet_users_infos.values()), [('AllianceScore', int, True), (USER_KEY_NAME, int, False)]) fleet_users_infos_count = len(fleet_users_infos) title = f'{fleet_name} member stars (division {division})' display_attempts = False lines = [] for i, user_info in enumerate(fleet_users_infos, 1): stars = user_info['AllianceScore'] user_name = 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) attempts_left = '' attempts = user.__get_tourney_battle_attempts(user_info, retrieved_at or utc_now) if attempts is not None and max_tourney_battle_attempts: display_attempts = True attempts_left = f'{max_tourney_battle_attempts - attempts}, ' lines.append( f'**{i}.** {stars} (+{difference}) {emojis.star} {user_name} ({attempts_left}{user_rank})' ) properties_attempts = 'Attempts left, ' if display_attempts else '' properties_text = f'Properties displayed: Rank. Stars (Difference to next) Player name ({properties_attempts}Fleet rank)' if retrieved_at is not None: footer_text = utils.datetime.get_historic_data_note(retrieved_at) else: footer_text = None if as_embed: if footer_text: footer_text = '\n'.join((properties_text, footer_text)) else: footer_text = properties_text colour = utils.discord.get_bot_member_colour(ctx.bot, ctx.guild) icon_url = await sprites.get_download_sprite_link( fleet_info.get('AllianceSpriteId')) result = utils.discord.create_basic_embeds_from_description( title, description=lines, colour=colour, icon_url=icon_url, footer=footer_text) return result else: lines.insert(0, f'**{title}**') lines.append(f'_{properties_text}_') if footer_text: lines.append(f'```{footer_text}```') return lines
def get_user_details_by_info(user_info: dict) -> list: user_id = user_info[USER_KEY_NAME] utc_now = util.get_utcnow() inspect_ship_info = ship.get_inspect_ship_for_user(user_id) ship_info = {} for key in inspect_ship_info.keys(): if key != user_id: ship_info = inspect_ship_info[key] fleet_id = user_info['AllianceId'] created_on_date = util.parse_pss_datetime(user_info['CreationDate']) crew_donated = user_info['CrewDonated'] crew_received = user_info['CrewReceived'] defense_draws = int(user_info['PVPDefenceDraws']) defense_losses = int(user_info['PVPDefenceLosses']) defense_wins = int(user_info['PVPDefenceWins']) highest_trophies = user_info['HighestTrophy'] logged_in_date = util.parse_pss_datetime(user_info['LastLoginDate']) pvp_draws = int(user_info['PVPAttackDraws']) pvp_losses = int(user_info['PVPAttackLosses']) pvp_wins = int(user_info['PVPAttackWins']) ship_status = ship_info.get('ShipStatus', '<unknown>') stars = user_info['AllianceScore'] trophies = int(user_info['Trophy']) user_name = user_info[USER_DESCRIPTION_PROPERTY_NAME] user_type = user_info['UserType'] has_fleet = fleet_id != '0' if has_fleet: fleet_info = fleet._get_fleet_info_by_id(fleet_id) if fleet_info: division_design_id = fleet_info['DivisionDesignId'] fleet_join_date = util.parse_pss_datetime( user_info['AllianceJoinDate']) fleet_joined_ago = util.get_formatted_timedelta(fleet_join_date - utc_now) fleet_name = fleet_info[fleet.FLEET_DESCRIPTION_PROPERTY_NAME] fleet_rank = lookups.get_lookup_value_or_default( lookups.ALLIANCE_MEMBERSHIP, user_info['AllianceMembership'], user_info['AllianceMembership']) fleet_name_and_rank = f'{fleet_name} ({fleet_rank})' joined = f'{util.format_excel_datetime(fleet_join_date)} ({fleet_joined_ago})' else: division_design_id = '0' fleet_name_and_rank = '<unknown>' joined = '-' else: division_design_id = '0' fleet_name_and_rank = '<no fleet>' joined = '-' created_ago = util.get_formatted_timedelta(created_on_date - utc_now) created = f'{util.format_excel_datetime(created_on_date)} ({created_ago})' defense_win_rate = _calculate_win_rate(defense_wins, defense_losses, defense_draws) division = lookups.get_lookup_value_or_default( lookups.DIVISION_DESIGN_ID_TO_CHAR, division_design_id, '-') league_name = _get_league_from_trophies(trophies) level = None if user_id: level = ship.get_ship_level(ship_info) if level is None: level = '-' logged_in_ago = util.get_formatted_timedelta(logged_in_date - utc_now) logged_in = f'{util.format_excel_datetime(logged_in_date)} ({logged_in_ago})' pvp_win_rate = _calculate_win_rate(pvp_wins, pvp_losses, pvp_draws) status = lookups.get_lookup_value_or_default(lookups.USER_STATUS, ship_status, default=ship_status) user_type = lookups.get_lookup_value_or_default(lookups.USER_TYPE, user_type, user_type) lines = [f'**```{user_name}```**```'] lines.append(f'Account created: {created}') lines.append(f'Last login: {logged_in}') lines.append(f'Fleet: {fleet_name_and_rank}') if has_fleet: lines.append(f'Joined fleet: {joined}') lines.append(f'League: {league_name}') lines.append(f'Trophies: {trophies}') lines.append(f'Highest trophies: {highest_trophies}') if has_fleet: lines.append(f'Division: {division}') if stars != '0': lines.append(f'Stars: {stars}') if has_fleet: lines.append(f'Crew donated: {crew_donated}') lines.append(f'Crew borrowed: {crew_received}') lines.append( f'PVP win/lose/draw: {pvp_wins}/{pvp_losses}/{pvp_draws} ({pvp_win_rate:0.2f}%)' ) lines.append( f'Defense win/lose/draw: {defense_wins}/{defense_losses}/{defense_draws} ({defense_win_rate:0.2f}%)' ) lines.append(f'Level: {level}') lines.append(f'Status: {status}') lines.append(f'User type: {user_type}') lines[-1] += '```' return lines