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;
|
2021-02-02 06:31:10 +01:00
|
|
|
use thiserror::Error;
|
|
|
|
|
2021-02-02 07:28:14 +01:00
|
|
|
mod autojoin;
|
|
|
|
mod bot;
|
2021-04-10 02:01:17 +02:00
|
|
|
mod config;
|
2021-02-02 07:11:16 +01:00
|
|
|
|
2021-02-02 07:28:14 +01:00
|
|
|
use bot::BadNewsBot;
|
2021-04-10 02:01:17 +02:00
|
|
|
use config::Config;
|
2021-02-02 04:20:27 +01:00
|
|
|
|
2021-02-02 06:31:10 +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]
|
2021-02-02 06:31:10 +01:00
|
|
|
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;
|
|
|
|
|
2021-02-02 06:31:10 +01:00
|
|
|
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
|
|
|
}
|