tenebrous-dicebot/src/bin/dicebot.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

//Needed for nested Result handling from tokio. Probably can go away after 1.47.0.
#![type_length_limit = "7605144"]
2020-08-28 00:13:01 +00:00
use env_logger::Env;
use log::error;
use std::sync::{Arc, RwLock};
use tenebrous_dicebot::bot::DiceBot;
use tenebrous_dicebot::config::*;
use tenebrous_dicebot::db::Database;
use tenebrous_dicebot::error::BotError;
use tenebrous_dicebot::migrator;
use tenebrous_dicebot::state::DiceBotState;
#[tokio::main]
async fn main() {
env_logger::Builder::from_env(
Env::default().default_filter_or("tenebrous_dicebot=info,dicebot=info"),
)
.init();
match run().await {
Ok(_) => (),
Err(e) => error!("Error: {}", e),
};
}
async fn run() -> Result<(), BotError> {
2020-04-17 22:53:27 +00:00
let config_path = std::env::args()
2020-04-17 05:25:13 +00:00
.skip(1)
.next()
2020-04-17 22:53:27 +00:00
.expect("Need a config as an argument");
2020-04-17 05:20:54 +00:00
let cfg = Arc::new(read_config(config_path)?);
let db = Database::new(&cfg.database_path())?;
let state = Arc::new(RwLock::new(DiceBotState::new(&cfg)));
db.migrate(cfg.migration_version())?;
let sqlite_path = format!("{}/dicebot.sqlite", cfg.database_path());
migrator::migrate(&sqlite_path).await?;
match DiceBot::new(&cfg, &state, &db) {
Ok(bot) => bot.run().await?,
Err(e) => println!("Error connecting: {:?}", e),
};
2020-04-17 05:20:54 +00:00
Ok(())
2020-04-17 05:20:54 +00:00
}