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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod ids {
|
2021-10-30 05:38:48 +00:00
|
|
|
pub const SUMMONER_ID_LUGNUTSK: &str = "SBM8Ubipo4ge2yj7bhEzL7yvV0C9Oc1XA2l6v5okGMA_nCw";
|
2021-12-29 17:35:09 +00:00
|
|
|
pub const SUMMONER_ID_MA5TERY: &str = "IbC4uyFEEW3ZkZw6FZF4bViw3P1EynclAcI6-p-vCpI99Ec";
|
2021-10-30 05:38:48 +00:00
|
|
|
pub const SUMMONER_ID_C9SNEAKY: &str = "ghHSdADqgxKwcRl_vWndx6wKiyZx0xKQv-LOhOcU5LU";
|
2021-12-29 17:35:09 +00:00
|
|
|
pub const ACCOUNT_ID_C9SNEAKY: &str = "ML_CcLT94UUHp1iDvXOXCidfmzzPrk_Jbub1f_INhw";
|
|
|
|
pub const ACCOUNT_ID_LUGNUTSK: &str = "iheZF2uJ50S84Hfq6Ob8GNlJAUmBmac-EsEEWBJjD01q1jQ";
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn match_v5_get(route: RegionalRoute, matches: &[&'static str]) -> Result<(), String> {
|
|
|
|
for &matche in matches {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn match_v5_get_timeline(
|
|
|
|
route: RegionalRoute,
|
|
|
|
matches: &[&'static str],
|
|
|
|
) -> Result<(), String> {
|
|
|
|
for &matche in matches {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
2021-06-30 23:34:34 +00:00
|
|
|
}
|