Compare commits

..

2 Commits

Author SHA1 Message Date
13612062ad Fix
Some checks are pending
Build docker image / Build-Docker-Image (push) Waiting to run
2025-08-09 23:18:10 +02:00
34f0c9feb6 Update deps and refactor 2025-08-09 23:10:40 +02:00
18 changed files with 390 additions and 359 deletions

181
Cargo.lock generated
View File

@@ -46,7 +46,7 @@ dependencies = [
"mime",
"percent-encoding",
"pin-project-lite",
"rand 0.9.1",
"rand 0.9.2",
"sha1",
"smallvec",
"tokio",
@@ -90,7 +90,7 @@ dependencies = [
"futures-core",
"futures-util",
"mio",
"socket2",
"socket2 0.5.10",
"tokio",
"tracing",
]
@@ -148,7 +148,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"smallvec",
"socket2",
"socket2 0.5.10",
"time",
"tracing",
"url",
@@ -227,9 +227,9 @@ dependencies = [
[[package]]
name = "async-lock"
version = "3.4.0"
version = "3.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
checksum = "5fd03604047cee9b6ce9de9f70c6cd540a0520c813cbd49bae61f33ab80ed1dc"
dependencies = [
"event-listener",
"event-listener-strategy",
@@ -408,9 +408,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]]
name = "bytemuck"
version = "1.23.1"
version = "1.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422"
checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677"
[[package]]
name = "bytes"
@@ -429,9 +429,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.29"
version = "1.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362"
checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e"
dependencies = [
"shlex",
]
@@ -702,9 +702,9 @@ dependencies = [
[[package]]
name = "dyn-clone"
version = "1.0.19"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005"
checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
[[package]]
name = "either"
@@ -749,9 +749,9 @@ dependencies = [
[[package]]
name = "event-listener"
version = "5.4.0"
version = "5.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae"
checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab"
dependencies = [
"concurrent-queue",
"parking",
@@ -966,9 +966,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "h2"
version = "0.4.11"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17da50a276f1e01e0ba6c029e47b7100754904ee8a278f886546e98575380785"
checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386"
dependencies = [
"atomic-waker",
"bytes",
@@ -991,9 +991,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.15.4"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"foldhash",
]
@@ -1133,9 +1133,9 @@ dependencies = [
[[package]]
name = "hyper-util"
version = "0.1.15"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f66d5bd4c6f02bf0542fad85d626775bab9258cf795a4256dcaf3161114d1df"
checksum = "8d9b05277c7e8da2c93a568989bb6207bef0112e8d17df7a6eda4a3cf143bc5e"
dependencies = [
"base64",
"bytes",
@@ -1149,7 +1149,7 @@ dependencies = [
"libc",
"percent-encoding",
"pin-project-lite",
"socket2",
"socket2 0.6.0",
"system-configuration",
"tokio",
"tower-service",
@@ -1337,15 +1337,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661"
dependencies = [
"equivalent",
"hashbrown 0.15.4",
"hashbrown 0.15.5",
"serde",
]
[[package]]
name = "io-uring"
version = "0.7.8"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4"
dependencies = [
"bitflags",
"cfg-if",
@@ -1522,10 +1522,10 @@ checksum = "b8496cc523d1f94c1385dd8f0f0c2c480b2b8aeccb5b7e4485ad6365523ae376"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
"hashbrown 0.15.4",
"hashbrown 0.15.5",
"metrics",
"quanta",
"rand 0.9.1",
"rand 0.9.2",
"rand_xoshiro",
"sketches-ddsketch",
]
@@ -1901,9 +1901,9 @@ dependencies = [
[[package]]
name = "quick-xml"
version = "0.38.0"
version = "0.38.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8927b0664f5c5a98265138b7e3f90aa19a6b21353182469ace36d4ac527b7b1b"
checksum = "9845d9dccf565065824e69f9f235fafba1587031eda353c1f1561cd6a6be78f4"
dependencies = [
"memchr",
]
@@ -1936,9 +1936,9 @@ dependencies = [
[[package]]
name = "rand"
version = "0.9.1"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha 0.9.0",
"rand_core 0.9.3",
@@ -2011,9 +2011,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.13"
version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
dependencies = [
"bitflags",
]
@@ -2158,9 +2158,9 @@ dependencies = [
[[package]]
name = "rustc-demangle"
version = "0.1.25"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f"
checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
[[package]]
name = "rustc_version"
@@ -2173,22 +2173,22 @@ dependencies = [
[[package]]
name = "rustix"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
]
[[package]]
name = "rustls"
version = "0.23.29"
version = "0.23.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1"
checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc"
dependencies = [
"once_cell",
"rustls-pki-types",
@@ -2228,9 +2228,9 @@ dependencies = [
[[package]]
name = "rustversion"
version = "1.0.21"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "ryu"
@@ -2314,9 +2314,9 @@ checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0"
[[package]]
name = "sentry"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "507ac2be9bf2da56c831da57faf1dadd81f434bd282935cdb06193d0c94e8811"
checksum = "989425268ab5c011e06400187eed6c298272f8ef913e49fcadc3fda788b45030"
dependencies = [
"httpdate",
"native-tls",
@@ -2334,9 +2334,9 @@ dependencies = [
[[package]]
name = "sentry-actix"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8402c142005ee560ae361c73ebece13a299ec3e9cce5b8654479ea9aac8dc8df"
checksum = "a5c675bdf6118764a8e265c3395c311b4d905d12866c92df52870c0223d2ffc1"
dependencies = [
"actix-http",
"actix-web",
@@ -2347,9 +2347,9 @@ dependencies = [
[[package]]
name = "sentry-backtrace"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb4416302fa5325181a120e0fe7d4afd83cd95e52a9b86afa34a8161383fe0dc"
checksum = "68e299dd3f7bcf676875eee852c9941e1d08278a743c32ca528e2debf846a653"
dependencies = [
"backtrace",
"regex",
@@ -2358,9 +2358,9 @@ dependencies = [
[[package]]
name = "sentry-contexts"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936752f42b6f651dcb257da0bfa235ecc79e82011c49ed3383c212cc582263ff"
checksum = "fac0c5d6892cd4c414492fc957477b620026fb3411fca9fa12774831da561c88"
dependencies = [
"hostname",
"libc",
@@ -2372,21 +2372,22 @@ dependencies = [
[[package]]
name = "sentry-core"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e9bd2cadaeda3af41e9fa5d14645127d6f6a4aec73da3ae38e477ecafd3682"
checksum = "deaa38b94e70820ff3f1f9db3c8b0aef053b667be130f618e615e0ff2492cbcc"
dependencies = [
"rand 0.9.1",
"rand 0.9.2",
"sentry-types",
"serde",
"serde_json",
"url",
]
[[package]]
name = "sentry-debug-images"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1e074fe9a0970c91999b23ed3195e6e30990d589fba3a68f20a1686af0f5cda"
checksum = "00950648aa0d371c7f57057434ad5671bd4c106390df7e7284739330786a01b6"
dependencies = [
"findshlibs",
"sentry-core",
@@ -2394,9 +2395,9 @@ dependencies = [
[[package]]
name = "sentry-panic"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4651d34f3ba649d9e6dc1268443cae6728b8f741c2f0264004f8ecf5b247330d"
checksum = "2b7a23b13c004873de3ce7db86eb0f59fe4adfc655a31f7bbc17fd10bacc9bfe"
dependencies = [
"sentry-backtrace",
"sentry-core",
@@ -2404,9 +2405,9 @@ dependencies = [
[[package]]
name = "sentry-tracing"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c25c47d36bc80c74d26d568ffe970c37b337c061b7234ad6f2d159439c16f000"
checksum = "fac841c7050aa73fc2bec8f7d8e9cb1159af0b3095757b99820823f3e54e5080"
dependencies = [
"bitflags",
"sentry-backtrace",
@@ -2417,13 +2418,13 @@ dependencies = [
[[package]]
name = "sentry-types"
version = "0.41.0"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08e7154abe2cd557f26fd70038452810748aefdf39bc973f674421224b147c1"
checksum = "e477f4d4db08ddb4ab553717a8d3a511bc9e81dde0c808c680feacbb8105c412"
dependencies = [
"debugid",
"hex",
"rand 0.9.1",
"rand 0.9.2",
"serde",
"serde_json",
"thiserror 2.0.12",
@@ -2454,9 +2455,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.140"
version = "1.0.142"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7"
dependencies = [
"itoa",
"memchr",
@@ -2546,9 +2547,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.5"
version = "1.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410"
checksum = "b2a4719bff48cee6b39d12c020eeb490953ad2443b7055bd0b21fca26bd8c28b"
dependencies = [
"libc",
]
@@ -2561,9 +2562,9 @@ checksum = "c1e9a774a6c28142ac54bb25d25562e6bcf957493a184f15ad4eebccb23e410a"
[[package]]
name = "slab"
version = "0.4.10"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"
[[package]]
name = "smallvec"
@@ -2602,6 +2603,16 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "socket2"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807"
dependencies = [
"libc",
"windows-sys 0.59.0",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@@ -2635,20 +2646,19 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "strum"
version = "0.27.1"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32"
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
[[package]]
name = "strum_macros"
version = "0.27.1"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8"
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn",
]
@@ -2919,9 +2929,9 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.46.1"
version = "1.47.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
dependencies = [
"backtrace",
"bytes",
@@ -2932,9 +2942,9 @@ dependencies = [
"pin-project-lite",
"signal-hook-registry",
"slab",
"socket2",
"socket2 0.6.0",
"tokio-macros",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -2981,9 +2991,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.15"
version = "0.7.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df"
checksum = "14307c986784f72ef81c89db7d9e28d6ac26d16213b109ea501696195e6e3ce5"
dependencies = [
"bytes",
"futures-core",
@@ -3373,14 +3383,14 @@ version = "0.26.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75c7f0ef91146ebfb530314f5f1d24528d7f0767efbfd31dce919275413e393e"
dependencies = [
"webpki-root-certs 1.0.1",
"webpki-root-certs 1.0.2",
]
[[package]]
name = "webpki-root-certs"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86138b15b2b7d561bc4469e77027b8dd005a43dc502e9031d1f5afc8ce1f280e"
checksum = "4e4ffd8df1c57e87c325000a3d6ef93db75279dc3a231125aac571650f22b12a"
dependencies = [
"rustls-pki-types",
]
@@ -3544,7 +3554,7 @@ version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets 0.53.2",
"windows-targets 0.53.3",
]
[[package]]
@@ -3565,10 +3575,11 @@ dependencies = [
[[package]]
name = "windows-targets"
version = "0.53.2"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
@@ -3783,9 +3794,9 @@ dependencies = [
[[package]]
name = "zerovec"
version = "0.11.2"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428"
checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b"
dependencies = [
"yoke",
"zerofrom",

View File

@@ -34,7 +34,7 @@ tower-http = { version = "0.6.2", features = ["trace"] }
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
sentry-tracing = "0.41.0"
sentry-tracing = "0.42.0"
reqwest = { version = "0.12.15", features = ["json", "stream"] }
@@ -66,5 +66,5 @@ smartstring = { version = "1.0.1", features = ["serde"] }
moka = { version = "0.12.10", features = ["future"] }
sentry = { version = "0.41.0", features = ["debug-images"] }
sentry = { version = "0.42.0", features = ["debug-images"] }
anyhow = "1.0.98"

View File

@@ -41,10 +41,10 @@ async fn _update_activity(me: teloxide::types::Me, user: teloxide::types::User)
if create_or_update_user_settings(
user.id,
user.last_name.clone().unwrap_or("".to_string()),
user.first_name.clone(),
user.username.clone().unwrap_or("".to_string()),
me.username.clone().unwrap(),
&user.last_name.unwrap_or("".to_string()),
&user.first_name,
&user.username.unwrap_or("".to_string()),
&me.username.clone().unwrap_or("".to_string()),
allowed_langs,
)
.await
@@ -64,21 +64,18 @@ async fn _update_activity(me: teloxide::types::Me, user: teloxide::types::User)
fn update_user_activity_handler() -> BotHandler {
dptree::entry()
.branch(
Update::filter_callback_query().chain(dptree::filter_map_async(
|cq: CallbackQuery, bot: CacheMe<Throttle<Bot>>| async move {
_update_activity(bot.get_me().await.unwrap(), cq.from).await
},
)),
)
.branch(Update::filter_message().chain(dptree::filter_map_async(
.branch(Update::filter_callback_query().inspect_async(
|cq: CallbackQuery, bot: CacheMe<Throttle<Bot>>| async move {
_update_activity(bot.get_me().await.unwrap(), cq.from).await;
},
))
.branch(Update::filter_message().inspect_async(
|message: Message, bot: CacheMe<Throttle<Bot>>| async move {
match message.from {
Some(user) => _update_activity(bot.get_me().await.unwrap(), user.clone()).await,
None => None,
if let Some(user) = message.from {
_update_activity(bot.get_me().await.unwrap(), user).await;
}
},
)))
))
}
pub fn get_approved_handler() -> (BotHandler, BotCommands) {

View File

@@ -66,7 +66,7 @@ where
let allowed_langs = get_user_or_default_lang_codes(user_id).await;
let items_page = match books_getter(id, 1, allowed_langs.clone()).await {
let items_page = match books_getter(id, 1, allowed_langs).await {
Ok(v) => v,
Err(err) => {
bot.send_message(chat_id, "Ошибка! Попробуйте позже :(")
@@ -160,7 +160,7 @@ where
};
if page > items_page.pages {
items_page = match books_getter(id, items_page.pages, allowed_langs.clone()).await {
items_page = match books_getter(id, items_page.pages, allowed_langs).await {
Ok(v) => v,
Err(err) => {
bot.send_message(chat_id, "Ошибка! Попробуйте позже :(")

View File

@@ -97,12 +97,12 @@ async fn send_cached_message(
if _send_cached(&message, &bot, cached).await.is_ok() {
if need_delete_message {
if let MaybeInaccessibleMessage::Regular(message) = message.clone() {
if let MaybeInaccessibleMessage::Regular(message) = &message {
let _ = bot.delete_message(message.chat.id, message.id).await;
}
}
match send_donation_notification(bot.clone(), message).await {
match send_donation_notification(&bot, &message).await {
Ok(_) => (),
Err(err) => log::error!("{err:?}"),
}
@@ -119,7 +119,7 @@ async fn send_cached_message(
async fn _send_downloaded_file(
message: &MaybeInaccessibleMessage,
bot: CacheMe<Throttle<Bot>>,
bot: &CacheMe<Throttle<Bot>>,
downloaded_data: DownloadFile,
) -> BotHandlerInternal {
let DownloadFile {
@@ -134,14 +134,14 @@ async fn _send_downloaded_file(
.into_async_read()
.compat();
let document = InputFile::read(data).file_name(filename.clone());
let document = InputFile::read(data).file_name(filename);
bot.send_document(message.chat().id, document)
.caption(caption)
.send()
.await?;
send_donation_notification(bot, message.clone()).await?;
send_donation_notification(bot, message).await?;
Ok(())
}
@@ -159,7 +159,7 @@ async fn send_with_download_from_channel(
}
};
_send_downloaded_file(&message, bot.clone(), downloaded_file).await?;
_send_downloaded_file(&message, &bot, downloaded_file).await?;
if need_delete_message {
if let MaybeInaccessibleMessage::Regular(message) = message {
@@ -240,13 +240,13 @@ async fn get_download_archive_keyboard_handler(
let available_types = match command {
DownloadArchiveCommand::Sequence { id } => {
get_sequence_books_available_types(id, allowed_langs).await
get_sequence_books_available_types(id, &allowed_langs).await
}
DownloadArchiveCommand::Author { id } => {
get_author_books_available_types(id, allowed_langs).await
get_author_books_available_types(id, &allowed_langs).await
}
DownloadArchiveCommand::Translator { id } => {
get_translator_books_available_types(id, allowed_langs).await
get_translator_books_available_types(id, &allowed_langs).await
}
};
@@ -307,19 +307,20 @@ async fn send_error_message(bot: CacheMe<Throttle<Bot>>, chat_id: ChatId, messag
}
async fn send_archive_link(
bot: CacheMe<Throttle<Bot>>,
message: Box<Message>,
task: Task,
bot: &CacheMe<Throttle<Bot>>,
chat_id: ChatId,
message_id: MessageId,
task: &Task,
) -> BotHandlerInternal {
let link = format!(
"{}/api/download/{}",
config::CONFIG.public_batch_downloader_url.clone(),
config::CONFIG.public_batch_downloader_url,
task.id
);
bot.edit_message_text(
message.chat.id,
message.id,
chat_id,
message_id,
format!(
"Файл не может быть загружен в чат! \n \
Вы можете скачать его <a href=\"{link}\">по ссылке</a> (работает 3 часа)"
@@ -352,7 +353,7 @@ async fn wait_archive(
let task = loop {
interval.tick().await;
let task = match get_task(task_id.clone()).await {
let task = match get_task(&task_id).await {
Ok(v) => v,
Err(err) => {
send_error_message(bot, message.chat.id, message.id).await;
@@ -388,18 +389,18 @@ async fn wait_archive(
let content_size = task.content_size.unwrap();
if content_size > 1024 * 1024 * 1024 {
send_archive_link(bot.clone(), message.clone(), task.clone()).await?;
send_archive_link(&bot, message.chat.id, message.id, &task).await?;
return Ok(());
}
let link = format!(
"{}/api/download/{}",
config::CONFIG.batch_downloader_url.clone(),
config::CONFIG.batch_downloader_url,
task.id
);
let downloaded_data =
match download_file_by_link(task.clone().result_filename.unwrap(), link).await {
match download_file_by_link(&task.clone().result_filename.unwrap(), link).await {
Ok(v) => match v {
Some(v) => v,
None => {
@@ -416,14 +417,14 @@ async fn wait_archive(
match _send_downloaded_file(
&MaybeInaccessibleMessage::Regular(message.clone()),
bot.clone(),
&bot,
downloaded_data,
)
.await
{
Ok(_) => (),
Err(err) => {
send_archive_link(bot.clone(), message.clone(), task).await?;
send_archive_link(&bot, message.chat.id, message.id, &task).await?;
log::error!("{err:?}");
}
}

View File

@@ -13,7 +13,7 @@ use self::commands::HelpCommand;
pub async fn help_handler(message: Message, bot: CacheMe<Throttle<Bot>>) -> BotHandlerInternal {
let name = message
.from
.map(|user| user.first_name.clone())
.map(|user| user.first_name)
.unwrap_or("пользователь".to_string());
match bot

View File

@@ -93,17 +93,16 @@ where
};
if page > items_page.pages {
items_page =
match items_getter(query.clone(), items_page.pages, allowed_langs.clone()).await {
Ok(v) => v,
Err(err) => {
bot.send_message(chat_id, "Ошибка! Попробуйте позже :(")
.send()
.await?;
items_page = match items_getter(query, items_page.pages, allowed_langs).await {
Ok(v) => v,
Err(err) => {
bot.send_message(chat_id, "Ошибка! Попробуйте позже :(")
.send()
.await?;
return Err(err);
}
};
return Err(err);
}
};
}
let formatted_page = items_page.format(page, 4096);

View File

@@ -118,10 +118,10 @@ async fn settings_callback_handler(
if let Err(err) = create_or_update_user_settings(
user.id,
user.last_name.clone().unwrap_or("".to_string()),
user.first_name.clone(),
user.username.clone().unwrap_or("".to_string()),
me.username.clone().unwrap(),
&user.last_name.unwrap_or("".to_string()),
&user.first_name,
&user.username.unwrap_or("".to_string()),
&me.username.clone().unwrap(),
allowed_langs_set.clone().into_iter().collect(),
)
.await

View File

@@ -16,20 +16,20 @@ enum SupportCommand {
pub async fn support_command_handler(
message: Message,
bot: CacheMe<Throttle<Bot>>,
bot: &CacheMe<Throttle<Bot>>,
) -> BotHandlerInternal {
let username = match message.clone().from {
Some(user) => match user.is_bot {
true => match message.reply_to_message() {
Some(v) => match &v.from {
Some(v) => v.first_name.clone(),
None => "пользователь".to_string(),
Some(v) => &v.first_name,
None => "пользователь",
},
None => "пользователь".to_string(),
None => "пользователь",
},
false => user.first_name,
false => &user.first_name.clone(),
},
None => "пользователь".to_string(),
None => "пользователь",
};
let message_text = format!(
@@ -60,5 +60,7 @@ pub async fn support_command_handler(
pub fn get_support_handler() -> crate::bots::BotHandler {
Update::filter_message()
.filter_command::<SupportCommand>()
.endpoint(support_command_handler)
.endpoint(|message: Message, bot: CacheMe<Throttle<Bot>>| async move {
support_command_handler(message, &bot).await
})
}

View File

@@ -56,7 +56,7 @@ pub async fn create_task(data: CreateTaskData) -> anyhow::Result<Task> {
.await?)
}
pub async fn get_task(task_id: String) -> anyhow::Result<Task> {
pub async fn get_task(task_id: &str) -> anyhow::Result<Task> {
Ok(CLIENT
.get(format!(
"{}/api/check_archive/{task_id}",

View File

@@ -91,7 +91,7 @@ pub async fn download_file(
}
pub async fn download_file_by_link(
filename: String,
filename: &str,
link: String,
) -> anyhow::Result<Option<DownloadFile>> {
let response = CLIENT.get(link).send().await?;
@@ -102,7 +102,7 @@ pub async fn download_file_by_link(
Ok(Some(DownloadFile {
response,
filename,
filename: filename.to_string(),
caption: "".to_string(),
}))
}

View File

@@ -115,7 +115,7 @@ impl FormatInline for BookTranslator {
}
}
fn format_authors(authors: Vec<BookAuthor>, count: usize) -> String {
fn format_authors(authors: &[BookAuthor], count: usize) -> String {
if count == 0 {
return "".to_string();
}
@@ -139,7 +139,7 @@ fn format_authors(authors: Vec<BookAuthor>, count: usize) -> String {
}
}
fn format_translators(translators: Vec<BookTranslator>, count: usize) -> String {
fn format_translators(translators: &[BookTranslator], count: usize) -> String {
if count == 0 {
return "".to_string();
}
@@ -163,7 +163,7 @@ fn format_translators(translators: Vec<BookTranslator>, count: usize) -> String
}
}
fn format_sequences(sequences: Vec<Sequence>, count: usize) -> String {
fn format_sequences(sequences: &[Sequence], count: usize) -> String {
if count == 0 {
return "".to_string();
}
@@ -187,7 +187,7 @@ fn format_sequences(sequences: Vec<Sequence>, count: usize) -> String {
}
}
fn format_genres(genres: Vec<BookGenre>, count: usize) -> String {
fn format_genres(genres: &[BookGenre], count: usize) -> String {
if count == 0 {
return "".to_string();
}
@@ -395,117 +395,231 @@ impl FormatVectorsResult {
}
}
impl Book {
fn format_vectors(&self, max_size: usize) -> FormatVectorsResult {
let mut counts = FormatVectorsCounts {
authors: self.authors.len(),
translators: self.translators.len(),
sequences: self.sequences.len(),
genres: self.genres.len(),
};
fn format_vectors(
authors: &[BookAuthor],
translators: &[BookTranslator],
sequences: &[Sequence],
genres: &[BookGenre],
max_size: usize,
) -> FormatVectorsResult {
let mut counts = FormatVectorsCounts {
authors: authors.len(),
translators: translators.len(),
sequences: sequences.len(),
genres: genres.len(),
};
let mut result = FormatVectorsResult {
authors: format_authors(self.authors.clone(), counts.authors),
translators: format_translators(self.translators.clone(), counts.translators),
sequences: format_sequences(self.sequences.clone(), counts.sequences),
genres: format_genres(self.genres.clone(), counts.genres),
let mut result = FormatVectorsResult {
authors: format_authors(authors, counts.authors),
translators: format_translators(translators, counts.translators),
sequences: format_sequences(sequences, counts.sequences),
genres: format_genres(genres, counts.genres),
max_result_size: 0,
};
let max_result_size = result.len();
while result.len() > max_size && counts.can_sub() {
counts = counts.sub();
result = FormatVectorsResult {
authors: format_authors(authors, counts.authors),
translators: format_translators(translators, counts.translators),
sequences: format_sequences(sequences, counts.sequences),
genres: format_genres(genres, counts.genres),
max_result_size: 0,
};
}
let max_result_size = result.len();
result.with_max_result_size(max_result_size)
}
while result.len() > max_size && counts.can_sub() {
counts = counts.sub();
struct FormatData<'a> {
pub id: u32,
pub title: &'a str,
pub lang: &'a str,
pub annotation_exists: bool,
pub authors: &'a [BookAuthor],
pub translators: &'a [BookTranslator],
pub sequences: &'a [Sequence],
pub genres: &'a [BookGenre],
pub year: i32,
pub pages: Option<u32>,
pub position: Option<i32>,
}
result = FormatVectorsResult {
authors: format_authors(self.authors.clone(), counts.authors),
translators: format_translators(self.translators.clone(), counts.translators),
sequences: format_sequences(self.sequences.clone(), counts.sequences),
genres: format_genres(self.genres.clone(), counts.genres),
max_result_size: 0,
};
fn format_common(data: FormatData, max_size: usize) -> FormatResult {
let FormatData {
id,
title,
lang,
annotation_exists,
authors,
translators,
sequences,
genres,
year,
pages,
position,
} = data;
let book_title = {
let year_part = match year {
0 => "".to_string(),
v => format!(" | {v}г."),
};
let pages_count = match pages {
Some(1) | None => "".to_string(),
Some(v) => format!(" | {v}с."),
};
let position_prefix = match position {
Some(0) | None => "".to_string(),
Some(v) => format!("{v} | "),
};
format!("{position_prefix}📖 {title} | {lang}{year_part}{pages_count}\n")
};
let annotations = match annotation_exists {
true => {
format!("📝 Аннотация: /b_an_{id}\n")
}
false => "".to_string(),
};
result.with_max_result_size(max_result_size)
let download_command = (StartDownloadCommand { id }).to_string();
let download_links = format!("Скачать:\n📥{download_command}");
let required_data_len: usize = format!("{book_title}{annotations}{download_links}").len();
let FormatVectorsResult {
authors,
translators,
sequences,
genres,
max_result_size,
} = format_vectors(
authors,
translators,
sequences,
genres,
max_size - required_data_len,
);
let result = format!(
"{book_title}{annotations}{authors}{translators}{sequences}{genres}{download_links}"
);
let result_len = result.len();
FormatResult {
result,
current_size: result_len,
max_size: max_result_size + required_data_len,
}
}
impl Format for Book {
fn format(&self, max_size: usize) -> FormatResult {
let book_title = {
let Book { title, lang, .. } = self;
let year_part = match self.year {
0 => "".to_string(),
v => format!(" | {v}г."),
};
let pages_count = match self.pages {
Some(1) | None => "".to_string(),
Some(v) => format!(" | {v}с."),
};
let position_prefix = match self.position {
Some(0) | None => "".to_string(),
Some(v) => format!("{v} | "),
};
format!("{position_prefix}📖 {title} | {lang}{year_part}{pages_count}\n")
};
let annotations = match self.annotation_exists {
true => {
let Book { id, .. } = self;
format!("📝 Аннотация: /b_an_{id}\n")
}
false => "".to_string(),
};
let download_command = (StartDownloadCommand { id: self.id }).to_string();
let download_links = format!("Скачать:\n📥{download_command}");
let required_data_len: usize = format!("{book_title}{annotations}{download_links}").len();
let FormatVectorsResult {
authors,
translators,
sequences,
genres,
max_result_size,
} = self.format_vectors(max_size - required_data_len);
let result = format!(
"{book_title}{annotations}{authors}{translators}{sequences}{genres}{download_links}"
);
let result_len = result.len();
FormatResult {
result,
current_size: result_len,
max_size: max_result_size + required_data_len,
}
format_common(
FormatData {
id: self.id,
title: &self.title,
lang: &self.lang,
annotation_exists: self.annotation_exists,
authors: &self.authors,
translators: &self.translators,
sequences: &self.sequences,
genres: &self.genres,
year: self.year,
pages: self.pages,
position: self.position,
},
max_size,
)
}
}
impl Format for SearchBook {
fn format(&self, max_size: usize) -> FormatResult {
Into::<Book>::into(self.clone()).format(max_size)
format_common(
FormatData {
id: self.id,
title: &self.title,
lang: &self.lang,
annotation_exists: self.annotation_exists,
authors: &self.authors,
translators: &self.translators,
sequences: &self.sequences,
genres: &[],
year: self.year,
pages: None,
position: None,
},
max_size,
)
}
}
impl Format for AuthorBook {
fn format(&self, max_size: usize) -> FormatResult {
Into::<Book>::into(self.clone()).format(max_size)
format_common(
FormatData {
id: self.id,
title: &self.title,
lang: &self.lang,
annotation_exists: self.annotation_exists,
authors: &[],
translators: &self.translators,
sequences: &self.sequences,
genres: &[],
year: self.year,
pages: None,
position: None,
},
max_size,
)
}
}
impl Format for TranslatorBook {
fn format(&self, max_size: usize) -> FormatResult {
Into::<Book>::into(self.clone()).format(max_size)
format_common(
FormatData {
id: self.id,
title: &self.title,
lang: &self.lang,
annotation_exists: self.annotation_exists,
authors: &self.authors,
translators: &[],
sequences: &self.sequences,
genres: &[],
year: self.year,
pages: None,
position: None,
},
max_size,
)
}
}
impl Format for SequenceBook {
fn format(&self, max_size: usize) -> FormatResult {
Into::<Book>::into(self.clone()).format(max_size)
format_common(
FormatData {
id: self.id,
title: &self.title,
lang: &self.lang,
annotation_exists: self.annotation_exists,
authors: &self.authors,
translators: &self.translators,
sequences: &[],
genres: &[],
year: self.year,
pages: None,
position: Some(self.position),
},
max_size,
)
}
}

View File

@@ -15,11 +15,11 @@ use self::types::Empty;
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
fn get_allowed_langs_params(
allowed_langs: SmallVec<[SmartString; 3]>,
allowed_langs: &SmallVec<[SmartString; 3]>,
) -> Vec<(&'static str, SmartString)> {
allowed_langs
.into_iter()
.map(|lang| ("allowed_langs", lang))
.map(|lang| ("allowed_langs", lang.clone()))
.collect()
}
@@ -52,7 +52,7 @@ pub async fn get_random_book_by_genre(
allowed_langs: SmallVec<[SmartString; 3]>,
genre: Option<u32>,
) -> anyhow::Result<types::Book> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
if let Some(v) = genre {
params.push(("genre", v.to_string().into()));
@@ -70,7 +70,7 @@ pub async fn get_random_book(
pub async fn get_random_author(
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Author> {
let params = get_allowed_langs_params(allowed_langs);
let params = get_allowed_langs_params(&allowed_langs);
_make_request("/api/v1/authors/random", params).await
}
@@ -78,7 +78,7 @@ pub async fn get_random_author(
pub async fn get_random_sequence(
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Sequence> {
let params = get_allowed_langs_params(allowed_langs);
let params = get_allowed_langs_params(&allowed_langs);
_make_request("/api/v1/sequences/random", params).await
}
@@ -100,7 +100,7 @@ pub async fn search_book(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::SearchBook, Empty>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -113,7 +113,7 @@ pub async fn search_author(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::Author, Empty>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -126,7 +126,7 @@ pub async fn search_sequence(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::Sequence, Empty>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -139,7 +139,7 @@ pub async fn search_translator(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::Translator, Empty>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -164,7 +164,7 @@ pub async fn get_author_books(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::AuthorBook, types::BookAuthor>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -177,7 +177,7 @@ pub async fn get_translator_books(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::TranslatorBook, types::BookTranslator>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -190,7 +190,7 @@ pub async fn get_sequence_books(
page: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<types::Page<types::SequenceBook, types::Sequence>> {
let mut params = get_allowed_langs_params(allowed_langs);
let mut params = get_allowed_langs_params(&allowed_langs);
params.push(("page", page.to_string().into()));
params.push(("size", PAGE_SIZE.to_string().into()));
@@ -216,7 +216,7 @@ pub async fn get_uploaded_books(
pub async fn get_author_books_available_types(
id: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
allowed_langs: &SmallVec<[SmartString; 3]>,
) -> anyhow::Result<Vec<String>> {
let params = get_allowed_langs_params(allowed_langs);
@@ -229,7 +229,7 @@ pub async fn get_author_books_available_types(
pub async fn get_translator_books_available_types(
id: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
allowed_langs: &SmallVec<[SmartString; 3]>,
) -> anyhow::Result<Vec<String>> {
let params = get_allowed_langs_params(allowed_langs);
@@ -242,7 +242,7 @@ pub async fn get_translator_books_available_types(
pub async fn get_sequence_books_available_types(
id: u32,
allowed_langs: SmallVec<[SmartString; 3]>,
allowed_langs: &SmallVec<[SmartString; 3]>,
) -> anyhow::Result<Vec<String>> {
let params = get_allowed_langs_params(allowed_langs);

View File

@@ -149,6 +149,8 @@ where
.map(|item| item_size - item.current_size)
.sum();
use std::borrow::Cow;
self.items
.iter()
.enumerate()
@@ -156,17 +158,17 @@ where
let already_formated_result = &format_result[index];
if already_formated_result.current_size == already_formated_result.max_size {
already_formated_result.result.clone()
Cow::Borrowed(already_formated_result.result.as_str())
} else {
let new_item_size = item_size + free_symbols;
let new_formated_result = item.format(new_item_size);
free_symbols = new_item_size - new_formated_result.current_size;
new_formated_result.result
Cow::Owned(new_formated_result.result)
}
})
.collect::<Vec<String>>()
.collect::<Vec<Cow<str>>>()
.join(separator)
}
}
@@ -192,17 +194,12 @@ pub struct Book {
pub id: u32,
pub title: String,
pub lang: String,
// file_type: String,
pub available_types: SmallVec<[String; 4]>,
// uploaded: String,
pub annotation_exists: bool,
pub authors: Vec<BookAuthor>,
pub translators: Vec<BookTranslator>,
pub sequences: Vec<Sequence>,
pub genres: Vec<BookGenre>,
// source: Source,
// remote_id: u32,
// id_deleted: bool,
pub year: i32,
pub pages: Option<u32>,
pub position: Option<i32>,
@@ -213,9 +210,6 @@ pub struct SearchBook {
pub id: u32,
pub title: String,
pub lang: String,
// file_type: String,
pub available_types: SmallVec<[String; 4]>,
// uploaded: String,
pub annotation_exists: bool,
pub authors: Vec<BookAuthor>,
pub translators: Vec<BookTranslator>,
@@ -223,121 +217,36 @@ pub struct SearchBook {
pub year: i32,
}
impl From<SearchBook> for Book {
fn from(value: SearchBook) -> Self {
Book {
id: value.id,
title: value.title,
lang: value.lang,
available_types: value.available_types,
annotation_exists: value.annotation_exists,
authors: value.authors,
translators: value.translators,
sequences: value.sequences,
genres: vec![],
pages: None,
year: value.year,
position: None,
}
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct AuthorBook {
pub id: u32,
pub title: String,
pub lang: String,
// file_type: String,
pub available_types: SmallVec<[String; 4]>,
// uploaded: String,
pub annotation_exists: bool,
pub translators: Vec<BookTranslator>,
pub sequences: Vec<Sequence>,
pub year: i32,
}
impl From<AuthorBook> for Book {
fn from(value: AuthorBook) -> Self {
Book {
id: value.id,
title: value.title,
lang: value.lang,
available_types: value.available_types,
annotation_exists: value.annotation_exists,
authors: vec![],
translators: value.translators,
sequences: value.sequences,
genres: vec![],
pages: None,
year: value.year,
position: None,
}
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct TranslatorBook {
pub id: u32,
pub title: String,
pub lang: String,
// file_type: String,
pub available_types: SmallVec<[String; 4]>,
// uploaded: String,
pub annotation_exists: bool,
pub authors: Vec<BookAuthor>,
pub sequences: Vec<Sequence>,
pub year: i32,
}
impl From<TranslatorBook> for Book {
fn from(value: TranslatorBook) -> Self {
Book {
id: value.id,
title: value.title,
lang: value.lang,
available_types: value.available_types,
annotation_exists: value.annotation_exists,
authors: value.authors,
translators: vec![],
sequences: value.sequences,
genres: vec![],
pages: None,
year: value.year,
position: None,
}
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct SequenceBook {
pub id: u32,
pub title: String,
pub lang: String,
// file_type: String,
pub available_types: SmallVec<[String; 4]>,
// uploaded: String,
pub authors: Vec<BookAuthor>,
pub translators: Vec<BookTranslator>,
pub annotation_exists: bool,
pub year: i32,
pub position: i32,
}
impl From<SequenceBook> for Book {
fn from(value: SequenceBook) -> Self {
Book {
id: value.id,
title: value.title,
lang: value.lang,
available_types: value.available_types,
annotation_exists: value.annotation_exists,
authors: value.authors,
translators: value.translators,
sequences: vec![],
genres: vec![],
pages: None,
year: value.year,
position: Some(value.position),
}
}
}

View File

@@ -12,8 +12,8 @@ use crate::{
use super::user_settings::{is_need_donate_notifications, mark_donate_notification_sent};
pub async fn send_donation_notification(
bot: CacheMe<Throttle<Bot>>,
message: MaybeInaccessibleMessage,
bot: &CacheMe<Throttle<Bot>>,
message: &MaybeInaccessibleMessage,
) -> BotHandlerInternal {
if CHAT_DONATION_NOTIFICATIONS_CACHE
.get(&message.chat().id)
@@ -31,7 +31,7 @@ pub async fn send_donation_notification(
mark_donate_notification_sent(message.chat().id).await?;
if let MaybeInaccessibleMessage::Regular(message) = message {
support_command_handler(*message, bot).await?;
support_command_handler(*message.clone(), bot).await?;
}
};

View File

@@ -74,10 +74,10 @@ pub async fn get_user_or_default_lang_codes(user_id: UserId) -> SmallVec<[SmartS
pub async fn create_or_update_user_settings(
user_id: UserId,
last_name: String,
first_name: String,
username: String,
source: String,
last_name: &str,
first_name: &str,
username: &str,
source: &str,
allowed_langs: SmallVec<[SmartString; 3]>,
) -> anyhow::Result<UserSettings> {
USER_LANGS_CACHE.invalidate(&user_id).await;

View File

@@ -42,9 +42,9 @@ async fn make_register_request(
});
let result = reqwest::Client::new()
.post(config::CONFIG.manager_url.clone())
.post(&config::CONFIG.manager_url)
.body(body.to_string())
.header("Authorization", config::CONFIG.manager_api_key.clone())
.header("Authorization", &config::CONFIG.manager_api_key)
.header("Content-Type", "application/json")
.send()
.await?;

View File

@@ -93,9 +93,7 @@ impl BotsManager {
let bot_data: BotData = bot_data.clone();
BOTS_DATA
.insert(bot_data.token.clone(), bot_data.clone())
.await;
BOTS_DATA.insert(bot_data.token.clone(), bot_data).await;
}
}
@@ -110,9 +108,9 @@ impl BotsManager {
let bot_data: BotData = bot_data.clone();
let semphore = semaphore.clone();
let semaphore = semaphore.clone();
set_webhook_tasks.spawn(async move {
let _permit = semphore.acquire().await.unwrap();
let _permit = semaphore.acquire().await.unwrap();
let webhook_status = set_webhook(&bot_data).await;