def create_match_message(match_data): match = MatchDto(**match_data) match_id = match.match_id hero_id = match.hero_id hero_data = hero_services.get_hero_by_id(hero_id) hero_name = hero_data.localized_name duration = str(datetime.timedelta(seconds=match.duration)) kda = f"%s/%s/%s" % (match.kills, match.deaths, match.assists) gpm = match.gold_per_min xpm = match.xp_per_min result_string = helpers.get_match_result(match.player_slot, match.radiant_win) game_mode = constants.GAME_MODE_MAP[match.game_mode] lobby_type = constants.LOBBY_TYPE_MAP[match.lobby_type] start_date = helpers.convert_timestamp_to_datetime(match.start_time) output_message = f"*{hero_name}* \| {kda} \| {gpm} GPM \| {xpm} XPM \n\n" output_message += f"Match ID: {match_id} \| {start_date}\n" output_message += f"{lobby_type} lobby \| {game_mode} game \n" output_message += f"Result: *{result_string}* after {duration}" return output_message
def build_default_match_message(match, player_data): # Be agnostic about the amount of players on radiant or dire, just in case output_message = "\nRadiant:\n" for player in player_data: if player.isRadiant: output_message += build_default_player_string(player) output_message += "\nDire:\n" for player in player_data: if not player.isRadiant: output_message += build_default_player_string(player) known_players = [] for player in player_data: if player.account_id: bot_user = user_services.lookup_user_by_account_id(player.account_id) if bot_user: hero_data = hero_services.get_hero_by_id(player.hero_id) hero_name = hero_data.localized_name known_players.append(f"{bot_user.telegram_handle} ({hero_name})") output_message += f"\nKnown players: {', '.join(known_players)}" # Escape markdown up to this point output_message = escape_markdown(output_message, version=2) opendota_link = f"https://www.opendota.com/matches/{match.match_id}" dotabuff_link = f"https://www.dotabuff.com/matches/{match.match_id}" output_message += f"\n\nMore information: [OpenDota]({opendota_link}), [Dotabuff]({dotabuff_link})" return output_message
def build_damage_player_line(player): damage = player.hero_damage building_damage = player.tower_damage healing = player.hero_healing hero_data = hero_services.get_hero_by_id(player.hero_id) hero_name = hero_data.localized_name return f"{damage} DMG | {building_damage} TD | {healing} H | {hero_name}\n"
def format_winrate_response(hero_data, telegram_handle): print(hero_data) hero_by_id = hero_services.get_hero_by_id(hero_data["hero_id"]) hero_name = hero_by_id.localized_name if not hero_data["games"]: return f"@{telegram_handle} has no games as {hero_name} recorded" winrate = hero_data["win"] / hero_data["games"] * 100 winrate = round(winrate, 3) return f"@{telegram_handle} has a {winrate}% winrate as {hero_name} ({hero_data['win']} wins over {hero_data['games']} games)"
def build_pick_order_player_line(player, picks_ordered): index = picks_ordered.index(player.hero_id) if index < 4: pick_string = "First phase" elif index < 8: pick_string = "Second phase" else: pick_string = "Last pick" hero_data = hero_services.get_hero_by_id(player.hero_id) hero_name = hero_data.localized_name return f"{hero_name}: {pick_string}\n"
def build_players_player_line(player): try: player_name = player.personaname except: player_name = "Anonymous" hero_data = hero_services.get_hero_by_id(player.hero_id) hero_name = hero_data.localized_name if player.rank_tier: rank = f"| {helpers.map_rank_tier_to_string(player.rank_tier)}" else: rank = "" party_letter = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"][player.party_id] return f"{party_letter} | {player_name} ({hero_name}) {rank}\n"
def build_default_player_string(player): kills = player.kills deaths = player.deaths assists = player.assists kda = f"{kills}/{deaths}/{assists}" last_hits = player.last_hits denies = player.denies cs = f"{last_hits}/{denies}" level = player.level xpm = player.xp_per_min gpm = player.gold_per_min hero_data = hero_services.get_hero_by_id(player.hero_id) hero_name = hero_data.localized_name return f"{kda} | L{level} | {cs} | {gpm} GPM | {xpm} XPM | {hero_name}\n"
def inner(update, context): if not context.args: update.message.reply_markdown_v2( constants.MISSING_HERO_ARGUMENT_MESSAGE) return hero_name_parts = context.args hero_name = " ".join(hero_name_parts) hero = hero_services.get_hero_by_name(hero_name) if not hero: hero_alias = hero_services.get_hero_alias_by_name(hero_name) if hero_alias: hero = hero_services.get_hero_by_id(hero_alias.hero_id) if not hero: update.message.reply_markdown_v2(constants.HERO_NOT_FOUND_MESSAGE % hero_name) func(update, hero)
def create_recent_matches_message(json_api_data): output_message = "MatchID | Result | KDA | Duration | Hero\n" for element in json_api_data: match = MatchDto(**element) match_id = match.match_id hero_id = match.hero_id hero_data = hero_services.get_hero_by_id(hero_id) hero_name = hero_data.localized_name kda = f"%s/%s/%s" % (match.kills, match.deaths, match.assists) result_string = helpers.get_match_result(match.player_slot, match.radiant_win) duration = str(datetime.timedelta(seconds=match.duration)) output_message += ( f"{match_id} | {result_string[0]} | {kda} | {duration} | {hero_name} \n" ) return output_message
def build_pick_order_match_message(match, player_data): heroes_in_game = [] for player in player_data: heroes_in_game.append(player.hero_id) picks_and_bans = [] for pick_or_ban in match.picks_bans: picks_and_bans.append(pick_or_ban["hero_id"]) # Filter picks and bans by heroes that actually appeared in the game # Everything else got banned picks_ordered = [pick for pick in picks_and_bans if pick in heroes_in_game] bans = [ban for ban in picks_and_bans if ban not in heroes_in_game] output_message = "\nRadiant:\n" for player in player_data: if player.isRadiant: output_message += build_pick_order_player_line(player, picks_ordered) output_message += "\nDire:\n" for player in player_data: if not player.isRadiant: output_message += build_pick_order_player_line(player, picks_ordered) banned_heroes = [] for ban in bans: hero_data = hero_services.get_hero_by_id(ban) hero_name = hero_data.localized_name banned_heroes.append(hero_name) output_message += "\nBans:\n" output_message += ", ".join(banned_heroes) output_message = escape_markdown(output_message, version=2) return output_message