async fn extract_match_info(
match_ids: Vec<String>,
ctx: &ApplicationContext<'_, Data, Box<dyn Error + Send + Sync>>,
puuid: String,
) -> Vec<Value>Expand description
⚙️ Function: Extracts detailed information from recent League of Legends matches.
This function processes a list of match IDs, fetching and extracting key match information such as champion played, kills, deaths, assists (K/D/A), total farm, game duration, and match outcome (victory or defeat). The extracted data is returned as a vector of JSON-like values for use in other parts of the application, such as creating embeds for Discord.
§Parameters:
match_ids: A vector of match IDs to fetch and process. Each ID corresponds to a recent match played by the user.ctx: The application context, which includes the Riot API key for fetching match data and methods for interacting with Discord.summoner_id: The unique ID of the summoner (player) whose match data is being processed. This is used to find the player’s data within each match.
§Returns:
Vec<Value>: A vector of JSON-like values, where each entry contains information about a match:champion_name: The name of the champion played in the match.K/D/A: The player’s kills, deaths, and assists in the match.Farm: The total number of minions and neutral monsters killed.Result: The outcome of the match (Victory or Defeat).Duration: The duration of the match in minutes and seconds.time_elapsed: The time since the match ended, formatted as seconds, minutes, hours, or days ago.game_type: The type of game played (e.g., Ranked Solo/Duo, ARAM).
§⚠️ Notes:
- Only matches with a valid game mode (as determined by
is_valid_game_mode()) are processed. - If a match does not contain the player’s data, it is skipped.
- The function uses the
time_since_game_endedutility to calculate how long ago the match was played.
§Example:
let match_ids = vec!["EUW1_1234567890", "EUW1_0987654321"];
let match_info = extract_match_info(match_ids, ctx, summoner_id).await;The resulting match_info vector will contain data for each match, such as:
[
{
"champion_name": "Yasuo",
"K/D/A": "10/2/8",
"Farm": 220,
"Result": "Victory",
"Duration": "30:12",
"time_elapsed": "2 hours ago",
"game_type": "Ranked Solo/Duo"
},
{
"champion_name": "Zed",
"K/D/A": "7/5/10",
"Farm": 180,
"Result": "Defeat",
"Duration": "28:45",
"time_elapsed": "1 day ago",
"game_type": "Ranked Flex"
}
]