2021-06-30 23:34:34 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
2021-12-29 17:35:09 +00:00
|
|
|
use riven::consts::RegionalRoute;
|
|
|
|
use riven::{RiotApi, RiotApiConfig};
|
2021-06-30 23:34:34 +00:00
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
pub static ref RIOT_API: RiotApi = {
|
2021-12-29 17:35:09 +00:00
|
|
|
let api_key = std::env::var("RGAPI_KEY")
|
|
|
|
.ok()
|
2021-06-30 23:34:34 +00:00
|
|
|
.or_else(|| std::fs::read_to_string("apikey.txt").ok())
|
|
|
|
.expect("Failed to find RGAPI_KEY env var or apikey.txt.");
|
2021-09-19 18:22:09 +00:00
|
|
|
RiotApi::new(RiotApiConfig::with_key(api_key.trim()).preconfig_burst())
|
2021-06-30 23:34:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-08 21:49:53 +00:00
|
|
|
pub async fn tft_match_v1_get(route: RegionalRoute, matches: &[impl AsRef<str>]) -> Result<(), String> {
|
|
|
|
let futures = matches.iter().map(|matche| async move {
|
|
|
|
let matche = matche.as_ref();
|
|
|
|
let p = RIOT_API.tft_match_v1().get_match(route, matche);
|
|
|
|
let m = p
|
|
|
|
.await
|
|
|
|
.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?
|
|
|
|
.ok_or(format!("Match {} not found.", matche))?;
|
|
|
|
|
|
|
|
if matche != &*m.metadata.match_id {
|
|
|
|
return Err(format!(
|
|
|
|
"Bad match id? Sent {}, received {}.",
|
|
|
|
matche, m.metadata.match_id
|
|
|
|
));
|
|
|
|
}
|
|
|
|
if m.metadata.participants.is_empty() {
|
|
|
|
return Err("Match should have participants (metadata).".to_owned());
|
|
|
|
}
|
|
|
|
if m.metadata.participants.len() != m.info.participants.len() {
|
|
|
|
return Err("Match participants do not line up with participant UUIDs.".to_owned());
|
|
|
|
}
|
|
|
|
if m.info.participants.is_empty() {
|
|
|
|
return Err("Match should have participants (info).".to_owned());
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
futures::future::try_join_all(futures).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn match_v5_get(route: RegionalRoute, matches: &[impl AsRef<str>]) -> Result<(), String> {
|
|
|
|
let futures = matches.iter().map(|matche| async move {
|
|
|
|
let matche = matche.as_ref();
|
2021-12-29 17:35:09 +00:00
|
|
|
let p = RIOT_API.match_v5().get_match(route, matche);
|
|
|
|
let m = p
|
|
|
|
.await
|
|
|
|
.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?
|
|
|
|
.ok_or(format!("Match {} not found.", matche))?;
|
|
|
|
|
|
|
|
if matche != &*m.metadata.match_id {
|
|
|
|
return Err(format!(
|
|
|
|
"Bad match id? Sent {}, received {}.",
|
|
|
|
matche, m.metadata.match_id
|
|
|
|
));
|
|
|
|
}
|
|
|
|
if m.metadata.participants.is_empty() {
|
|
|
|
return Err("Match should have participants.".to_owned());
|
|
|
|
}
|
2021-12-29 19:50:45 +00:00
|
|
|
if m.metadata.participants.len() != m.info.participants.len() {
|
|
|
|
return Err("Match participants do not line up with participant UUIDs.".to_owned());
|
|
|
|
}
|
|
|
|
for participant in &m.info.participants {
|
|
|
|
participant.champion().map_err(|e| format!("Failed to determine champion: {}", e))?;
|
|
|
|
}
|
2021-12-29 17:35:09 +00:00
|
|
|
if m.info.teams.is_empty() {
|
|
|
|
return Err("Match should have teams.".to_owned());
|
|
|
|
}
|
2023-03-08 21:49:53 +00:00
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
futures::future::try_join_all(futures).await?;
|
2021-12-29 17:35:09 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn match_v5_get_timeline(
|
|
|
|
route: RegionalRoute,
|
2023-03-08 21:49:53 +00:00
|
|
|
matches: &[impl AsRef<str>],
|
2021-12-29 17:35:09 +00:00
|
|
|
) -> Result<(), String> {
|
2023-03-08 21:49:53 +00:00
|
|
|
let futures = matches.iter().map(|matche| async move {
|
|
|
|
let matche = matche.as_ref();
|
2021-12-29 17:35:09 +00:00
|
|
|
let p = RIOT_API.match_v5().get_timeline(route, matche);
|
|
|
|
let m = p
|
|
|
|
.await
|
|
|
|
.map_err(|e| format!("Failed to get match {}: {:?}", matche, e))?
|
|
|
|
.ok_or(format!("Match {} not found.", matche))?;
|
|
|
|
if matche != &*m.metadata.match_id {
|
|
|
|
return Err(format!(
|
|
|
|
"Bad match id? Sent {}, received {}.",
|
|
|
|
matche, m.metadata.match_id
|
|
|
|
));
|
|
|
|
}
|
|
|
|
if m.metadata.participants.is_empty() {
|
|
|
|
return Err("Match should have participants.".to_owned());
|
|
|
|
}
|
|
|
|
if let Some(game_id) = m.info.game_id {
|
|
|
|
if matche[(matche.find('_').unwrap() + 1)..] != game_id.to_string() {
|
|
|
|
return Err("Match number ID should match.".to_owned());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if m.info.frames.is_empty() {
|
|
|
|
return Err("Match timleine should have frames.".to_owned());
|
|
|
|
}
|
2023-03-08 21:49:53 +00:00
|
|
|
Ok(())
|
|
|
|
});
|
|
|
|
futures::future::try_join_all(futures).await?;
|
2021-12-29 17:35:09 +00:00
|
|
|
Ok(())
|
2021-06-30 23:34:34 +00:00
|
|
|
}
|