Index: Cargo.lock ================================================================== --- Cargo.lock +++ Cargo.lock @@ -2098,11 +2098,11 @@ "quick-xml", ] [[package]] name = "rsstg" -version = "0.4.1" +version = "0.4.2" dependencies = [ "anyhow", "async-std", "atom_syndication", "chrono", @@ -2728,13 +2728,13 @@ "windows-sys 0.59.0", ] [[package]] name = "tgbot" -version = "0.37.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5280aeee7c4600846513c67329304a100e6ab4295e6389e6194aa16b5e73595" +checksum = "1f93a57a73ceda468ee27ccfa9ee21b35891d72ad0ea9c48ba24ca96621f25ca" dependencies = [ "async-stream", "bytes", "derive_more", "futures-util", Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,18 +1,18 @@ [package] name = "rsstg" -version = "0.4.1" +version = "0.4.2" authors = ["arcade"] edition = "2021" [dependencies] anyhow = "1.0.86" async-std = { version = "1.12.0", features = [ "attributes", "tokio1" ] } atom_syndication = { version = "0.12.4", features = [ "with-serde" ] } chrono = "0.4.38" config = { version = "0.15", default-features = false, features = [ "toml" ] } -tgbot = "0.37" +tgbot = "0.38" futures = "0.3.30" futures-util = "0.3.30" lazy_static = "1.5.0" regex = "1.10.6" reqwest = { version = "0.12.7", features = [ "brotli", "socks", "deflate" ]} Index: src/core.rs ================================================================== --- src/core.rs +++ src/core.rs @@ -199,14 +199,22 @@ if next_fetch < now { if let (Some(owner), Some(source_id)) = (row.owner, row.source_id) { let clone = Core { owner_chat: ChatPeerId::from(owner), ..self.clone() + }; + let source = { + let mut conn = self.db.begin().await?; + match conn.get_one(owner, source_id).await { + Ok(Some(source)) => source.to_string(), + Ok(None) => "Source not found in database?".to_string(), + Err(err) => format!("Failed to fetch source data:\n{err}"), + } }; task::spawn(async move { if let Err(err) = clone.check(source_id, true).await { - if let Err(err) = clone.send(&format!("šŸ›‘ {err:?}"), None, None).await { + if let Err(err) = clone.send(&format!("{source}\nšŸ›‘ {err:?}"), None, None).await { eprintln!("Check error: {err:?}"); // clone.disable(&source_id, owner).await.unwrap(); }; }; }); @@ -218,27 +226,17 @@ }; Ok(delay.to_std()?) } pub async fn list (&self, owner: UserPeerId) -> Result { - let mut reply: Vec> = vec![]; + let mut reply: Vec = vec![]; reply.push("Channels:".into()); let mut conn = self.db.begin().await?; for row in conn.get_list(owner).await? { - reply.push(format!("\n\\#ļøāƒ£ {} \\*ļøāƒ£ `{}` {}\nšŸ”— `{}`", row.source_id, row.channel, - match row.enabled { - true => "šŸ”„ enabled", - false => "ā›” disabled", - }, row.url).into()); - if let Some(hash) = &row.iv_hash { - reply.push(format!("IV: `{hash}`").into()); - } - if let Some(re) = &row.url_re { - reply.push(format!("RE: `{re}`").into()); - } + reply.push(row.to_string()); }; - Ok(reply.join("\n")) + Ok(reply.join("\n\n")) } } impl UpdateHandler for Core { async fn handle (&self, update: Update) { Index: src/sql.rs ================================================================== --- src/sql.rs +++ src/sql.rs @@ -1,6 +1,9 @@ -use std::borrow::Cow; +use std::{ + borrow::Cow, + fmt, +}; use anyhow::{ Result, bail, }; @@ -27,10 +30,27 @@ pub enabled: bool, pub url: String, pub iv_hash: Option, pub url_re: Option, } + +impl fmt::Display for List { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { + write!(f, "\\#ļøāƒ£ {} \\*ļøāƒ£ `{}` {}\nšŸ”— `{}`", self.source_id, self.channel, + match self.enabled { + true => "šŸ”„ enabled", + false => "ā›” disabled", + }, self.url)?; + if let Some(iv_hash) = &self.iv_hash { + write!(f, "\nIV: `{iv_hash}`")?; + } + if let Some(url_re) = &self.url_re { + write!(f, "\nRE: `{url_re}`")?; + } + Ok(()) + } +} #[derive(sqlx::FromRow, Debug)] pub struct Source { pub channel_id: i64, pub url: String, @@ -156,10 +176,19 @@ let source: Vec = sqlx::query_as("select source_id, channel, enabled, url, iv_hash, url_re from rsstg_source where owner = $1 order by source_id") .bind(owner.into()) .fetch_all(&mut *self.conn).await?; Ok(source) } + + pub async fn get_one (&mut self, owner: I, id: i32) -> Result> + where I: Into { + let source: Option = sqlx::query_as("select source_id, channel, enabled, url, iv_hash, url_re from rsstg_source where owner = $1 and source_id = $2") + .bind(owner.into()) + .bind(id) + .fetch_optional(&mut *self.conn).await?; + Ok(source) + } pub async fn get_source (&mut self, id: i32, owner: I) -> Result where I: Into { let source: Source = sqlx::query_as("select channel_id, url, iv_hash, owner, url_re from rsstg_source where source_id = $1 and owner = $2") .bind(id)