pub async fn create_embed_loop(
info_json: &Value,
player_name: &str,
collection_emoji: Collection<EmojiId>,
) -> CreateEmbedExpand description
⚙️ Function: Creates a detailed embed for a player’s match performance in Discord.
This asynchronous function generates a CreateEmbed object that includes detailed statistics
of a player’s match, such as the game mode, result, duration, and a role-by-role comparison
of the player’s team versus the enemy team. The embed is enriched with emojis and formatted
data to make it visually appealing for Discord.
§Parameters:
info_json: A reference to aValue(from theserde_jsoncrate) containing the match data fetched from the Riot API.player_name: A string slice representing the player’s name, used for the embed’s title.collection_emoji: A MongoDBCollectioncontaining emoji mappings, which are used to enhance the embed with role and champion-specific emojis.
§Returns:
CreateEmbed: Returns aCreateEmbedobject containing the formatted match data, including role-based comparisons and game metadata, ready to be sent to a Discord channel.
§Example:
This function is typically used to send detailed match information to a Discord channel:
let embed = create_embed_loop(&info_json, "PlayerName", collection_emoji).await;
// Send the embed to a Discord channel using your bot's message-sending logic§Notes:
- The function begins by extracting key game metadata (game mode, result, and duration) from
info_json. - Based on the match result, it selects appropriate emojis and colors for the embed.
- The function then constructs the title and proceeds to iterate over the available role-based matchups, comparing the stats of the player’s team with the enemy team for each role (TOP, JUNGLE, MIDDLE, BOTTOM, UTILITY).
- Role and champion names are replaced by their corresponding emojis from the
collection_emoji, retrieved using theget_emojifunction. - The function formats team and enemy stats (kills, deaths, assists, CS, gold, vision score) for each role and adds them as fields in the embed.
- It returns a fully constructed
CreateEmbedready to be sent in a Discord message.