aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-03-06 12:56:09 +0100
committerDaniel Schadt <kingdread@gmx.de>2021-03-06 12:56:09 +0100
commit15e573150547f956956b7c58c752e31184253fbd (patch)
treec986211e9a9b8758c85f0461b208679c28a1181b /src
parent9079d9ec37bfd4293347539155f1164a979379be (diff)
downloadezau-15e573150547f956956b7c58c752e31184253fbd.tar.gz
ezau-15e573150547f956956b7c58c752e31184253fbd.tar.bz2
ezau-15e573150547f956956b7c58c752e31184253fbd.zip
put matrix & discord functionality behind gates
serenity and matrix-sdk pull in quite a lot of dependencies, which for a minimal use of ezau might not be wanted. Therefore, we now disable those parts by default, and the user has to opt-in into building ezau with Discord or Matrix functionality.
Diffstat (limited to 'src')
-rw-r--r--src/discord.rs2
-rw-r--r--src/logbag.rs5
-rw-r--r--src/main.rs53
3 files changed, 56 insertions, 4 deletions
diff --git a/src/discord.rs b/src/discord.rs
index ea0ea36..c98a6c7 100644
--- a/src/discord.rs
+++ b/src/discord.rs
@@ -11,7 +11,7 @@ use tokio::runtime::Runtime;
use log::info;
use super::categories::Categorizable;
-use super::logbag::{LogBag, state_emoji};
+use super::logbag::{state_emoji, LogBag};
const MAX_HOURS: i64 = 5;
const MAX_MESSAGE_LENGTH: usize = 2000;
diff --git a/src/logbag.rs b/src/logbag.rs
index f94b80a..362bee5 100644
--- a/src/logbag.rs
+++ b/src/logbag.rs
@@ -14,15 +14,16 @@ pub struct LogBag {
data: Vec<(String, Vec<String>)>,
}
+// Conditional compilation makes it hard to really use all the code, so we just allow dead code
+// here locally.
+#[allow(dead_code)]
impl LogBag {
/// Construct a new, empty [`LogBag`].
- #[cfg(test)]
pub fn new() -> Self {
LogBag { data: Vec::new() }
}
/// Return an iterator over all available categories.
- #[cfg(test)]
pub fn categories(&self) -> impl Iterator<Item = &str> {
self.data.iter().map(|x| &x.0 as &str)
}
diff --git a/src/main.rs b/src/main.rs
index ab40d86..55bd637 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,7 @@ use std::{
time::Duration,
};
-use anyhow::{anyhow, Context, Result};
+use anyhow::{anyhow, bail, Context, Result};
use clap::Clap;
use evtclib::{Compression, Encounter, Log};
use log::{debug, error, info, warn};
@@ -20,8 +20,11 @@ mod categories;
use categories::Categorizable;
mod config;
use config::Config;
+#[cfg(feature = "im-discord")]
mod discord;
+#[cfg(any(feature = "im-discord", feature = "im-matrix"))]
mod logbag;
+#[cfg(feature = "im-matrix")]
mod matrix;
const DPS_REPORT_API: &str = "https://dps.report/uploadContent";
@@ -75,6 +78,8 @@ fn main() {
fn inner_main(opts: &Opts) -> Result<()> {
let config = config::load(&opts.config).context("Could not load configuration")?;
+ sanity_check(&config)?;
+
match &opts.subcmd {
SubCommand::Watch(w) => watch(w, &config)?,
SubCommand::Upload(u) => {
@@ -244,3 +249,49 @@ fn upload_log(file: &Path) -> Result<String> {
.json()?;
Ok(resp.permalink)
}
+
+fn sanity_check(config: &Config) -> Result<()> {
+ if config.discord.is_some() && !cfg!(feature = "im-discord") {
+ bail!(
+ "Discord is configured but ezau was built without Discord support. \
+ Please enable the `im-discord` feature or adjust your configuration \
+ to continue."
+ );
+ }
+ if config.matrix.is_some() && !cfg!(feature = "im-matrix") {
+ bail!(
+ "Matrix is configured but ezau was built without Matrix support. \
+ Please enable the `im-matrix` feature or adjust your configuration \
+ to continue."
+ );
+ }
+ Ok(())
+}
+
+// Dummy modules for when the features are disabled
+#[cfg(not(feature = "im-discord"))]
+mod discord {
+ use super::{Log, Result};
+ use anyhow::bail;
+
+ /// Stub, enable the `im-discord` feature to use this function.
+ pub fn post_link(_: &str, _: u64, _: &Log, _: &str) -> Result<()> {
+ bail!("Discord feature is disabled in this build!")
+ }
+}
+
+#[cfg(not(feature = "im-matrix"))]
+mod matrix {
+ use super::{Log, Result};
+ use anyhow::bail;
+ pub struct MatrixUser;
+ impl From<super::config::Matrix> for MatrixUser {
+ fn from(_: super::config::Matrix) -> MatrixUser {
+ MatrixUser
+ }
+ }
+ /// Stub, enable the `im-matrix` feature to use this function.
+ pub fn post_link(_: MatrixUser, _: &str, _: &Log, _: &str) -> Result<()> {
+ bail!("Matrix feature is disabled in this build!")
+ }
+}