bad-news/src/main.rs

48 lines
964 B
Rust
Raw Normal View History

2021-02-02 05:37:43 +01:00
use std::{
fs::File,
2021-02-02 07:28:14 +01:00
io::{self, BufReader},
2021-02-02 06:43:23 +01:00
path::PathBuf,
2021-02-02 05:37:43 +01:00
};
2021-02-02 04:20:27 +01:00
use clap::Clap;
use thiserror::Error;
2021-02-02 07:28:14 +01:00
mod autojoin;
mod bot;
mod config;
2021-02-02 07:11:16 +01:00
2021-02-02 07:28:14 +01:00
use bot::BadNewsBot;
use config::Config;
2021-02-02 04:20:27 +01:00
#[derive(Error, Debug)]
enum BadNewsError {
#[error("problem accessing configuration file")]
ConfigFile(#[from] io::Error),
#[error("Matrix communication error")]
Matrix(#[from] matrix_sdk::Error),
}
2021-02-02 06:04:06 +01:00
#[derive(Clap)]
#[clap(version = "0.1", author = "Antoine Martin")]
struct Opts {
/// File where session information will be saved
#[clap(short, long, parse(from_os_str))]
config: PathBuf,
}
2021-02-02 04:20:27 +01:00
#[tokio::main]
async fn main() -> anyhow::Result<()> {
2021-02-02 04:20:27 +01:00
tracing_subscriber::fmt::init();
2021-02-02 06:04:06 +01:00
2021-02-02 04:20:27 +01:00
let opts = Opts::parse();
2021-02-02 06:04:06 +01:00
let config_file = opts.config;
let config: Config = serde_yaml::from_reader(BufReader::new(File::open(config_file)?))?;
2021-02-02 04:20:27 +01:00
2021-02-02 07:11:16 +01:00
let bot = BadNewsBot::new(config)?;
bot.init().await?;
bot.run().await;
Ok(())
2021-02-02 04:20:27 +01:00
}