Switched to teloxide 0.13

This commit is contained in:
StNicolay 2024-08-17 12:48:50 +03:00
parent 14b858808d
commit 374a9d91c7
29 changed files with 163 additions and 108 deletions

179
Cargo.lock generated
View File

@ -66,22 +66,23 @@ dependencies = [
[[package]] [[package]]
name = "aquamarine" name = "aquamarine"
version = "0.1.12" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a941c39708478e8eea39243b5983f1c42d2717b3620ee91f4a52115fd02ac43f" checksum = "21cc1548309245035eb18aa7f0967da6bc65587005170c56e6ef2788a4cf3f4e"
dependencies = [ dependencies = [
"itertools 0.9.0", "include_dir",
"itertools 0.10.5",
"proc-macro-error", "proc-macro-error",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.74",
] ]
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.4" version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]] [[package]]
name = "atoi" name = "atoi"
@ -175,9 +176,12 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.10" version = "1.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48"
dependencies = [
"shlex",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -268,9 +272,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.12" version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -391,7 +395,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustc_version", "rustc_version",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -411,7 +415,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
"unicode-xid", "unicode-xid",
] ]
@ -607,7 +611,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -845,10 +849,29 @@ dependencies = [
] ]
[[package]] [[package]]
name = "indexmap" name = "include_dir"
version = "2.3.0" version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd"
dependencies = [
"include_dir_macros",
]
[[package]]
name = "include_dir_macros"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75"
dependencies = [
"proc-macro2",
"quote",
]
[[package]]
name = "indexmap"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
@ -871,9 +894,9 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.9.0" version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [ dependencies = [
"either", "either",
] ]
@ -895,9 +918,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.69" version = "0.3.70"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -913,9 +936,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.155" version = "0.2.156"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a"
[[package]] [[package]]
name = "libm" name = "libm"
@ -1014,9 +1037,9 @@ dependencies = [
[[package]] [[package]]
name = "mio" name = "mio"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
@ -1024,12 +1047,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "never"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91"
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.3" version = "7.1.3"
@ -1246,7 +1263,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -1660,29 +1677,29 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.206" version = "1.0.208"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b3e4cd94123dd520a128bcd11e34d9e9e423e7e3e50425cb1b4b1e3549d0284" checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.206" version = "1.0.208"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fabfb6138d2383ea8208cf98ccf69cdfb1aff4088460681d84189aa259762f97" checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.122" version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -1702,6 +1719,16 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_with"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff"
dependencies = [
"serde",
"serde_with_macros",
]
[[package]] [[package]]
name = "serde_with_macros" name = "serde_with_macros"
version = "1.5.2" version = "1.5.2"
@ -1758,6 +1785,12 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.2" version = "1.4.2"
@ -1899,7 +1932,7 @@ dependencies = [
"quote", "quote",
"sqlx-core", "sqlx-core",
"sqlx-macros-core", "sqlx-macros-core",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -1922,7 +1955,7 @@ dependencies = [
"sqlx-mysql", "sqlx-mysql",
"sqlx-postgres", "sqlx-postgres",
"sqlx-sqlite", "sqlx-sqlite",
"syn 2.0.73", "syn 2.0.74",
"tempfile", "tempfile",
"tokio", "tokio",
"url", "url",
@ -2067,9 +2100,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.73" version = "2.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "837a7e8026c6ce912ff01cefbe8cafc2f8010ac49682e2a3d9decc3bce1ecaaf" checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2117,21 +2150,21 @@ checksum = "20f34339676cdcab560c9a82300c4c2581f68b9369aedf0fae86f2ff9565ff3e"
[[package]] [[package]]
name = "teloxide" name = "teloxide"
version = "0.12.2" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c63345cf32a8850ebddcdd769dc2d5193d5e231262d5dada264b79da01a664da" checksum = "5f79dd283eb21b90451c03fa7c7f83b9985130efb876b33bad89a2c208ccbc16"
dependencies = [ dependencies = [
"aquamarine", "aquamarine",
"bytes", "bytes",
"derive_more 0.99.18", "derive_more 0.99.18",
"dptree", "dptree",
"either",
"futures", "futures",
"log", "log",
"mime", "mime",
"pin-project", "pin-project",
"serde", "serde",
"serde_json", "serde_json",
"serde_with_macros",
"teloxide-core", "teloxide-core",
"teloxide-macros", "teloxide-macros",
"thiserror", "thiserror",
@ -2143,9 +2176,9 @@ dependencies = [
[[package]] [[package]]
name = "teloxide-core" name = "teloxide-core"
version = "0.9.1" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "303db260110c238e3af77bb9dff18bf7a5b5196f783059b0852aab75f91d5a16" checksum = "9e1642a7ef10e7af63b8298c8d13c0f986d4fc646d42649ff060359607f62f69"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"bytes", "bytes",
@ -2155,14 +2188,13 @@ dependencies = [
"futures", "futures",
"log", "log",
"mime", "mime",
"never",
"once_cell", "once_cell",
"pin-project", "pin-project",
"rc-box", "rc-box",
"reqwest", "reqwest",
"serde", "serde",
"serde_json", "serde_json",
"serde_with_macros", "serde_with",
"take_mut", "take_mut",
"takecell", "takecell",
"thiserror", "thiserror",
@ -2175,9 +2207,9 @@ dependencies = [
[[package]] [[package]]
name = "teloxide-macros" name = "teloxide-macros"
version = "0.7.1" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f1d653b093dba5e44cada57a516f572167df37b8a619443e59c8c517bb6d804" checksum = "7e2d33d809c3e7161a9ab18bedddf98821245014f0a78fa4d2c9430b2ec018c1"
dependencies = [ dependencies = [
"heck 0.4.1", "heck 0.4.1",
"proc-macro2", "proc-macro2",
@ -2215,7 +2247,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -2269,7 +2301,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -2308,9 +2340,9 @@ dependencies = [
[[package]] [[package]]
name = "tower-service" name = "tower-service"
version = "0.3.2" version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]] [[package]]
name = "tracing" name = "tracing"
@ -2332,7 +2364,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]
@ -2531,34 +2563,35 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.92" version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.92" version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.42" version = "0.4.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -2568,9 +2601,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.92" version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -2578,22 +2611,22 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.92" version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.92" version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
[[package]] [[package]]
name = "wasm-streams" name = "wasm-streams"
@ -2610,9 +2643,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.69" version = "0.3.70"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -2832,7 +2865,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.73", "syn 2.0.74",
] ]
[[package]] [[package]]

View File

@ -21,7 +21,12 @@ arrayvec = "0.7"
base64 = "0.22" base64 = "0.22"
bitflags = "2" bitflags = "2"
chacha20poly1305 = { version = "0.10", features = ["std"] } chacha20poly1305 = { version = "0.10", features = ["std"] }
derive_more = { version = "1", features = ["deref", "display", "error", "from"] } derive_more = { version = "1", features = [
"deref",
"display",
"error",
"from",
] }
dotenvy = "0.15" dotenvy = "0.15"
futures = "0.3" futures = "0.3"
hex = "0.4" hex = "0.4"
@ -44,7 +49,7 @@ sqlx = { version = "0.8", features = [
"migrate", "migrate",
] } ] }
subtle = "2" subtle = "2"
teloxide = { version = "0.12", features = [ teloxide = { version = "0.13", features = [
"macros", "macros",
"ctrlc_handler", "ctrlc_handler",
"rustls", "rustls",

View File

@ -16,7 +16,7 @@ use crate::{
locales::LocaleTypeExt, locales::LocaleTypeExt,
}; };
use base64::{engine::general_purpose::STANDARD_NO_PAD as B64_ENGINE, Engine as _}; use base64::{engine::general_purpose::STANDARD_NO_PAD as B64_ENGINE, Engine as _};
use teloxide::types::CallbackQuery; use teloxide::types::{CallbackQuery, MaybeInaccessibleMessage};
type NameHash = Vec<u8>; type NameHash = Vec<u8>;
@ -40,7 +40,9 @@ pub enum CallbackCommand {
impl CallbackCommand { impl CallbackCommand {
pub fn from_query(q: CallbackQuery) -> Option<Self> { pub fn from_query(q: CallbackQuery) -> Option<Self> {
q.message?; if !matches!(q.message, Some(MaybeInaccessibleMessage::Regular(_))) {
return None;
}
q.data?.parse().map_err(handle_error).ok() q.data?.parse().map_err(handle_error).ok()
} }
} }

View File

@ -51,7 +51,7 @@ async fn get_master_pass(
master_pass: String, master_pass: String,
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let text = match update_account(user_id, &db, name, field, field_value, master_pass).await { let text = match update_account(user_id, &db, name, field, field_value, master_pass).await {
Ok(true) => locale.success.as_str(), Ok(true) => locale.success.as_str(),
@ -79,7 +79,7 @@ pub async fn alter(
(hash, field): (super::NameHash, AlterableField), (hash, field): (super::NameHash, AlterableField),
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = q.from.id.0; let user_id = q.from.id.0;
let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let mut ids = q.get_ids();
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else { let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
bot.send_message(ids.0, &locale.account_not_found) bot.send_message(ids.0, &locale.account_not_found)

View File

@ -9,7 +9,7 @@ pub async fn change_locale(
mut locale: LocaleRef, mut locale: LocaleRef,
new_locale: LocaleType, new_locale: LocaleType,
) -> crate::Result<()> { ) -> crate::Result<()> {
let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let mut ids = q.get_ids();
let user_id = q.from.id.0; let user_id = q.from.id.0;
let is_successful = new_locale let is_successful = new_locale

View File

@ -15,7 +15,7 @@ async fn get_master_pass(
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let Some(account) = Account::get(user_id, &name, &db).await? else { let Some(account) = Account::get(user_id, &name, &db).await? else {
bot.send_message(msg.chat.id, &locale.no_accounts_found) bot.send_message(msg.chat.id, &locale.no_accounts_found)
@ -47,7 +47,7 @@ pub async fn decrypt(
locale: LocaleRef, locale: LocaleRef,
hash: super::NameHash, hash: super::NameHash,
) -> crate::Result<()> { ) -> crate::Result<()> {
let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let mut ids = q.get_ids();
let user_id = q.from.id.0; let user_id = q.from.id.0;
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else { let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {

View File

@ -13,7 +13,7 @@ async fn get_master_pass(
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
Account::delete(user_id, &name, &db).await?; Account::delete(user_id, &name, &db).await?;
ids.alter_message(&bot, &locale.success, deletion_markup(locale), None) ids.alter_message(&bot, &locale.success, deletion_markup(locale), None)
@ -30,7 +30,7 @@ pub async fn delete(
locale: LocaleRef, locale: LocaleRef,
(hash, is_command): (super::NameHash, bool), (hash, is_command): (super::NameHash, bool),
) -> crate::Result<()> { ) -> crate::Result<()> {
let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let mut ids = q.get_ids();
let user_id = q.from.id.0; let user_id = q.from.id.0;
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else { let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {

View File

@ -7,8 +7,8 @@ pub async fn delete_message(
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
if let Some(msg) = q.message { if let Some(msg) = q.message {
if bot.delete_message(msg.chat.id, msg.id).await.is_err() { if bot.delete_message(msg.chat().id, msg.id()).await.is_err() {
bot.send_message(msg.chat.id, &locale.error_deleting_message) bot.send_message(msg.chat().id, &locale.error_deleting_message)
.reply_markup(deletion_markup(locale)) .reply_markup(deletion_markup(locale))
.await?; .await?;
} }

View File

@ -9,7 +9,7 @@ pub async fn get(
hash: super::NameHash, hash: super::NameHash,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = q.from.id.0; let user_id = q.from.id.0;
let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let mut ids = q.get_ids();
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else { let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
bot.send_message(ids.0, &locale.account_not_found) bot.send_message(ids.0, &locale.account_not_found)

View File

@ -7,7 +7,7 @@ pub async fn get_menu(
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = q.from.id.0; let user_id = q.from.id.0;
let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let mut ids = q.get_ids();
let markup = menu_markup("get", user_id, &db).await?; let markup = menu_markup("get", user_id, &db).await?;
if markup.inline_keyboard.is_empty() { if markup.inline_keyboard.is_empty() {

View File

@ -17,7 +17,7 @@ async fn get_master_pass(
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let account = spawn_blocking(move || { let account = spawn_blocking(move || {
DecryptedAccount { DecryptedAccount {

View File

@ -6,7 +6,7 @@ pub async fn delete(
db: Pool, db: Pool,
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let markup = menu_markup("delete1", user_id, &db).await?; let markup = menu_markup("delete1", user_id, &db).await?;

View File

@ -12,7 +12,7 @@ async fn get_master_pass(
_: String, _: String,
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let mut txn = db.begin().await?; let mut txn = db.begin().await?;
let result = ( let result = (

View File

@ -29,7 +29,7 @@ async fn get_master_pass(
dialogue.exit().await?; dialogue.exit().await?;
ids.delete(&bot).await?; ids.delete(&bot).await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let mut accounts = Vec::new(); let mut accounts = Vec::new();
{ {

View File

@ -6,7 +6,7 @@ pub async fn get_account(
db: Pool, db: Pool,
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let markup = menu_markup("decrypt", user_id, &db).await?; let markup = menu_markup("decrypt", user_id, &db).await?;

View File

@ -9,7 +9,7 @@ pub async fn get_accounts(
db: Pool, db: Pool,
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let mut account_names = Account::get_names(user_id, &db); let mut account_names = Account::get_names(user_id, &db);
let Some(mut text) = account_names.try_next().await? else { let Some(mut text) = account_names.try_next().await? else {

View File

@ -38,7 +38,7 @@ async fn get_master_pass(
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let mut failed = Vec::new(); let mut failed = Vec::new();
{ {

View File

@ -6,7 +6,7 @@ pub async fn menu(
db: Pool, db: Pool,
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let markup = menu_markup("get", user_id, &db).await?; let markup = menu_markup("get", user_id, &db).await?;

View File

@ -16,7 +16,7 @@ async fn get_master_pass2(
master_pass: String, master_pass: String,
) -> crate::Result<()> { ) -> crate::Result<()> {
dialogue.exit().await?; dialogue.exit().await?;
let from = msg.from().ok_or(NoUserInfo)?; let from = msg.from.as_ref().ok_or(NoUserInfo)?;
let user_id = from.id.0; let user_id = from.id.0;
if !hash.verify(master_pass.as_bytes()) { if !hash.verify(master_pass.as_bytes()) {
@ -82,7 +82,7 @@ pub async fn set_master_pass(
db: Pool, db: Pool,
locale: LocaleRef, locale: LocaleRef,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
if MasterPass::exists(user_id, &db).await? { if MasterPass::exists(user_id, &db).await? {
bot.send_message(msg.chat.id, &locale.master_password_is_set) bot.send_message(msg.chat.id, &locale.master_password_is_set)
.reply_markup(deletion_markup(locale)) .reply_markup(deletion_markup(locale))

View File

@ -3,7 +3,7 @@ use teloxide::{dispatching::DpHandlerDescription, dptree::Handler};
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
fn has_no_user_info(msg: Message) -> bool { fn has_no_user_info(msg: Message) -> bool {
msg.from().is_none() msg.from.is_none()
} }
async fn notify_about_no_user_info( async fn notify_about_no_user_info(

View File

@ -14,7 +14,7 @@ type DynError = Arc<dyn std::error::Error + Send + Sync>;
/// Returns None if account exists, Some(None) if there's an account and Some(Some(DynError)) if an error occures. /// Returns None if account exists, Some(None) if there's an account and Some(Some(DynError)) if an error occures.
/// The String represents the error that occured /// The String represents the error that occured
async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>> { async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>> {
let user_id = match update.user() { let user_id = match update.from() {
Some(user) => user.id.0, Some(user) => user.id.0,
None => return Some(Some(Arc::new(NoUserInfo))), None => return Some(Some(Arc::new(NoUserInfo))),
}; };

View File

@ -142,7 +142,7 @@ pub trait LocaleTypeExt: Sized {
impl LocaleTypeExt for LocaleType { impl LocaleTypeExt for LocaleType {
async fn locale_for_update(update: &Update, db: &Pool) -> Self { async fn locale_for_update(update: &Update, db: &Pool) -> Self {
let Some(from) = update.user() else { let Some(from) = update.from() else {
return Self::default(); return Self::default();
}; };

View File

@ -28,6 +28,6 @@ async fn main() -> Result<()> {
entity::migrate(&pool).await?; entity::migrate(&pool).await?;
dispatching::get_dispatcher(token, pool).dispatch().await; Box::pin(dispatching::get_dispatcher(token, pool).dispatch()).await;
Ok(()) Ok(())
} }

View File

@ -5,7 +5,7 @@ pub use crate::{
first_handler, handler, first_handler, handler,
locales::LocaleRef, locales::LocaleRef,
markups::{deletion_markup, menu_markup}, markups::{deletion_markup, menu_markup},
state::{Handler, MainDialogue, MessageIds, PackagedHandler, State}, state::{CallbackMessageIdExt as _, Handler, MainDialogue, MessageIds, PackagedHandler, State},
}; };
pub use futures::{StreamExt as _, TryStreamExt as _}; pub use futures::{StreamExt as _, TryStreamExt as _};
pub use teloxide::{adaptors::Throttle, prelude::*}; pub use teloxide::{adaptors::Throttle, prelude::*};

View File

@ -3,7 +3,7 @@
mod generic; mod generic;
mod handler; mod handler;
pub use handler::{Handler, MessageIds, Packaged as PackagedHandler}; pub use handler::{CallbackMessageIdExt, Handler, MessageIds, Packaged as PackagedHandler};
crate::export_handlers!( crate::export_handlers!(
get_login, get_login,

View File

@ -8,7 +8,7 @@ async fn check_master_pass(
locale: LocaleRef, locale: LocaleRef,
master_pass: &str, master_pass: &str,
) -> crate::Result<Option<String>> { ) -> crate::Result<Option<String>> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let Some(model) = MasterPass::get(user_id, db).await? else { let Some(model) = MasterPass::get(user_id, db).await? else {
handle_error(anyhow::anyhow!( handle_error(anyhow::anyhow!(
"User was put into the GetMasterPass state with no master password set" "User was put into the GetMasterPass state with no master password set"

View File

@ -7,7 +7,7 @@ async fn check_new_account_name(
locale: LocaleRef, locale: LocaleRef,
name: &str, name: &str,
) -> crate::Result<Option<String>> { ) -> crate::Result<Option<String>> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
if Account::exists(user_id, name, db).await? { if Account::exists(user_id, name, db).await? {
Ok(Some(locale.account_already_exists.to_owned())) Ok(Some(locale.account_already_exists.to_owned()))

View File

@ -181,7 +181,7 @@ pub async fn get_user(
locale: LocaleRef, locale: LocaleRef,
handler: PackagedHandler<User>, handler: PackagedHandler<User>,
) -> crate::Result<()> { ) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let user_id = msg.from.as_ref().ok_or(NoUserInfo)?.id.0;
let mut handler = handler.lock().await; let mut handler = handler.lock().await;
if handler.func.is_none() { if handler.func.is_none() {

View File

@ -4,7 +4,7 @@ use std::{mem, sync::Arc};
use teloxide::{ use teloxide::{
errors::{ApiError, RequestError}, errors::{ApiError, RequestError},
requests::HasPayload, requests::HasPayload,
types::{InlineKeyboardMarkup, MessageId, ParseMode}, types::{InlineKeyboardMarkup, MaybeInaccessibleMessage, MessageId, ParseMode},
}; };
use tokio::{join, sync::Mutex}; use tokio::{join, sync::Mutex};
@ -102,3 +102,18 @@ impl<T> Handler<T> {
Arc::new(Mutex::new(handler)) Arc::new(Mutex::new(handler))
} }
} }
pub trait CallbackMessageIdExt {
fn get_ids(&self) -> MessageIds;
}
impl CallbackMessageIdExt for CallbackQuery {
fn get_ids(&self) -> MessageIds {
match self.message.as_ref().unwrap() {
MaybeInaccessibleMessage::Regular(m) => m.into(),
MaybeInaccessibleMessage::Inaccessible(_) => {
panic!()
}
}
}
}