Index: Cargo.lock ================================================================== --- Cargo.lock +++ Cargo.lock @@ -52,13 +52,13 @@ "alloc-no-stdlib", ] [[package]] name = "anyhow" -version = "1.0.47" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d9ff5d688f1c13395289f67db01d4826b46dd694e7580accdc3e8430f2d98e" +checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" [[package]] name = "arrayvec" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -333,13 +333,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" [[package]] name = "crc32fast" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" dependencies = [ "cfg-if 1.0.0", ] [[package]] @@ -612,13 +612,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "encoding_rs" -version = "0.8.29" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a74ea89a0a1b98f6332de42c95baff457ada66d1cb4030f9ff151b2041a1c746" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ "cfg-if 1.0.0", ] [[package]] @@ -714,13 +714,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +checksum = "8cd0210d8c325c245ff06fd95a3b13689a1a276ac8cfa8e8720cb840bfb84b9e" dependencies = [ "futures-channel", "futures-core", "futures-executor", "futures-io", @@ -729,23 +729,23 @@ "futures-util", ] [[package]] name = "futures-channel" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27" dependencies = [ "futures-core", "futures-sink", ] [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445" [[package]] name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -755,13 +755,13 @@ "num_cpus", ] [[package]] name = "futures-executor" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97" dependencies = [ "futures-core", "futures-task", "futures-util", ] @@ -777,57 +777,52 @@ "parking_lot 0.11.2", ] [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11" [[package]] name = "futures-macro" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +checksum = "a89f17b21645bc4ed773c69af9c9a0effd4a3f1a3876eadd453469f8854e7fdd" dependencies = [ - "autocfg 1.0.1", - "proc-macro-hack", "proc-macro2", "quote", "syn", ] [[package]] name = "futures-sink" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" +checksum = "996c6442437b62d21a32cd9906f9c41e7dc1e19a9579843fad948696769305af" [[package]] name = "futures-task" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" +checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12" [[package]] name = "futures-util" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e" dependencies = [ - "autocfg 1.0.1", "futures-channel", "futures-core", "futures-io", "futures-macro", "futures-sink", "futures-task", "memchr", "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] [[package]] name = "generic-array" @@ -1155,13 +1150,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" [[package]] name = "itertools" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" dependencies = [ "either", ] [[package]] @@ -1208,13 +1203,13 @@ "static_assertions", ] [[package]] name = "libc" -version = "0.2.107" +version = "0.2.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219" +checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01" [[package]] name = "linked-hash-map" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1645,37 +1640,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" +checksum = "d1a3ea4f0dd7f1f3e512cf97bf100819aa547f36a6eccac8dbaae839eb92363e" [[package]] name = "ppv-lite86" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a" dependencies = [ "unicode-xid", ] [[package]] @@ -1998,13 +1981,13 @@ "winreg 0.6.2", ] [[package]] name = "reqwest" -version = "0.11.6" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d2927ca2f685faf0fc620ac4834690d29e7abb153add10f5812eef20b5e280" +checksum = "07bea77bc708afa10e59905c3d4af7c8fd43c9214251673095ff8b14345fcbc5" dependencies = [ "async-compression", "base64 0.13.0", "bytes 1.1.0", "encoding_rs", @@ -2046,21 +2029,21 @@ "reqwest 0.9.24", ] [[package]] name = "rsstg" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "atom_syndication", "chrono", "config", - "futures 0.3.17", + "futures 0.3.18", "futures-util", "lazy_static", "regex", - "reqwest 0.11.6", + "reqwest 0.11.7", "rss", "sedregex", "sqlx", "telegram-bot", "tokio 1.14.0", @@ -2087,13 +2070,13 @@ "semver", ] [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568" [[package]] name = "schannel" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2204,13 +2187,13 @@ "syn", ] [[package]] name = "serde_json" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063bf466a64011ac24040a49009724ee60a57da1b437617ceb32e53ad61bfb19" +checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527" dependencies = [ "itoa", "ryu", "serde 1.0.130", ] @@ -2441,13 +2424,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] @@ -2468,11 +2451,11 @@ name = "telegram-bot" version = "0.9.0" source = "git+https://github.com/telegram-rs/telegram-bot#65ad5cfd578e9a1260ce6daac714eb2153c0bec7" dependencies = [ "bytes 1.1.0", - "futures 0.3.17", + "futures 0.3.18", "hyper 0.14.15", "hyper-tls 0.5.0", "multipart", "telegram-bot-raw", "tokio 1.14.0", @@ -3020,13 +3003,13 @@ "wasm-bindgen", ] [[package]] name = "whoami" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c33ac5ee236a4efbf2c98967e12c6cc0c51d93a744159a52957ba206ae6ef5f7" +checksum = "524b58fa5a20a2fb3014dd6358b70e6579692a56ef6fce928834e488f42f65e8" dependencies = [ "wasm-bindgen", "web-sys", ] Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "rsstg" -version = "0.2.3" +version = "0.2.4" authors = ["arcade"] edition = "2018" [dependencies] anyhow = "*" Index: rsstg.sql ================================================================== --- rsstg.sql +++ rsstg.sql @@ -6,11 +6,11 @@ source_id serial, channel text not null, channel_id integer not null, url text not null, last_scrape not null timestamptz default now(), - enabled boolean not null default false, + enabled boolean not null default true, iv_hash text, owner bigint not null); create unique index rsstg_source__source_id on rsstg_source(source_id); create unique index rsstg_source__channel_id__owner on rsstg_source(channel_id, owner); create index rsstg_source__owner on rsstg_source(owner); Index: src/command.rs ================================================================== --- src/command.rs +++ src/command.rs @@ -20,20 +20,18 @@ Ok(()) } pub async fn command(core: &Core, sender: telegram_bot::UserId, command: Vec<&str>) -> Result<()> { core.send( match &command[1].parse::() { - Err(err) => format!("I need a number\\.\n{}", &err), + Err(err) => format!("I need a number\\.\n{}", &err).into(), Ok(number) => match command[0] { "/check" => core.check(&number, sender, false).await .context("Channel check failed.")?, "/clean" => core.clean(&number, sender).await?, - "/enable" => core.enable(&number, sender).await? - .to_string(), + "/enable" => core.enable(&number, sender).await?.into(), "/delete" => core.delete(&number, sender).await?, - "/disable" => core.disable(&number, sender).await? - .to_string(), + "/disable" => core.disable(&number, sender).await?.into(), _ => bail!("Command {} not handled.", &command[0]), }, }, Some(sender), None)?; Ok(()) } @@ -87,12 +85,13 @@ } } }, 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 + let s_channel = &channel.to_string(); + let channel_id = i64::from(core.tg.send(telegram_bot::GetChat::new(telegram_bot::types::ChatRef::ChannelUsername(s_channel.into()))).await?.id()); + let chan_adm = core.tg.send(telegram_bot::GetChatAdministrators::new(telegram_bot::types::ChatRef::ChannelUsername(s_channel.into()))).await .context("Sorry, I have no access to that chat.")?; let (mut me, mut user) = (false, false); for admin in chan_adm { if admin.user.id == core.my.id { me = true; Index: src/core.rs ================================================================== --- src/core.rs +++ src/core.rs @@ -75,11 +75,11 @@ None => self.owner_chat, }, msg).parse_mode(parse_mode)); Ok(()) } - pub async fn check(&self, id: &i32, owner: S, real: bool) -> Result + 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 id = { @@ -150,16 +150,16 @@ } }; for (date, url) in posts.iter() { let mut conn = self.pool.acquire().await .with_context(|| format!("Check post fetch conn:\n{:?}", &self.pool))?; - let post_url = match url_re { - Some(ref x) => x.execute(url).to_string(), - None => url.to_string(), + let post_url: Cow = match url_re { + Some(ref x) => x.execute(url).into(), + None => url.into(), }; let row = sqlx::query("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;") - .bind(&post_url) + .bind(&*post_url) .bind(*id) .fetch_one(&mut conn).await .with_context(|| format!("Check post:\n{:?}", &conn))?; let exists: bool = row.try_get("exists")?; if ! exists { @@ -172,11 +172,11 @@ }.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) - .bind(post_url) + .bind(&*post_url) .execute(&mut conn).await .with_context(|| format!("Record post:\n{:?}", &conn))?; drop(conn); tokio::time::sleep(std::time::Duration::new(4, 0)).await; }; @@ -188,14 +188,14 @@ .with_context(|| format!("Update scrape fetch conn:\n{:?}", &self.pool))?; sqlx::query("update rsstg_source set last_scrape = now() where source_id = $1;") .bind(*id) .execute(&mut conn).await .with_context(|| format!("Update scrape:\n{:?}", &conn))?; - Ok(format!("Posted: {}", &posted)) + Ok(format!("Posted: {}", &posted).into()) } - pub async fn delete(&self, source_id: &i32, owner: S) -> Result + pub async fn delete(&self, source_id: &i32, owner: S) -> Result> where S: Into { let owner = owner.into(); let mut conn = self.pool.acquire().await .with_context(|| format!("Delete fetch conn:\n{:?}", &self.pool))?; @@ -203,16 +203,16 @@ .bind(source_id) .bind(owner) .execute(&mut conn).await .with_context(|| format!("Delete source rule:\n{:?}", &self.pool))? .rows_affected() { - 0 => { Ok("No data found found.".to_string()) }, - x => { Ok(format!("{} sources removed.", x)) }, + 0 => { Ok("No data found found.".into()) }, + x => { Ok(format!("{} sources removed.", x).into()) }, } } - pub async fn clean(&self, source_id: &i32, owner: S) -> Result + pub async fn clean(&self, source_id: &i32, owner: S) -> Result> where S: Into { let owner = owner.into(); let mut conn = self.pool.acquire().await .with_context(|| format!("Clean fetch conn:\n{:?}", &self.pool))?; @@ -220,12 +220,12 @@ .bind(source_id) .bind(owner) .execute(&mut conn).await .with_context(|| format!("Clean seen posts:\n{:?}", &self.pool))? .rows_affected() { - 0 => { Ok("No data found found.".to_string()) }, - x => { Ok(format!("{} posts purged.", x)) }, + 0 => { Ok("No data found found.".into()) }, + x => { Ok(format!("{} posts purged.", x).into()) }, } } pub async fn enable(&self, source_id: &i32, owner: S) -> Result<&str> where S: Into { @@ -261,11 +261,11 @@ 0 => { Ok("Source not found.") }, _ => { Err(anyhow!("Database error.")) }, } } - 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 + 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<&str> where S: Into { let owner = owner.into(); let mut conn = self.pool.acquire().await .with_context(|| format!("Update fetch conn:\n{:?}", &self.pool))?; @@ -283,24 +283,24 @@ .bind(iv_hash) .bind(owner) .bind(channel) .bind(url_re) .execute(&mut conn).await { - Ok(_) => return Ok(String::from(match update { + Ok(_) => return Ok(match update { Some(_) => "Channel updated.", None => "Channel added.", - })), + }), Err(sqlx::Error::Database(err)) => { match err.downcast::().routine() { Some("_bt_check_unique", ) => { - return Ok("Duplicate key.".to_string()) + return Ok("Duplicate key.") }, Some(_) => { - return Ok("Database error.".to_string()) + return Ok("Database error.") }, None => { - return Ok("No database error extracted.".to_string()) + return Ok("No database error extracted.") }, }; }, Err(err) => { bail!("Sorry, unknown error:\n{:#?}\n", err); @@ -347,14 +347,14 @@ pub async fn list(&self, owner: S) -> Result where S: Into { let owner = owner.into(); - let mut reply = vec![]; + let mut reply: Vec> = vec![]; let mut conn = self.pool.acquire().await .with_context(|| format!("List fetch conn:\n{:?}", &self.pool))?; - reply.push("Channels:".to_string()); + reply.push("Channels:".into()); 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")?; @@ -365,16 +365,16 @@ 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)); + }, url).into()); if let Some(hash) = iv_hash { - reply.push(format!("IV: `{}`", hash)); + reply.push(format!("IV: `{}`", hash).into()); } if let Some(re) = url_re { - reply.push(format!("RE: `{}`", re)); + reply.push(format!("RE: `{}`", re).into()); } }; Ok(reply.join("\n")) } }