config: extract Config into its own file
This commit is contained in:
parent
6f155bba0b
commit
f22416adac
23
src/config.rs
Normal file
23
src/config.rs
Normal 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>,
|
||||||
|
}
|
24
src/main.rs
24
src/main.rs
|
@ -1,20 +1,18 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{self, BufReader},
|
io::{self, BufReader},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
use matrix_sdk::identifiers::RoomId;
|
|
||||||
use serde::Deserialize;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
mod autojoin;
|
mod autojoin;
|
||||||
mod bot;
|
mod bot;
|
||||||
|
mod config;
|
||||||
|
|
||||||
use bot::BadNewsBot;
|
use bot::BadNewsBot;
|
||||||
|
use config::Config;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
enum BadNewsError {
|
enum BadNewsError {
|
||||||
|
@ -32,24 +30,6 @@ struct Opts {
|
||||||
config: PathBuf,
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
Loading…
Reference in a new issue