diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-01-24 12:19:30 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-01-24 12:19:30 +0100 |
commit | 65942dd6f688e77422246eb6ee862bf6f3224b31 (patch) | |
tree | e0cc635b6415ec31678f2a19bb0ad5a66c02edde | |
parent | acee7556b0c90d96f9fea9b7370f1bd707c4468f (diff) | |
parent | e9c281cbf72413089788d775797906e65cae5599 (diff) | |
download | ezau-65942dd6f688e77422246eb6ee862bf6f3224b31.tar.gz ezau-65942dd6f688e77422246eb6ee862bf6f3224b31.tar.bz2 ezau-65942dd6f688e77422246eb6ee862bf6f3224b31.zip |
Merge branch 'networkjanitor/ezau-multiple-matrix-channels'
-rw-r--r-- | Cargo.lock | 71 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | ezau-sample.toml | 4 | ||||
-rw-r--r-- | src/config.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 17 |
6 files changed, 96 insertions, 11 deletions
@@ -483,6 +483,41 @@ dependencies = [ ] [[package]] +name = "darling" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2 1.0.32", + "quote 1.0.10", + "strsim", + "syn 1.0.82", +] + +[[package]] +name = "darling_macro" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b" +dependencies = [ + "darling_core", + "quote 1.0.10", + "syn 1.0.82", +] + +[[package]] name = "dashmap" version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -608,6 +643,7 @@ dependencies = [ "reqwest", "ruma", "serde", + "serde_with", "serenity", "tokio", "toml", @@ -1091,6 +1127,12 @@ dependencies = [ ] [[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] name = "idna" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2427,6 +2469,12 @@ dependencies = [ ] [[package]] +name = "rustversion" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" + +[[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2546,6 +2594,29 @@ dependencies = [ ] [[package]] +name = "serde_with" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad6056b4cb69b6e43e3a0f055def223380baecc99da683884f205bf347f7c4b3" +dependencies = [ + "rustversion", + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12e47be9471c72889ebafb5e14d5ff930d89ae7a67bbdb5f8abb564f845a927e" +dependencies = [ + "darling", + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", +] + +[[package]] name = "serenity" version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -45,3 +45,7 @@ features = [ ] version = "0.10" optional = true + +[dependencies.serde_with] +version = "1.11.0" +features = [] @@ -113,9 +113,9 @@ password = "secret-foo" # after the first connection. # (optional) device_id = "ASDFGH" -# Room ID to which the message should be posted +# Room ID(s) to which the message should be posted # (mandatory) -room_id = "!room123456:homeserver.org" +room_id = ["!room123456:homeserver.org"] ``` Usage diff --git a/ezau-sample.toml b/ezau-sample.toml index 302f9dd..9076233 100644 --- a/ezau-sample.toml +++ b/ezau-sample.toml @@ -55,6 +55,6 @@ password = "secret-foo" # after the first connection. # (optional) device_id = "ASDFGH" -# Room ID to which the message should be posted +# Room ID(s) to which the message should be posted # (mandatory) -room_id = "!room123456:homeserver.org" +room_id = ["!room123456:homeserver.org"] diff --git a/src/config.rs b/src/config.rs index a4bba44..bf9af1e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use std::{fs, path::Path}; use anyhow::Result; use serde::Deserialize; +use serde_with::{serde_as, OneOrMany}; /// The main configuration. #[derive(Debug, Clone, Deserialize, Default)] @@ -36,6 +37,7 @@ pub struct Discord { } /// Configuration pertaining to the Matrix posting. +#[serde_as] #[derive(Debug, Clone, Deserialize)] pub struct Matrix { /// Matrix homeserver. @@ -46,8 +48,9 @@ pub struct Matrix { pub password: String, /// Device ID, or None if a new one should be generated. pub device_id: Option<String>, - /// Room ID where the message should be posted to. - pub room_id: String, + /// Room ID(s) where the message should be posted to. + #[serde_as(as = "OneOrMany<_>")] + pub room_id: Vec<String>, } /// Attempt to load the configuration from the given file. diff --git a/src/main.rs b/src/main.rs index bdaf13a..b86f281 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,8 +93,11 @@ fn inner_main(opts: &Opts) -> Result<()> { } if let Some(m) = &config.matrix { - matrix::post_link(m.clone().into(), &m.room_id, &log, &permalink) - .context("Could not post link to Matrix")?; + for room_id in &m.room_id { + matrix::post_link(m.clone().into(), room_id, &log, &permalink).context( + format!("Could not post link to Matrix (room_id: {})", &room_id), + )?; + } } } } @@ -203,9 +206,13 @@ fn handle_file(config: &Config, filename: &Path) -> Result<()> { } if let Some(m) = &config.matrix { - matrix::post_link(m.clone().into(), &m.room_id, &log, &permalink) - .context("Could not post link to Matrix")?; - info!("Posted link to Matrix"); + for room_id in &m.room_id { + matrix::post_link(m.clone().into(), room_id, &log, &permalink).context(format!( + "Could not post link to Matrix (room_id: {})", + &room_id + ))?; + info!("Posted link to Matrix ({})", &room_id); + } } Ok(()) |