diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9d99a37 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,23 @@ +use matrix_sdk::identifiers::RoomId; +use serde::Deserialize; +use std::collections::HashSet; +use std::path::PathBuf; +use url::Url; + +/// Holds the configuration for the bot. +#[derive(Clone, Deserialize)] +pub struct Config { + /// The URL for the homeserver we should connect to + pub homeserver: Url, + /// The bot's account username + pub username: String, + /// The bot's account password + pub password: String, + /// Path to a directory where the bot will store Matrix state and current session information. + pub state_dir: PathBuf, + /// ID of the Matrix room where the bot should post messages. The bot will only accept + /// invitations to this room. + pub room_id: RoomId, + /// Units to watch for logs + pub units: HashSet, +} diff --git a/src/main.rs b/src/main.rs index dee3102..877d58e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,18 @@ use std::{ - collections::HashSet, fs::File, io::{self, BufReader}, path::PathBuf, }; use clap::Clap; -use matrix_sdk::identifiers::RoomId; -use serde::Deserialize; use thiserror::Error; -use url::Url; mod autojoin; mod bot; +mod config; use bot::BadNewsBot; +use config::Config; #[derive(Error, Debug)] enum BadNewsError { @@ -32,24 +30,6 @@ struct Opts { config: PathBuf, } -/// Holds the configuration for the bot. -#[derive(Clone, Deserialize)] -pub struct Config { - /// The URL for the homeserver we should connect to - homeserver: Url, - /// The bot's account username - username: String, - /// The bot's account password - password: String, - /// Path to a directory where the bot will store Matrix state and current session information. - state_dir: PathBuf, - /// ID of the Matrix room where the bot should post messages. The bot will only accept - /// invitations to this room. - room_id: RoomId, - /// Units to watch for logs - units: HashSet, -} - #[tokio::main] async fn main() -> anyhow::Result<()> { tracing_subscriber::fmt::init();