mirror of
https://github.com/Steffo99/patched-porobot.git
synced 2024-12-23 01:54:22 +00:00
Allow specifying locale via the DATA_DRAGON_LOCALE
envvar
This commit is contained in:
parent
2c83a773e1
commit
f469776a1d
4 changed files with 29 additions and 18 deletions
|
@ -71,7 +71,7 @@ pub fn create_globalindexes_from_wd() -> globals::LocalizedGlobalsIndexes {
|
||||||
.expect("a valid core bundle to exist");
|
.expect("a valid core bundle to exist");
|
||||||
|
|
||||||
let core = CoreBundle::load(&path)
|
let core = CoreBundle::load(&path)
|
||||||
.expect("to be able to load `core-en_us` bundle");
|
.expect("to be able to load CoreBundle bundle");
|
||||||
|
|
||||||
globals::LocalizedGlobalsIndexes::from(core.globals)
|
globals::LocalizedGlobalsIndexes::from(core.globals)
|
||||||
}
|
}
|
||||||
|
@ -80,15 +80,15 @@ pub fn create_globalindexes_from_wd() -> globals::LocalizedGlobalsIndexes {
|
||||||
/// Create [`globals::LocalizedGlobalsIndexes`] from the latest english data in Data Dragon.
|
/// Create [`globals::LocalizedGlobalsIndexes`] from the latest english data in Data Dragon.
|
||||||
///
|
///
|
||||||
/// This function tries to load data from `https://dd.b.pvp.net/latest`.
|
/// This function tries to load data from `https://dd.b.pvp.net/latest`.
|
||||||
pub async fn create_globalindexes_from_dd_latest_en_us() -> globals::LocalizedGlobalsIndexes {
|
pub async fn create_globalindexes_from_dd_latest(locale: &str) -> globals::LocalizedGlobalsIndexes {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
log::debug!("Fetching latest CoreBundle from Data Dragon...");
|
log::debug!("Fetching {} CoreBundle from Data Dragon...", locale);
|
||||||
|
|
||||||
let core = CoreBundle::fetch(&client, "https://dd.b.pvp.net/latest", "en_us").await
|
let core = CoreBundle::fetch(&client, "https://dd.b.pvp.net/latest", locale).await
|
||||||
.expect("to be able to fetch `core-en_us` bundle");
|
.expect("to be able to fetch CoreBundle");
|
||||||
|
|
||||||
log::debug!("Fetched latest CoreBundle: it defines {} regions, {} keywords, {} rarities, {} sets, {} spell speeds, and {} vocab terms!", &core.globals.regions.len(), &core.globals.keywords.len(), &core.globals.rarities.len(), &core.globals.sets.len(), &core.globals.spell_speeds.len(), &core.globals.vocab_terms.len());
|
log::debug!("Fetched {} CoreBundle: it defines {} regions, {} keywords, {} rarities, {} sets, {} spell speeds, and {} vocab terms!", locale, &core.globals.regions.len(), &core.globals.keywords.len(), &core.globals.rarities.len(), &core.globals.sets.len(), &core.globals.spell_speeds.len(), &core.globals.vocab_terms.len());
|
||||||
|
|
||||||
globals::LocalizedGlobalsIndexes::from(core.globals)
|
globals::LocalizedGlobalsIndexes::from(core.globals)
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,17 +163,17 @@ pub const DD_KNOWN_SET_CODES: [&str; 7] = [
|
||||||
/// Create a [`card::CardIndex`] from the latest known english data in Data Dragon.
|
/// 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`.
|
/// This function tries to load data from `https://dd.b.pvp.net/latest`.
|
||||||
pub async fn create_cardindex_from_dd_latest_en_us() -> card::CardIndex {
|
pub async fn create_cardindex_from_dd_latest(locale: &str) -> card::CardIndex {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let mut index = card::CardIndex::new();
|
let mut index = card::CardIndex::new();
|
||||||
|
|
||||||
for set_code in DD_KNOWN_SET_CODES {
|
for set_code in DD_KNOWN_SET_CODES {
|
||||||
log::debug!("Fetching SetBundle with code {} from Data Dragon...", &set_code);
|
log::debug!("Fetching {} SetBundle with code {} from Data Dragon...", locale, &set_code);
|
||||||
|
|
||||||
let set = SetBundle::fetch(&client, "https://dd.b.pvp.net/latest", "en_us", 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");
|
.expect("to be able to fetch set bundle");
|
||||||
|
|
||||||
log::debug!("Fetched SetBundle with code {}: it defines {} cards!", &set_code, set.cards.len());
|
log::debug!("Fetched {} SetBundle with code {}: it defines {} cards!", locale, &set_code, set.cards.len());
|
||||||
|
|
||||||
for card in set.cards {
|
for card in set.cards {
|
||||||
index.insert(card.code.clone(), card);
|
index.insert(card.code.clone(), card);
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use log::*;
|
use log::*;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
use crate::data::corebundle::create_globalindexes_from_dd_latest_en_us;
|
use crate::data::corebundle::create_globalindexes_from_dd_latest;
|
||||||
use crate::data::setbundle::create_cardindex_from_dd_latest_en_us;
|
use crate::data::setbundle::create_cardindex_from_dd_latest;
|
||||||
use crate::discord::handler::EventHandler;
|
use crate::discord::handler::EventHandler;
|
||||||
use crate::search::cardsearch::CardSearchEngine;
|
use crate::search::cardsearch::CardSearchEngine;
|
||||||
|
|
||||||
|
@ -13,12 +13,17 @@ pub async fn main() {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
debug!("Logger initialized successfully!");
|
debug!("Logger initialized successfully!");
|
||||||
|
|
||||||
|
debug!("Detecting locale to use...");
|
||||||
|
let locale = env::var("DATA_DRAGON_LOCALE")
|
||||||
|
.expect("DATA_DRAGON_LOCALE to be set");
|
||||||
|
debug!("Using {} locale!", &locale);
|
||||||
|
|
||||||
debug!("Creating LocalizedGlobalIndexes...");
|
debug!("Creating LocalizedGlobalIndexes...");
|
||||||
let globals = create_globalindexes_from_dd_latest_en_us().await;
|
let globals = create_globalindexes_from_dd_latest(&locale).await;
|
||||||
debug!("Created LocalizedGlobalIndexes!");
|
debug!("Created LocalizedGlobalIndexes!");
|
||||||
|
|
||||||
debug!("Creating CardIndex...");
|
debug!("Creating CardIndex...");
|
||||||
let cards = create_cardindex_from_dd_latest_en_us().await;
|
let cards = create_cardindex_from_dd_latest(&locale).await;
|
||||||
debug!("Created CardIndex!");
|
debug!("Created CardIndex!");
|
||||||
|
|
||||||
debug!("Creating CardSearchEngine...");
|
debug!("Creating CardSearchEngine...");
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
//! Module defining the [`main`] function for `patched_porobot_telegram`.
|
//! Module defining the [`main`] function for `patched_porobot_telegram`.
|
||||||
|
|
||||||
use crate::data::corebundle::create_globalindexes_from_dd_latest_en_us;
|
use std::env;
|
||||||
use crate::data::setbundle::create_cardindex_from_dd_latest_en_us;
|
use crate::data::corebundle::create_globalindexes_from_dd_latest;
|
||||||
|
use crate::data::setbundle::create_cardindex_from_dd_latest;
|
||||||
use crate::search::cardsearch::CardSearchEngine;
|
use crate::search::cardsearch::CardSearchEngine;
|
||||||
use crate::telegram::handler::{inline_query_handler, message_handler};
|
use crate::telegram::handler::{inline_query_handler, message_handler};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
@ -13,12 +14,17 @@ pub async fn main() {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
debug!("Logger initialized successfully!");
|
debug!("Logger initialized successfully!");
|
||||||
|
|
||||||
|
debug!("Detecting locale to use...");
|
||||||
|
let locale = env::var("DATA_DRAGON_LOCALE")
|
||||||
|
.expect("DATA_DRAGON_LOCALE to be set");
|
||||||
|
debug!("Using {} locale!", &locale);
|
||||||
|
|
||||||
debug!("Creating LocalizedGlobalIndexes...");
|
debug!("Creating LocalizedGlobalIndexes...");
|
||||||
let globals = create_globalindexes_from_dd_latest_en_us().await;
|
let globals = create_globalindexes_from_dd_latest(&locale).await;
|
||||||
debug!("Created LocalizedGlobalIndexes!");
|
debug!("Created LocalizedGlobalIndexes!");
|
||||||
|
|
||||||
debug!("Creating CardIndex...");
|
debug!("Creating CardIndex...");
|
||||||
let cards = create_cardindex_from_dd_latest_en_us().await;
|
let cards = create_cardindex_from_dd_latest(&locale).await;
|
||||||
debug!("Created CardIndex!");
|
debug!("Created CardIndex!");
|
||||||
|
|
||||||
debug!("Creating CardSearchEngine...");
|
debug!("Creating CardSearchEngine...");
|
||||||
|
|
Loading…
Reference in a new issue