config: extract Config into its own file

This commit is contained in:
Bruno BELANYI 2021-04-10 02:01:17 +02:00 committed by Antoine Martin
parent 6f155bba0b
commit f22416adac
2 changed files with 25 additions and 22 deletions

23
src/config.rs Normal file
View file

@ -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<String>,
}

View file

@ -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<String>,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();