Index: Cargo.lock ================================================================== --- Cargo.lock +++ Cargo.lock @@ -468,11 +468,11 @@ name = "crypto-mac" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "generic-array 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "darling" version = "0.10.2" @@ -986,11 +986,11 @@ "http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "httpdate 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "socket2 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "socket2 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)", "tower-service 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "tracing 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1880,11 +1880,11 @@ version = "0.1.13" dependencies = [ "anyhow 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rss 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sqlx 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2100,16 +2100,15 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "socket2" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.81 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.57 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sqlformat" @@ -2230,11 +2229,11 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" version = "1.0.54" @@ -3099,21 +3098,21 @@ "checksum signal-hook-registry 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ce32ea0c6c56d5eacaeb814fbed9960547021d3edd010ded1425f180536b20ab" "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" -"checksum socket2 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" +"checksum socket2 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "97e0e9fd577458a4f61fb91fcb559ea2afecc54c934119421f9f5d3d5b1a1057" "checksum sqlformat 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "74c70f0235b9925cbb106c52af1a28b5ea4885a8b851e328b8562e257a389c2d" "checksum sqlx 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d1f8eb788e1733bdbf69a8f97087213ebdebd253d4782c686d3cfd586b0a9453" "checksum sqlx-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e647268dc1239dd9db2d3103fefd61151971a2214882cff9efea6f60cf50840" "checksum sqlx-macros 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7acd32cba35531345f8a94a038874baf00efd0b701c913f5b00d2870b474b64" "checksum sqlx-rt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "63fc5454c9dd7aaea3a0eeeb65ca40d06d0d8e7413a8184f7c3a3ffa5056190b" "checksum static_assertions 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum stringprep 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" "checksum strsim 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" -"checksum subtle 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" +"checksum subtle 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" "checksum syn 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" "checksum synstructure 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" "checksum tap 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36474e732d1affd3a6ed582781b3683df3d0563714c59c39591e8ff707cf078e" "checksum telegram-bot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc9552e972bcb551705fcad45bd0b86eca12a22379db36cdfa6d053e1a19b2de" "checksum telegram-bot-raw 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e4fc120e2b85d639fc932a4aa7c1b6a5f1189fb86948d7a02037d1d8f1ef559" Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "rsstg" -version = "0.1.13" +version = "0.1.14" authors = ["arcade"] edition = "2018" [dependencies] chrono = "*" Index: src/main.rs ================================================================== --- src/main.rs +++ src/main.rs @@ -53,11 +53,11 @@ sources: Arc::new(Mutex::new(HashSet::new())), }; let clone = core.clone(); tokio::spawn(async move { if let Err(err) = &clone.autofetch().await { - if let Err(err) = clone.debug(&format!("🛑 {:?}", err)) { + if let Err(err) = clone.debug(&format!("🛑 {:?}", err), None) { eprintln!("Autofetch error: {}", err); }; } }); Ok(core) @@ -65,12 +65,15 @@ fn stream(&self) -> telegram_bot::UpdatesStream { self.tg.stream() } - fn debug(&self, msg: &str) -> Result<()> { - self.tg.spawn(SendMessage::new(self.owner_chat, msg)); + fn debug(&self, msg: &str, target: Option) -> Result<()> { + self.tg.spawn(SendMessage::new(match target { + Some(user) => user, + None => self.owner_chat, + }, msg)); Ok(()) } async fn check(&self, id: i32, owner: S, real: bool) -> Result<()> where S: Into { @@ -280,11 +283,11 @@ owner_chat: UserId::new(owner), ..self.clone() }; tokio::spawn(async move { if let Err(err) = clone.check(source_id, owner, true).await { - if let Err(err) = clone.debug(&format!("🛑 {:?}", err)) { + if let Err(err) = clone.debug(&format!("🛑 {:?}", err), None) { eprintln!("Check error: {}", err); }; }; }); } else { @@ -334,28 +337,30 @@ settings.merge(config::File::with_name("rsstg"))?; let core = Core::new(settings).await?; let mut stream = core.stream(); + let mut reply_to: Option; loop { + reply_to = None; match stream.next().await { Some(update) => { - if let Err(err) = handle(update?, &core).await { - core.debug(&format!("🛑 {:?}", err))?; + if let Err(err) = handle(update?, &core, &mut reply_to).await { + core.debug(&format!("🛑 {:?}", err), reply_to)?; }; }, None => { - core.debug(&format!("🛑 None error."))?; + core.debug(&format!("🛑 None error."), None)?; } }; } //Ok(()) } -async fn handle(update: telegram_bot::Update, core: &Core) -> Result<()> { +async fn handle(update: telegram_bot::Update, core: &Core, mut _reply_to: &Option) -> Result<()> { lazy_static! { static ref RE_USERNAME: Regex = Regex::new(r"^@[a-zA-Z][a-zA-Z0-9_]+$").unwrap(); static ref RE_LINK: Regex = Regex::new(r"^https?://[a-zA-Z.0-9-]+/[-_a-zA-Z.0-9/?=]+$").unwrap(); static ref RE_IV_HASH: Regex = Regex::new(r"^[a-f0-9]{14}$").unwrap(); } @@ -382,10 +387,11 @@ }, // add "/add" | "/update" => { + _reply_to = &Some(message.from.id); let mut source_id: Option = None; let at_least = "Requires at least 3 parameters."; if cmd == "/update" { let first_word = words.next() .context(at_least)?;