2023-02-07 00:31:15 +00:00
|
|
|
//! Module defining the [`main`] function for `patched_porobot_discord`.
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use log::*;
|
|
|
|
use serenity::prelude::*;
|
2023-03-23 18:58:59 +00:00
|
|
|
use crate::data::corebundle::create_globalindexes_from_dd_latest;
|
|
|
|
use crate::data::setbundle::create_cardindex_from_dd_latest;
|
2023-02-07 00:31:15 +00:00
|
|
|
use crate::discord::handler::EventHandler;
|
|
|
|
use crate::search::cardsearch::CardSearchEngine;
|
|
|
|
|
|
|
|
/// The function that `patched_porobot_discord` should run when it's started.
|
|
|
|
pub async fn main() {
|
|
|
|
pretty_env_logger::init();
|
|
|
|
debug!("Logger initialized successfully!");
|
|
|
|
|
2023-03-23 18:58:59 +00:00
|
|
|
debug!("Detecting locale to use...");
|
|
|
|
let locale = env::var("DATA_DRAGON_LOCALE")
|
|
|
|
.expect("DATA_DRAGON_LOCALE to be set");
|
|
|
|
debug!("Using {} locale!", &locale);
|
|
|
|
|
2023-03-24 01:04:58 +00:00
|
|
|
debug!("Detecting set codes to fetch...");
|
2023-03-24 12:22:33 +00:00
|
|
|
let known_set_codes: String = env::var("DATA_DRAGON_SET_CODES")
|
|
|
|
.expect("DATA_DRAGON_SET_CODES to be set");
|
|
|
|
let known_set_codes: Vec<&str> = known_set_codes
|
2023-04-11 15:11:53 +00:00
|
|
|
.rsplit(',')
|
2023-03-24 12:22:33 +00:00
|
|
|
.collect();
|
|
|
|
debug!("Detected set codes: {:?}", &known_set_codes);
|
2023-03-24 01:04:58 +00:00
|
|
|
|
2023-02-07 00:31:15 +00:00
|
|
|
debug!("Creating LocalizedGlobalIndexes...");
|
2023-03-23 18:58:59 +00:00
|
|
|
let globals = create_globalindexes_from_dd_latest(&locale).await;
|
2023-02-07 00:31:15 +00:00
|
|
|
debug!("Created LocalizedGlobalIndexes!");
|
|
|
|
|
|
|
|
debug!("Creating CardIndex...");
|
2023-03-24 12:22:33 +00:00
|
|
|
let cards = create_cardindex_from_dd_latest(&locale, known_set_codes.into_iter()).await;
|
2023-02-07 00:31:15 +00:00
|
|
|
debug!("Created CardIndex!");
|
|
|
|
|
|
|
|
debug!("Creating CardSearchEngine...");
|
|
|
|
let engine = CardSearchEngine::new(globals, cards);
|
|
|
|
debug!("Created CardSearchEngine!");
|
|
|
|
|
|
|
|
let token: String = env::var("SERENITY_TOKEN").expect("SERENITY_TOKEN to be set");
|
|
|
|
let appid: u64 = env::var("SERENITY_APPID").expect("SERENITY_APPID to be set")
|
|
|
|
.parse().expect("SERENITY_APPID to be valid");
|
|
|
|
|
|
|
|
Client::builder(&token, GatewayIntents::non_privileged())
|
|
|
|
.event_handler(EventHandler)
|
|
|
|
.type_map_insert::<CardSearchEngine>(engine)
|
|
|
|
.application_id(appid)
|
|
|
|
.await
|
|
|
|
.expect("to be able to create the Discord client")
|
|
|
|
.start_autosharded()
|
|
|
|
.await
|
|
|
|
.expect("to be able to start the Discord client");
|
|
|
|
}
|