Ver código fonte

[Telegram] Telegram build switched to option

Signed-off-by: Slava Barinov <rayslava@gmail.com>
Slava Barinov 4 anos atrás
pai
commit
fbff7b36c0
3 arquivos alterados com 19 adições e 10 exclusões
  1. 13 10
      Cargo.toml
  2. 2 0
      src/main.rs
  3. 4 0
      src/telegram.rs

+ 13 - 10
Cargo.toml

@@ -14,17 +14,20 @@ csv = "1.1"
 structopt = "0.3"
 shellexpand = "2.1"
 radix_trie = { version = "0.2", features = ["serde"] }
-libc = "0.2"
-teloxide = { version = "0.4", features = ["auto-send"] }
-log = "0.4.8"
-pretty_env_logger = "0.4.0"
-tokio = { version =  "1.3", features = ["rt-multi-thread", "macros"] }
-derive_more = "0.99.13"
-thiserror = "1.0.24"
+libc = { version = "0.2" }
+
+teloxide = { version = "0.4", features = ["auto-send"], optional = true }
+log = { version = "0.4.8", optional = true }
+pretty_env_logger = { version = "0.4.0", optional = true }
+tokio = { version =  "1.3", features = ["rt-multi-thread", "macros"], optional = true }
+derive_more = { version = "0.99.13", optional = true }
+thiserror = { version = "1.0.24", optional = true }
 
 [build-dependencies]
-cc = "1.0"
-pkg-config = "0.3"
+cc = { version = "1.0", optional = true }
+pkg-config = { version = "0.3", optional = true }
 
 [features]
-tv = []
+default = [ "telegram" ]
+tv = [ "cc", "pkg-config" ]
+telegram = [ "teloxide", "log", "pretty_env_logger", "tokio", "derive_more", "thiserror" ]

+ 2 - 0
src/main.rs

@@ -18,6 +18,7 @@ use categories::CatStats;
 
 mod import;
 mod receipt;
+#[cfg(feature = "telegram")]
 mod telegram;
 mod ui;
 
@@ -130,6 +131,7 @@ fn main() {
         db.set("accounts", &accounts).unwrap();
     }
 
+    #[cfg(feature = "telegram")]
     telegram::bot();
 
     let purchase = read_file(&args.filename);

+ 4 - 0
src/telegram.rs

@@ -8,12 +8,14 @@ use teloxide::{DownloadError, RequestError};
 use thiserror::Error;
 use tokio::fs::File;
 
+#[cfg(feature = "telegram")]
 #[tokio::main]
 pub async fn bot() {
     run().await;
 }
 
 /// Possible error while receiving a file
+#[cfg(feature = "telegram")]
 #[derive(Debug, Error, From)]
 enum FileReceiveError {
     /// Download process error
@@ -27,6 +29,7 @@ enum FileReceiveError {
     Io(#[source] std::io::Error),
 }
 
+#[cfg(feature = "telegram")]
 async fn download_file(downloader: &Bot, file_id: &str) -> Result<String, FileReceiveError> {
     let TgFile {
         file_id, file_path, ..
@@ -37,6 +40,7 @@ async fn download_file(downloader: &Bot, file_id: &str) -> Result<String, FileRe
     Ok(filepath)
 }
 
+#[cfg(feature = "telegram")]
 async fn run() {
     teloxide::enable_logging!();
     log::info!("Starting dices_bot...");