mirror of
https://github.com/Steffo99/patched-porobot.git
synced 2024-12-22 17:44:22 +00:00
Make set codes configurable via DATA_DRAGON_SET_CODES
This commit is contained in:
parent
ead9eedea3
commit
ad084d6dc8
3 changed files with 19 additions and 20 deletions
|
@ -145,32 +145,17 @@ pub fn create_cardindex_from_wd() -> card::CardIndex {
|
|||
create_cardindex_from_paths(paths)
|
||||
}
|
||||
|
||||
/// List of all known Data Dragon set codes.
|
||||
///
|
||||
/// See [the Riot Developer Portal](https://developer.riotgames.com/docs/lor#data-dragon_set-bundles) for more details.
|
||||
///
|
||||
/// Not related with [`set::CardSet`].
|
||||
pub const DD_KNOWN_SET_CODES: [&str; 7] = [
|
||||
"set1",
|
||||
"set2",
|
||||
"set3",
|
||||
"set4",
|
||||
"set5",
|
||||
"set6",
|
||||
"set6cde",
|
||||
];
|
||||
|
||||
/// Create a [`card::CardIndex`] from the latest known english data in Data Dragon.
|
||||
///
|
||||
/// This function tries to load data from `https://dd.b.pvp.net/latest`.
|
||||
pub async fn create_cardindex_from_dd_latest(locale: &str) -> card::CardIndex {
|
||||
pub async fn create_cardindex_from_dd_latest(known_set_codes: &Vec<String>, locale: &str) -> card::CardIndex {
|
||||
let client = reqwest::Client::new();
|
||||
let mut index = card::CardIndex::new();
|
||||
|
||||
for set_code in DD_KNOWN_SET_CODES {
|
||||
for set_code in known_set_codes {
|
||||
log::debug!("Fetching {} SetBundle with code {} from Data Dragon...", locale, &set_code);
|
||||
|
||||
let set = SetBundle::fetch(&client, "https://dd.b.pvp.net/latest", locale, set_code).await
|
||||
let set = SetBundle::fetch(&client, "https://dd.b.pvp.net/latest", locale, &set_code).await
|
||||
.expect("to be able to fetch set bundle");
|
||||
|
||||
log::debug!("Fetched {} SetBundle with code {}: it defines {} cards!", locale, &set_code, set.cards.len());
|
||||
|
|
|
@ -18,12 +18,19 @@ pub async fn main() {
|
|||
.expect("DATA_DRAGON_LOCALE to be set");
|
||||
debug!("Using {} locale!", &locale);
|
||||
|
||||
debug!("Detecting set codes to fetch...");
|
||||
let known_set_codes: Vec<String> = env::var("DATA_DRAGON_SET_CODES")
|
||||
.expect("DATA_DRAGON_SET_CODES to be set")
|
||||
.split(",")
|
||||
.into();
|
||||
debug!("Using set codes: {:#?}", &known_set_codes);
|
||||
|
||||
debug!("Creating LocalizedGlobalIndexes...");
|
||||
let globals = create_globalindexes_from_dd_latest(&locale).await;
|
||||
debug!("Created LocalizedGlobalIndexes!");
|
||||
|
||||
debug!("Creating CardIndex...");
|
||||
let cards = create_cardindex_from_dd_latest(&locale).await;
|
||||
let cards = create_cardindex_from_dd_latest(&known_set_codes, &locale).await;
|
||||
debug!("Created CardIndex!");
|
||||
|
||||
debug!("Creating CardSearchEngine...");
|
||||
|
|
|
@ -19,12 +19,19 @@ pub async fn main() {
|
|||
.expect("DATA_DRAGON_LOCALE to be set");
|
||||
debug!("Using {} locale!", &locale);
|
||||
|
||||
debug!("Detecting set codes to fetch...");
|
||||
let known_set_codes: Vec<String> = env::var("DATA_DRAGON_SET_CODES")
|
||||
.expect("DATA_DRAGON_SET_CODES to be set")
|
||||
.split(",")
|
||||
.into();
|
||||
debug!("Using set codes: {:#?}", &known_set_codes);
|
||||
|
||||
debug!("Creating LocalizedGlobalIndexes...");
|
||||
let globals = create_globalindexes_from_dd_latest(&locale).await;
|
||||
debug!("Created LocalizedGlobalIndexes!");
|
||||
|
||||
debug!("Creating CardIndex...");
|
||||
let cards = create_cardindex_from_dd_latest(&locale).await;
|
||||
let cards = create_cardindex_from_dd_latest(&known_set_codes, &locale).await;
|
||||
debug!("Created CardIndex!");
|
||||
|
||||
debug!("Creating CardSearchEngine...");
|
||||
|
|
Loading…
Reference in a new issue