def get_mob_emoji(mob_name: str) -> str: emojis = { "Wolf": "🐺", "Bear": "🐻", "Boar": "🐗", } mob_class = re.search("forbidden (\\w+)", mob_name.lower()) if mob_class is not None and not "⚜️Forbidden Champion" in mob_name: return classes_to_emoji.get(mob_class.group(1).capitalize(), '') for mob_class, emoji in list(emojis.items()): if mob_class in mob_name: return emoji return ''
def class_emoji(self): return classes_to_emoji.get(self.game_class, '❔')
def get_tops_text(player: Player, stat: str, stat_text: str, game_class: str = None) -> str: """ Функция, возвращающая текст сообщения с топами. Осуществляет выборку, сортировку, представления топов в красивом виде. :param player: Player instance - Player, who requested tops message :param stat: Str - Stat, which top has been required (e.g. "attack") :param stat_text: Str - Stat representation, which will be visible (e.g. "⚔️Attack") :param game_class: Str - Game class, which top is needed to be shown (e.g. "knight") :return: Str - Result tops text. """ response = "Топ {} по замку:\n".format(stat_text) found = False if player is None: found = True if stat in ["wood", "stone", "construction"]: if stat == "construction": request = "select nickname, count(1) as construction_count, game_class, lvl, player_id from castle_logs " \ "left join players on castle_logs.player_id = players.id where action = 'construction' {}" \ "group by nickname, game_class, lvl, player_id order by construction_count desc;" \ "".format("and game_class = '{}' ".format(game_class) if game_class is not None else "") else: request = "select nickname, count(1) as res_count, game_class, lvl, player_id from castle_logs " \ "left join players on castle_logs.player_id = players.id where action = 'collect_resources' and "\ "additional_info ->> 'resource' = '{}' {}group by nickname, game_class, lvl, player_id order by "\ "res_count desc;".format(stat, "and game_class = '{}'" "".format(game_class) if game_class is not None else "") elif stat.startswith("roulette"): select = stat.partition("roulette_")[2] request = "select nickname, count, game_class, lvl, players.id from locations, json_each(special_info -> '{}')"\ " as a(id, count) inner join players on a.id::text::integer = players.id where " \ "location_id = 10 order by " \ "count::text::integer desc".format(select) # Этот запрос составлялся час. Помянем. else: request = "select nickname, {}, game_class, lvl, id from players where castle = '🖤' and {} is not null " \ "and api_info -> 'token' is not null {}" \ "order by {} desc".format(stat, stat, "and game_class = '{}' ".format(game_class) if game_class is not None else "", stat) response += "<em>Обратите внимание, в топе отображаются только игроки, подключившие API (команда /auth).</em>" \ "\n\n" cursor.execute(request) row = cursor.fetchone() num = 0 response_old = "" while row is not None: num += 1 class_icon = classes_to_emoji.get(row[2]) or '❔' if row[4] == player.id: response_new = "<b>{}) {}</b><code>{:<3}</code><b> 🏅: {} {}{}</b> 🔻" \ "\n".format(num, stat_text, row[1] or "???", row[3], class_icon, row[0]) found = True if num <= TOP_NUM_PLAYERS: response += response_new row = cursor.fetchone() continue response += "\n...\n" + response_old + response_new else: response_old = "<code>{}</code>) {}<code>{:<3}</code> 🏅: <code>{}</code> {}{}" \ "\n".format(num, stat_text, row[1] or "???", row[3], class_icon, row[0]) if num <= TOP_NUM_PLAYERS: response += response_old else: if found: if num == TOP_NUM_PLAYERS + 1: break response += response_old break row = cursor.fetchone() return response
def get_profile_text(player, self_request=True, user_data=None, requested_player=None): barracks = Location.get_location(1) class_links = barracks.special_info.get("class_links") if class_links is None: class_links = {} barracks.special_info.update({"class_links": class_links}) try: class_format = (classes_to_emoji.get(player.game_class) + player.game_class) if \ player.game_class is not None else "Воин" except Exception: class_format = "Воин" logging.error(traceback.format_exc()) logging.error("id:{} nickname:{} class:{} username:{}".format( player.id, player.nickname, player.game_class, player.username)) response = "<b>{}</b> - {} {}\n".format( player.nickname, class_format, "🖤Скалы" if player.castle == '🖤' else player.castle) response += "{}id: <code>{}</code>, ".format( "@{}, ".format(player.username) if player.username is not None else "", player.id) if user_data is None: user_data = dispatcher.user_data.get(player.id) if player.status is not None: response += "Статус: <b>{}</b>\n".format( get_status_text_by_id(player.status, player.id)) response += "🏅: <code>{}</code>, 🔥: <code>{}</code> ⚔: <code>{}</code>, 🛡: <code>{}</code>" \ "\n".format(player.lvl, player.exp or "???", player.attack, player.defense) response += ("👝: {}, ".format(player.pogs) if player.pogs is not None else "") + \ "🔘: <code>{}</code>\n".format(player.reputation) guild = Guild.get_guild( guild_id=player.guild) if player.guild is not None else None response += "Гильдия: {} | {}🔋\n".format( "<code>{}</code>".format(guild.tag) if guild is not None else "нет", player.stamina) if guild is not None and self_request: response += "Покинуть гильдию: /leave_guild\n" elif guild is not None and guild.check_high_access(requested_player.id) and \ (requested_player.guild == guild.id or guild.is_academy()): response += "Удалить из гильдии: /remove_player_{}\n".format(player.id) if self_request: if player.game_class is not None and player.castle == '🖤' and player.game_class not in [ 'Master', 'Esquire' ]: try: if class_links.get(player.game_class) is None: revoke_class_link(player.game_class) invite_link = class_links.get(player.game_class) response += "<a href=\"{}\">\n📚Классовый чат</a>\n".format( "https://t.me/joinchat/" + invite_link) except Exception: logging.error(traceback.format_exc()) response += "\nЭкипировка:\n" eq_list = list(player.equipment.values()) for equipment in eq_list: if equipment is None: continue response += equipment.format() r1, r2, r3 = player.get_reports_count() try: if guild is not None and guild.commander_id == player.id: response += "\n<b>🎗Командир гильдии</b>\n" if guild is not None and player.id in guild.assistants: response += "\n<b>🎗Зам командира гильдии</b>\n" except Exception: logging.error(traceback.format_exc()) response += "\nРепорты(эта неделя / прошлая / всего): <code>{}</code> / <code>{}</code> / <code>{}</code>" \ "\n".format(r1, r2, r3) response += "Регистрация в боте: <code>{}</code>\n".format( player.created.strftime("%d/%m/%y %H:%M:%S") if player. created is not None else "Оппозит") response += "Последнее обновление профиля: " \ "<code>{}</code>\n".format(player.last_updated.strftime("%d/%m/%y %H:%M:%S") if player.last_updated is not None else "неизвестно") if user_data is None: return response status = user_data.get("status") if status is not None and status in ["sawmill", "quarry", "construction" ] or "quest_name" in user_data: if "quest_name" in user_data: quest_name = user_data.get("quest_name") response += "\n<b>Вы {}. Это займёт несколько минут.</b>" \ "".format("на разведке" if quest_name == 'exploration' else "копаете котлован" if quest_name == 'pit' else "") else: if player is not None: j = construction_jobs.get(player.id) if j is not None: seconds_left = j.get_time_left() response += "\nВы заняты делом. Окончание через <b>{:02.0f}:{:02.0f}</b>" \ "".format(seconds_left // 60, (seconds_left % 60) // 1) return response