Index: src/command.rs ================================================================== --- src/command.rs +++ src/command.rs @@ -63,26 +63,30 @@ if ! RE_LINK.is_match(&url) { bail!("Link should be a link to atom/rss feed, something like \"https://domain/path\".\nNot {:?}", &url); } 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); - }; match *hash { "-" => None, - thing => Some(thing), + thing => { + if ! RE_IV_HASH.is_match(thing) { + bail!("IV hash should be 14 hex digits.\nNot {:?}", thing); + }; + Some(thing) + }, } }, None => None, }; let url_re = match url_re { Some(re) => { - let _url_rex = ReplaceCommand::new(re).context("Regexp parsing error:")?; match *re { "-" => None, - thing => Some(thing), + thing => { + let _url_rex = ReplaceCommand::new(thing).context("Regexp parsing error:")?; + 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()); Index: src/core.rs ================================================================== --- src/core.rs +++ src/core.rs @@ -114,11 +114,13 @@ true => telegram_bot::UserId::new(channel_id), false => telegram_bot::UserId::new(row.try_get("owner")?), }; let mut this_fetch: Option> = None; let mut posts: BTreeMap, String> = BTreeMap::new(); - let content = reqwest::get(url).await?.bytes().await?; + let response = reqwest::get(url).await?; + let status = response.status(); + let content = response.bytes().await?; match rss::Channel::read_from(&content[..]) { Ok(feed) => { for item in feed.items() { match item.link() { Some(link) => { @@ -134,19 +136,19 @@ }; }, Err(err) => match err { rss::Error::InvalidStartTag => { let feed = atom_syndication::Feed::read_from(&content[..]) - .with_context(|| format!("Problem opening feed url:\n{}", &url))?; + .with_context(|| format!("Problem opening feed url:\n{}\n{}", &url, status))?; for item in feed.entries() { let date = item.published().unwrap(); let url = item.links()[0].href(); posts.insert(date.clone(), url.into()); }; }, rss::Error::Eof => (), - _ => bail!("Unsupported or mangled content:\n{:?}\n{:#?}\n", &url, err) + _ => bail!("Unsupported or mangled content:\n{:?}\n{:#?}\n{:#?}\n", &url, err, status) } }; for (date, url) in posts.iter() { let mut conn = self.pool.acquire().await .with_context(|| format!("Check post fetch conn:\n{:?}", &self.pool))?; @@ -157,17 +159,18 @@ .with_context(|| format!("Check post:\n{:?}", &conn))?; let exists: bool = row.try_get("exists")?; if ! exists { if this_fetch == None || *date > this_fetch.unwrap() { this_fetch = Some(*date); + }; + let post_url = match url_re { + Some(ref x) => x.execute(url).to_string(), + None => url.to_string(), }; self.tg.send( match iv_hash { - Some(hash) => telegram_bot::SendMessage::new(destination, format!(" {0}", match url_re { - Some(ref x) => x.execute(url).to_string(), - None => url.to_string(), - }, hash)), - None => telegram_bot::SendMessage::new(destination, format!("{}", url)), + Some(hash) => telegram_bot::SendMessage::new(destination, format!(" {0}", post_url, hash)), + None => telegram_bot::SendMessage::new(destination, format!("{}", post_url)), }.parse_mode(telegram_bot::types::ParseMode::Html)).await .context("Can't post message:")?; sqlx::query("insert into rsstg_post (source_id, posted, url) values ($1, $2, $3);") .bind(*id) .bind(date)