Overview
Comment: | bump and rewrite all database access to macros |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9910c2209c547a58b1997b52c1ea8821 |
User & Date: | arcade on 2023-08-04 15:41:44.221 |
Other Links: | manifest | tags |
Context
2023-08-04
| ||
16:19 | v0.2.20: fix bug with sending wrong url in prev build, fix StreamExt, autodisable sources for users who blocked bot check-in: 3dc9cddd4d user: arcade tags: trunk | |
15:41 | bump and rewrite all database access to macros check-in: 9910c2209c user: arcade tags: trunk | |
2023-07-30
| ||
11:19 | bump, fix proxy string handling check-in: 9d8a6738fd user: arcade tags: trunk | |
Changes
Modified Cargo.lock
from [7a2505f143]
to [4cf3b2a4c1].
︙ | ︙ | |||
229 230 231 232 233 234 235 | name = "async-trait" version = "0.1.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" dependencies = [ "proc-macro2", "quote", | | | 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | name = "async-trait" version = "0.1.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc6dde6e4ed435a4c1ee4e73592f5ba9da2151af10076cc04858746af9352d09" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "atoi" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" |
︙ | ︙ | |||
400 401 402 403 404 405 406 | name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" | | | > > > | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" dependencies = [ "libc", ] [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" |
︙ | ︙ | |||
1035 1036 1037 1038 1039 1040 1041 | name = "futures-macro" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", | | | 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | name = "futures-macro" version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "futures-rustls" version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2411eed028cdf8c8034eaf21f9915f956b6c3abec4d4c7949ee67f0721127bd" |
︙ | ︙ | |||
1542 1543 1544 1545 1546 1547 1548 | name = "linux-raw-sys" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" | | | | 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 | name = "linux-raw-sys" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "lock_api" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" dependencies = [ |
︙ | ︙ | |||
1798 1799 1800 1801 1802 1803 1804 | name = "openssl-macros" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", | | | 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 | name = "openssl-macros" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" |
︙ | ︙ | |||
1926 1927 1928 1929 1930 1931 1932 | name = "pin-project-internal" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", | | | 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 | name = "pin-project-internal" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "pin-project-lite" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" |
︙ | ︙ | |||
2418 2419 2420 2421 2422 2423 2424 | "libc", "linux-raw-sys 0.3.8", "windows-sys", ] [[package]] name = "rustix" | | | | | 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 | "libc", "linux-raw-sys 0.3.8", "windows-sys", ] [[package]] name = "rustix" version = "0.38.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f" dependencies = [ "bitflags 2.3.3", "errno", "libc", "linux-raw-sys 0.4.5", "windows-sys", ] [[package]] name = "rustls" version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" |
︙ | ︙ | |||
2530 2531 2532 2533 2534 2535 2536 | name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" | | | | | | | 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 | name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" version = "1.0.181" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d3e73c93c3240c0bda063c239298e633114c69a888c3e37ca8bb33f343e9890" dependencies = [ "serde_derive", ] [[package]] name = "serde-value" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" dependencies = [ "ordered-float", "serde", ] [[package]] name = "serde_derive" version = "1.0.181" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be02f6cb0cd3a5ec20bbcfbcbd749f57daddb1a0882dc2e46a6c236c90b977ed" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "serde_json" version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c" |
︙ | ︙ | |||
2827 2828 2829 2830 2831 2832 2833 | "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "syn" | | | | 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 | "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "syn" version = "2.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] |
︙ | ︙ | |||
2885 2886 2887 2888 2889 2890 2891 | version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall 0.3.5", | | | | 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 | version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.0", "redox_syscall 0.3.5", "rustix 0.38.6", "windows-sys", ] [[package]] name = "thiserror" version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "time" version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" |
︙ | ︙ | |||
3156 3157 3158 3159 3160 3161 3162 | name = "tracing-attributes" version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", | | | 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 | name = "tracing-attributes" version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", ] [[package]] name = "tracing-core" version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" |
︙ | ︙ | |||
3367 3368 3369 3370 3371 3372 3373 | checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", | | | 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 | checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", "syn 2.0.28", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" |
︙ | ︙ | |||
3401 3402 3403 3404 3405 3406 3407 | name = "wasm-bindgen-macro-support" version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", | | | 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 | name = "wasm-bindgen-macro-support" version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", "syn 2.0.28", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.87" |
︙ | ︙ |
Modified Cargo.toml
from [2ad01297e3]
to [f0efba3339].
1 2 | [package] name = "rsstg" | | | 1 2 3 4 5 6 7 8 9 10 | [package] name = "rsstg" version = "0.2.19" authors = ["arcade"] edition = "2021" [dependencies] anyhow = "*" async-std = { version = "*", features = [ "tokio1" ] } atom_syndication = { version = "*", features = [ "with-serde" ] } |
︙ | ︙ |
Modified src/core.rs
from [da1a6d4590]
to [ec9c851bcd].
1 2 3 | use anyhow::{anyhow, bail, Context, Result}; use async_std::task; use chrono::DateTime; | < | < < | 1 2 3 4 5 6 7 8 9 10 11 | use anyhow::{anyhow, bail, Context, Result}; use async_std::task; use chrono::DateTime; use sqlx::postgres::PgPoolOptions; use std::{ borrow::Cow, collections::{ BTreeMap, HashSet, }, sync::{Arc, Mutex}, |
︙ | ︙ | |||
95 96 97 98 99 100 101 | set.insert(id.clone()); id.clone() }, } }; let count = Arc::strong_count(&id); if count == 2 { | < < | < < | < < < < < < < < < < | | | | | < < | | | < < | < < | | | | | | | | | | < < < | < < | > < < | < | < < < | < < < < | < < | < < < < | < < | < < < < | < < | < < < < | < < < | > | > | < < < < < < < | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | set.insert(id.clone()); id.clone() }, } }; let count = Arc::strong_count(&id); if count == 2 { let source = sqlx::query!("select source_id, channel_id, url, iv_hash, owner, url_re from rsstg_source where source_id = $1 and owner = $2", *id, owner).fetch_one(&mut self.pool.acquire().await?).await?; let destination = match real { true => telegram_bot::UserId::new(source.channel_id), false => telegram_bot::UserId::new(source.owner), }; let mut this_fetch: Option<DateTime<chrono::FixedOffset>> = None; let mut posts: BTreeMap<DateTime<chrono::FixedOffset>, String> = BTreeMap::new(); let response = self.http_client.get(&source.url).send().await?; let status = response.status(); let content = response.bytes().await?; match rss::Channel::read_from(&content[..]) { Ok(feed) => { for item in feed.items() { if let Some(link) = item.link() { let date = match item.pub_date() { Some(feed_date) => DateTime::parse_from_rfc2822(feed_date), None => DateTime::parse_from_rfc3339(&item.dublin_core_ext().unwrap().dates()[0]), }?; let url = link; posts.insert(date, url.to_string()); } }; }, Err(err) => match err { rss::Error::InvalidStartTag => { let feed = atom_syndication::Feed::read_from(&content[..]) .with_context(|| format!("Problem opening feed url:\n{}\n{}", &source.url, status))?; for item in feed.entries() { let date = item.published().unwrap(); let url = item.links()[0].href(); posts.insert(*date, url.to_string()); }; }, rss::Error::Eof => (), _ => bail!("Unsupported or mangled content:\n{:?}\n{:#?}\n{:#?}\n", &source.url, err, status) } }; for (date, url) in posts.iter() { let post_url: Cow<str> = match source.url_re { Some(ref x) => sedregex::ReplaceCommand::new(x)?.execute(&source.url), None => url.into(), }; if let Some(exists) = sqlx::query!("select exists(select true from rsstg_post where url = $1 and source_id = $2) as exists;", &post_url, *id).fetch_one(&mut self.pool.acquire().await?).await?.exists { if ! exists { if this_fetch.is_none() || *date > this_fetch.unwrap() { this_fetch = Some(*date); }; self.tg.send( match &source.iv_hash { Some(hash) => telegram_bot::SendMessage::new(destination, format!("<a href=\"https://t.me/iv?url={}&rhash={}\"> </a>{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);", *id, date, &post_url).execute(&mut self.pool.acquire().await?).await?; task::sleep(std::time::Duration::new(4, 0)).await; }; }; posted += 1; }; posts.clear(); }; sqlx::query!("update rsstg_source set last_scrape = now() where source_id = $1;", *id).execute(&mut self.pool.acquire().await?).await?; Ok(format!("Posted: {}", &posted).into()) } pub async fn delete<S>(&self, source_id: &i32, owner: S) -> Result<Cow<'_, str>> where S: Into<i64> { let owner = owner.into(); match sqlx::query!("delete from rsstg_source where source_id = $1 and owner = $2;", source_id, owner).execute(&mut self.pool.acquire().await?).await?.rows_affected() { 0 => { Ok("No data found found.".into()) }, x => { Ok(format!("{} sources removed.", x).into()) }, } } pub async fn clean<S>(&self, source_id: &i32, owner: S) -> Result<Cow<'_, str>> where S: Into<i64> { let owner = owner.into(); 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;", source_id, owner).execute(&mut self.pool.acquire().await?).await?.rows_affected() { 0 => { Ok("No data found found.".into()) }, x => { Ok(format!("{} posts purged.", x).into()) }, } } pub async fn enable<S>(&self, source_id: &i32, owner: S) -> Result<&str> where S: Into<i64> { let owner = owner.into(); match sqlx::query!("update rsstg_source set enabled = true where source_id = $1 and owner = $2", source_id, owner).execute(&mut self.pool.acquire().await?).await?.rows_affected() { 1 => { Ok("Source enabled.") }, 0 => { Ok("Source not found.") }, _ => { Err(anyhow!("Database error.")) }, } } pub async fn disable<S>(&self, source_id: &i32, owner: S) -> Result<&str> where S: Into<i64> { let owner = owner.into(); match sqlx::query!("update rsstg_source set enabled = false where source_id = $1 and owner = $2", source_id, owner).execute(&mut self.pool.acquire().await?).await?.rows_affected() { 1 => { Ok("Source disabled.") }, 0 => { Ok("Source not found.") }, _ => { Err(anyhow!("Database error.")) }, } } pub async fn update<S>(&self, update: Option<i32>, channel: &str, channel_id: i64, url: &str, iv_hash: Option<&str>, url_re: Option<&str>, owner: S) -> Result<&str> where S: Into<i64> { let owner = owner.into(); match match update { Some(id) => { sqlx::query!("update rsstg_source set channel_id = $2, url = $3, iv_hash = $4, owner = $5, channel = $6, url_re = $7 where source_id = $1", id, channel_id, url, iv_hash, owner, channel, url_re).execute(&mut self.pool.acquire().await?).await }, None => { sqlx::query!("insert into rsstg_source (channel_id, url, iv_hash, owner, channel, url_re) values ($1, $2, $3, $4, $5, $6)", channel_id, url, iv_hash, owner, channel, url_re).execute(&mut self.pool.acquire().await?).await }, } { Ok(_) => Ok(match update { Some(_) => "Channel updated.", None => "Channel added.", }), Err(sqlx::Error::Database(err)) => { match err.downcast::<sqlx::postgres::PgDatabaseError>().routine() { Some("_bt_check_unique", ) => { |
︙ | ︙ | |||
309 310 311 312 313 314 315 | bail!("Sorry, unknown error:\n{:#?}\n", err); }, } } async fn autofetch(&self) -> Result<std::time::Duration> { let mut delay = chrono::Duration::minutes(1); | < < | | < < | | > | | | | | | | | | | | > | | > < < | < | < < < < < < | | | | | | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | bail!("Sorry, unknown error:\n{:#?}\n", err); }, } } async fn autofetch(&self) -> Result<std::time::Duration> { let mut delay = chrono::Duration::minutes(1); let now = chrono::Local::now(); let mut queue = sqlx::query!(r#"select source_id, next_fetch as "next_fetch: DateTime<chrono::Local>", owner from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';"#) .fetch_all(&mut self.pool.acquire().await?).await?; for row in queue.iter() { if let Some(next_fetch) = row.next_fetch { if next_fetch < now { if let (Some(owner), Some(source_id)) = (row.owner, row.source_id) { let clone = Core { owner_chat: telegram_bot::UserId::new(owner), ..self.clone() }; task::spawn(async move { if let Err(err) = clone.check(&source_id, owner, true).await { if let Err(err) = clone.send(&format!("š {:?}", err), None, None).await { eprintln!("Check error: {}", err); }; }; }); } } else if next_fetch - now < delay { delay = next_fetch - now; } } }; queue.clear(); Ok(delay.to_std()?) } pub async fn list<S>(&self, owner: S) -> Result<String> where S: Into<i64> { let owner = owner.into(); let mut reply: Vec<Cow<str>> = vec![]; 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", owner).fetch_all(&mut self.pool.acquire().await?).await?; for row in rows.iter() { 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()); } }; Ok(reply.join("\n")) } } |