(common_conf: &RunConfig, web_conf: &WebConfig)
| 27 | pub type AppState = Arc<InnerAppState>; |
| 28 | |
| 29 | pub async fn init_app_state(common_conf: &RunConfig, web_conf: &WebConfig) -> AppState { |
| 30 | let postgres_store = Db::new_with_url(&common_conf.database_url).await.unwrap(); |
| 31 | |
| 32 | let discord_config = common::discord::fetch_discord_config(common_conf.discord_token.clone()) |
| 33 | .await |
| 34 | .unwrap(); |
| 35 | |
| 36 | let news_handle = init_news_handle(web_conf, discord_config.clone()).await; |
| 37 | |
| 38 | let oauth_client = common_conf.get_discord_oauth2_client(); |
| 39 | |
| 40 | let bot_rpc_client = botrpc::Client::new(common_conf.bot_rpc_connect_addr.clone()); |
| 41 | |
| 42 | let stripe_client = init_stripe_client(postgres_store.clone(), web_conf); |
| 43 | let state_client = dbrokerapi::state_client::Client::new(web_conf.broker_api_addr.clone()); |
| 44 | |
| 45 | Arc::new(InnerAppState { |
| 46 | web_config: web_conf.clone(), |
| 47 | common_config: common_conf.clone(), |
| 48 | db: postgres_store.clone(), |
| 49 | stripe_client, |
| 50 | oauth_api_client_cache: ClientCache::new_twilight(oauth_client.clone(), postgres_store), |
| 51 | discord_oauth_client: oauth_client, |
| 52 | news_handle, |
| 53 | discord_config, |
| 54 | bot_rpc_client, |
| 55 | state_client, |
| 56 | }) |
| 57 | } |
| 58 | |
| 59 | async fn init_news_handle(web_conf: &WebConfig, discord_config: Arc<DiscordConfig>) -> NewsHandle { |
| 60 | if let Some(guild_id) = web_conf.news_guild { |
no test coverage detected