tenebrous-dicebot/src/bin/dicebot.rs

43 lines
1.1 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"]
use chronicle_dicebot::bot::DiceBot;
use chronicle_dicebot::config::*;
use chronicle_dicebot::db::Database;
use chronicle_dicebot::error::BotError;
use chronicle_dicebot::state::DiceBotState;
2020-08-28 00:13:01 +00:00
use env_logger::Env;
use log::error;
use std::sync::{Arc, RwLock};
#[tokio::main]
async fn main() {
env_logger::Builder::from_env(
Env::default().default_filter_or("chronicle_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())?;
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
}