Index: src/command.rs ================================================================== --- src/command.rs +++ src/command.rs @@ -66,18 +66,24 @@ let iv_hash = match iv_hash { Some(hash) => { if ! RE_IV_HASH.is_match(hash) { bail!("IV hash should be 14 hex digits.\nNot {:?}", hash); }; - Some(*hash) + match *hash { + "-" => None, + thing => Some(thing), + } }, None => None, }; let url_re = match url_re { Some(re) => { let _url_rex = ReplaceCommand::new(re).context("Regexp parsing error:")?; - Some(*re) + match *re { + "-" => None, + thing => Some(thing), + } }, None => None, }; let channel_id = i64::from(core.tg.send(telegram_bot::GetChat::new(telegram_bot::types::ChatRef::ChannelUsername(channel.to_string()))).await?.id()); let chan_adm = core.tg.send(telegram_bot::GetChatAdministrators::new(telegram_bot::types::ChatRef::ChannelUsername(channel.to_string()))).await Index: src/core.rs ================================================================== --- src/core.rs +++ src/core.rs @@ -7,10 +7,11 @@ postgres::PgPoolOptions, Row, }; use rss; use std::{ + borrow::Cow, collections::{ BTreeMap, HashSet, }, sync::{Arc, Mutex}, @@ -59,28 +60,30 @@ pub fn stream(&self) -> telegram_bot::UpdatesStream { self.tg.stream() } - pub fn send(&self, msg: S, target: Option, parse_mode: Option) -> Result<()> - where S: Into { - let msg: String = msg.into(); + pub fn send<'a, S>(&self, msg: S, target: Option, parse_mode: Option) -> Result<()> + where S: Into> { + let msg = msg.into(); + let parse_mode = match parse_mode { Some(mode) => mode, None => telegram_bot::types::ParseMode::Html, }; self.tg.spawn(telegram_bot::SendMessage::new(match target { Some(user) => user, None => self.owner_chat, - }, msg.to_owned()).parse_mode(parse_mode)); + }, msg).parse_mode(parse_mode)); Ok(()) } pub async fn check(&self, id: &i32, owner: S, real: bool) -> Result where S: Into { + let owner = owner.into(); + let mut posted: i32 = 0; - let owner: i64 = owner.into(); let id = { let mut set = self.sources.lock().unwrap(); match set.get(id) { Some(id) => id.clone(), None => { @@ -187,11 +190,12 @@ Ok(format!("Posted: {}", &posted)) } pub async fn delete(&self, source_id: &i32, owner: S) -> Result where S: Into { - let owner: i64 = owner.into(); + let owner = owner.into(); + let mut conn = self.pool.acquire().await .with_context(|| format!("Delete fetch conn:\n{:?}", &self.pool))?; match sqlx::query("delete from rsstg_source where source_id = $1 and owner = $2;") .bind(source_id) .bind(owner) @@ -203,11 +207,12 @@ } } pub async fn clean(&self, source_id: &i32, owner: S) -> Result where S: Into { - let owner: i64 = owner.into(); + let owner = owner.into(); + let mut conn = self.pool.acquire().await .with_context(|| format!("Clean fetch conn:\n{:?}", &self.pool))?; match sqlx::query("delete from rsstg_post p using rsstg_source s where p.source_id = $1 and owner = $2 and p.source_id = s.source_id;") .bind(source_id) .bind(owner) @@ -219,11 +224,12 @@ } } pub async fn enable(&self, source_id: &i32, owner: S) -> Result<&str> where S: Into { - let owner: i64 = owner.into(); + let owner = owner.into(); + let mut conn = self.pool.acquire().await .with_context(|| format!("Enable fetch conn:\n{:?}", &self.pool))?; match sqlx::query("update rsstg_source set enabled = true where source_id = $1 and owner = $2") .bind(source_id) .bind(owner) @@ -236,11 +242,12 @@ } } pub async fn disable(&self, source_id: &i32, owner: S) -> Result<&str> where S: Into { - let owner: i64 = owner.into(); + let owner = owner.into(); + let mut conn = self.pool.acquire().await .with_context(|| format!("Disable fetch conn:\n{:?}", &self.pool))?; match sqlx::query("update rsstg_source set enabled = false where source_id = $1 and owner = $2") .bind(source_id) .bind(owner) @@ -253,11 +260,12 @@ } } pub async fn update(&self, update: Option, channel: &str, channel_id: i64, url: &str, iv_hash: Option<&str>, url_re: Option<&str>, owner: S) -> Result where S: Into { - let owner: i64 = owner.into(); + let owner = owner.into(); + let mut conn = self.pool.acquire().await .with_context(|| format!("Update fetch conn:\n{:?}", &self.pool))?; match match update { Some(id) => { @@ -335,30 +343,35 @@ } pub async fn list(&self, owner: S) -> Result where S: Into { let owner = owner.into(); + let mut reply = vec![]; let mut conn = self.pool.acquire().await .with_context(|| format!("List fetch conn:\n{:?}", &self.pool))?; reply.push("Channels:".to_string()); - let rows = sqlx::query("select source_id, channel, enabled, url, iv_hash from rsstg_source where owner = $1 order by source_id") + let rows = sqlx::query("select source_id, channel, enabled, url, iv_hash, url_re from rsstg_source where owner = $1 order by source_id") .bind(owner) .fetch_all(&mut conn).await?; for row in rows.iter() { let source_id: i32 = row.try_get("source_id")?; let username: &str = row.try_get("channel")?; let enabled: bool = row.try_get("enabled")?; let url: &str = row.try_get("url")?; let iv_hash: Option<&str> = row.try_get("iv_hash")?; + let url_re: Option<&str> = row.try_get("url_re")?; reply.push(format!("\n\\#ļøāƒ£ {} \\*ļøāƒ£ `{}` {}\nšŸ”— `{}`", source_id, username, match enabled { true => "šŸ”„ enabled", false => "ā›” disabled", }, url)); if let Some(hash) = iv_hash { - reply.push(format!("IV `{}`", hash)); + reply.push(format!("IV: `{}`", hash)); + } + if let Some(re) = url_re { + reply.push(format!("RE: `{}`", re)); } }; Ok(reply.join("\n")) } }