2020-09-28 21:35:05 +00:00
|
|
|
//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;
|
2020-09-28 21:35:05 +00:00
|
|
|
use log::error;
|
2020-10-17 13:30:07 +00:00
|
|
|
use std::sync::{Arc, RwLock};
|
2021-05-14 22:25:09 +00:00
|
|
|
use tenebrous_dicebot::bot::DiceBot;
|
|
|
|
use tenebrous_dicebot::config::*;
|
|
|
|
use tenebrous_dicebot::db::Database;
|
|
|
|
use tenebrous_dicebot::error::BotError;
|
2021-05-15 15:27:40 +00:00
|
|
|
use tenebrous_dicebot::migrator;
|
2021-05-14 22:25:09 +00:00
|
|
|
use tenebrous_dicebot::state::DiceBotState;
|
2020-08-26 21:09:50 +00:00
|
|
|
|
2020-10-17 13:30:07 +00:00
|
|
|
#[tokio::main]
|
2020-09-28 21:35:05 +00:00
|
|
|
async fn main() {
|
2021-02-09 21:55:24 +00:00
|
|
|
env_logger::Builder::from_env(
|
2021-05-14 22:25:09 +00:00
|
|
|
Env::default().default_filter_or("tenebrous_dicebot=info,dicebot=info"),
|
2021-02-09 21:55:24 +00:00
|
|
|
)
|
|
|
|
.init();
|
2020-09-28 21:35:05 +00:00
|
|
|
match run().await {
|
|
|
|
Ok(_) => (),
|
2020-10-15 16:52:08 +00:00
|
|
|
Err(e) => error!("Error: {}", e),
|
2020-09-28 21:35:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-10-03 20:31:42 +00:00
|
|
|
let cfg = Arc::new(read_config(config_path)?);
|
2020-10-18 15:13:34 +00:00
|
|
|
let db = Database::new(&cfg.database_path())?;
|
2020-10-17 13:30:07 +00:00
|
|
|
let state = Arc::new(RwLock::new(DiceBotState::new(&cfg)));
|
2020-09-28 21:35:05 +00:00
|
|
|
|
2020-10-24 13:46:06 +00:00
|
|
|
db.migrate(cfg.migration_version())?;
|
|
|
|
|
2021-05-15 15:27:40 +00:00
|
|
|
let sqlite_path = format!("{}/dicebot.sqlite", cfg.database_path());
|
|
|
|
migrator::migrate(&sqlite_path).await?;
|
|
|
|
|
2020-10-17 13:30:07 +00:00
|
|
|
match DiceBot::new(&cfg, &state, &db) {
|
2020-09-28 21:35:05 +00:00
|
|
|
Ok(bot) => bot.run().await?,
|
|
|
|
Err(e) => println!("Error connecting: {:?}", e),
|
|
|
|
};
|
2020-04-17 05:20:54 +00:00
|
|
|
|
2020-08-26 21:09:50 +00:00
|
|
|
Ok(())
|
2020-04-17 05:20:54 +00:00
|
|
|
}
|