aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml12
-rw-r--r--src/discord.rs2
-rw-r--r--src/logbag.rs5
-rw-r--r--src/main.rs53
5 files changed, 67 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 47e2400..a812cfb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1475,6 +1475,8 @@ dependencies = [
[[package]]
name = "olm-sys"
version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "108c8902295791150d37f0d7b200de1fdd759f34bf479dfdc63c19de8c84c584"
dependencies = [
"cmake",
]
diff --git a/Cargo.toml b/Cargo.toml
index c0d5e9e..78abccd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,6 +7,10 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+[features]
+im-matrix = ["matrix-sdk", "tokio"]
+im-discord = ["serenity", "tokio"]
+
[dependencies]
clap = "3.0.0-beta.1"
log = "0.4.8"
@@ -14,15 +18,16 @@ pretty_env_logger = "0.4.0"
anyhow = "1.0.31"
evtclib = "0.5.0"
reqwest = { version = "0.10.6", features = ["json", "blocking"] }
-serde = "1.0.111"
+serde = { version = "1.0.111", features = ["derive"] }
chrono = "0.4.11"
notify = "4.0.15"
regex = "1.3.9"
zip = "0.5.5"
toml = "0.5.6"
-tokio = { version = "0.2", features = ["rt-core"] }
-matrix-sdk = "0.2.0"
itertools = "0.10.0"
+# Optional features for IM integration
+tokio = { version = "0.2", features = ["rt-core"], optional = true }
+matrix-sdk = { version = "0.2.0", optional = true }
[dependencies.serenity]
default-features = false
@@ -37,3 +42,4 @@ features = [
"rustls_backend",
]
version = "0.9"
+optional = true
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!")
+ }
+}