Matrix notification

This commit is contained in:
Pascal Engélibert 2022-10-15 23:48:06 +02:00
commit 2de26f5ffc
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
7 changed files with 1090 additions and 17 deletions

View file

@ -32,6 +32,17 @@ pub struct Config {
pub lang: String,
#[serde(default = "Config::default_listen")]
pub listen: SocketAddr,
/// Send a matrix message on new comment
#[serde(default = "Config::default_matrix_notify")]
pub matrix_notify: bool,
#[serde(default = "Config::default_matrix_password")]
pub matrix_password: String,
#[serde(default = "Config::default_matrix_room")]
pub matrix_room: String,
#[serde(default = "Config::default_matrix_server")]
pub matrix_server: String,
#[serde(default = "Config::default_matrix_user")]
pub matrix_user: String,
#[serde(default = "Config::default_root_url")]
pub root_url: String,
}
@ -70,6 +81,21 @@ impl Config {
fn default_listen() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 31720)
}
fn default_matrix_notify() -> bool {
false
}
fn default_matrix_password() -> String {
"".into()
}
fn default_matrix_room() -> String {
"#maintenance:matrix.txmn.tk".into()
}
fn default_matrix_server() -> String {
"https://matrix.txmn.tk".into()
}
fn default_matrix_user() -> String {
"@tuxmain:matrix.txmn.tk".into()
}
fn default_root_url() -> String {
"/".into()
}
@ -89,6 +115,11 @@ impl Default for Config {
cookies_domain: Self::default_cookies_domain(),
lang: Self::default_lang(),
listen: Self::default_listen(),
matrix_notify: Self::default_matrix_notify(),
matrix_password: Self::default_matrix_password(),
matrix_room: Self::default_matrix_room(),
matrix_server: Self::default_matrix_server(),
matrix_user: Self::default_matrix_user(),
root_url: Self::default_root_url(),
}
}
@ -107,7 +138,7 @@ pub fn read_config(dir: &Path) -> Config {
std::str::from_utf8(&std::fs::read(path).expect("Cannot read config file"))
.expect("Bad encoding in config file"),
)
.expect("Bad JSON in config file")
.expect("Bad TOML in config file")
}
}