aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXyoz Netsphere <nanoowl@xyooz.net>2022-01-24 12:02:56 +0100
committerXyoz Netsphere <nanoowl@xyooz.net>2022-01-24 12:02:56 +0100
commitcfc7dc8b3ef149f384bd1f2ef3989701a93c7df2 (patch)
treecb1f1ae6cb74648a591a9fc3bcf6a1c31f8cf44e /src
parentacee7556b0c90d96f9fea9b7370f1bd707c4468f (diff)
downloadezau-cfc7dc8b3ef149f384bd1f2ef3989701a93c7df2.tar.gz
ezau-cfc7dc8b3ef149f384bd1f2ef3989701a93c7df2.tar.bz2
ezau-cfc7dc8b3ef149f384bd1f2ef3989701a93c7df2.zip
feat(im-matrix): added multi-room support
Diffstat (limited to 'src')
-rw-r--r--src/config.rs7
-rw-r--r--src/main.rs14
2 files changed, 14 insertions, 7 deletions
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..ada456c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -93,8 +93,10 @@ 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 +205,11 @@ 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(())