Update teloxide

This commit is contained in:
2024-08-22 21:26:31 +02:00
parent 964b3c0e7b
commit 4e44b9ef34
21 changed files with 204 additions and 236 deletions

207
Cargo.lock generated
View File

@@ -61,15 +61,16 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
[[package]]
name = "aquamarine"
version = "0.1.12"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a941c39708478e8eea39243b5983f1c42d2717b3620ee91f4a52115fd02ac43f"
checksum = "21cc1548309245035eb18aa7f0967da6bc65587005170c56e6ef2788a4cf3f4e"
dependencies = [
"include_dir",
"itertools",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.60",
]
[[package]]
@@ -100,38 +101,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
[[package]]
name = "axum"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
dependencies = [
"async-trait",
"axum-core 0.3.4",
"bitflags 1.3.2",
"bytes",
"futures-util",
"http 0.2.12",
"http-body 0.4.6",
"hyper 0.14.28",
"itoa",
"matchit",
"memchr",
"mime",
"percent-encoding",
"pin-project-lite",
"rustversion",
"serde",
"serde_json",
"serde_path_to_error",
"serde_urlencoded",
"sync_wrapper 0.1.2",
"tokio",
"tower",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum"
version = "0.7.5"
@@ -139,7 +108,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf"
dependencies = [
"async-trait",
"axum-core 0.4.3",
"axum-core",
"bytes",
"futures-util",
"http 1.1.0",
@@ -166,23 +135,6 @@ dependencies = [
"tracing",
]
[[package]]
name = "axum-core"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [
"async-trait",
"bytes",
"futures-util",
"http 0.2.12",
"http-body 0.4.6",
"mime",
"rustversion",
"tower-layer",
"tower-service",
]
[[package]]
name = "axum-core"
version = "0.4.3"
@@ -206,13 +158,12 @@ dependencies = [
[[package]]
name = "axum-prometheus"
version = "0.6.1"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b683cbc43010e9a3d72c2f31ca464155ff4f95819e88a32924b0f47a43898978"
checksum = "739e2585f5376f5bdd129324ded72d3261fdd5b7c411a645920328fb5dc875d4"
dependencies = [
"axum 0.7.5",
"axum",
"bytes",
"futures",
"futures-core",
"http 1.1.0",
"http-body 1.0.0",
@@ -223,7 +174,7 @@ dependencies = [
"pin-project",
"tokio",
"tower",
"tower-http 0.5.2",
"tower-http",
]
[[package]]
@@ -269,7 +220,7 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
name = "book_bot"
version = "0.1.0"
dependencies = [
"axum 0.7.5",
"axum",
"axum-prometheus",
"base64 0.22.0",
"chrono",
@@ -294,7 +245,7 @@ dependencies = [
"tokio-stream",
"tokio-util",
"tower",
"tower-http 0.5.2",
"tower-http",
"tracing",
"tracing-subscriber",
"url",
@@ -856,12 +807,6 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "http-range-header"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f"
[[package]]
name = "httparse"
version = "1.8.0"
@@ -1007,6 +952,25 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "include_dir"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
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.2.6"
@@ -1025,9 +989,9 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
[[package]]
name = "itertools"
version = "0.9.0"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
@@ -1104,9 +1068,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
[[package]]
name = "metrics"
version = "0.22.3"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2be3cbd384d4e955b231c895ce10685e3d8260c5ccffae898c96c723b0772835"
checksum = "884adb57038347dfbaf2d5065887b6cf4312330dc8e94bc30a1a839bd79d3261"
dependencies = [
"ahash",
"portable-atomic",
@@ -1114,12 +1078,14 @@ dependencies = [
[[package]]
name = "metrics-exporter-prometheus"
version = "0.13.1"
version = "0.15.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bf4e7146e30ad172c42c39b3246864bd2d3c6396780711a1baf749cfe423e21"
checksum = "b4f0c8427b39666bf970460908b213ec09b3b350f20c0c2eabcbba51704a08e6"
dependencies = [
"base64 0.21.7",
"hyper 0.14.28",
"base64 0.22.0",
"http-body-util",
"hyper 1.3.1",
"hyper-util",
"indexmap",
"ipnet",
"metrics",
@@ -1127,13 +1093,14 @@ dependencies = [
"quanta",
"thiserror",
"tokio",
"tracing",
]
[[package]]
name = "metrics-util"
version = "0.16.3"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b07a5eb561b8cbc16be2d216faf7757f9baf3bfb94dbb0fae3df8387a5bb47f"
checksum = "4259040465c955f9f2f1a4a8a16dc46726169bca0f88e8fb2dbeced487c3e828"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
@@ -1222,12 +1189,6 @@ dependencies = [
"tempfile",
]
[[package]]
name = "never"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91"
[[package]]
name = "nix"
version = "0.28.0"
@@ -1799,9 +1760,9 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca"
[[package]]
name = "sentry"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00421ed8fa0c995f07cde48ba6c89e80f2b312f74ff637326f392fbfd23abe02"
checksum = "5484316556650182f03b43d4c746ce0e3e48074a21e2f51244b648b6542e1066"
dependencies = [
"httpdate",
"native-tls",
@@ -1818,9 +1779,9 @@ dependencies = [
[[package]]
name = "sentry-backtrace"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a79194074f34b0cbe5dd33896e5928bbc6ab63a889bd9df2264af5acb186921e"
checksum = "40aa225bb41e2ec9d7c90886834367f560efc1af028f1c5478a6cce6a59c463a"
dependencies = [
"backtrace",
"once_cell",
@@ -1830,9 +1791,9 @@ dependencies = [
[[package]]
name = "sentry-contexts"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eba8870c5dba2bfd9db25c75574a11429f6b95957b0a78ac02e2970dd7a5249a"
checksum = "1a8dd746da3d16cb8c39751619cefd4fcdbd6df9610f3310fd646b55f6e39910"
dependencies = [
"hostname",
"libc",
@@ -1844,9 +1805,9 @@ dependencies = [
[[package]]
name = "sentry-core"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46a75011ea1c0d5c46e9e57df03ce81f5c7f0a9e199086334a1f9c0a541e0826"
checksum = "161283cfe8e99c8f6f236a402b9ccf726b201f365988b5bb637ebca0abbd4a30"
dependencies = [
"once_cell",
"rand",
@@ -1857,9 +1818,9 @@ dependencies = [
[[package]]
name = "sentry-debug-images"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ec2a486336559414ab66548da610da5e9626863c3c4ffca07d88f7dc71c8de8"
checksum = "8fc6b25e945fcaa5e97c43faee0267eebda9f18d4b09a251775d8fef1086238a"
dependencies = [
"findshlibs",
"once_cell",
@@ -1868,9 +1829,9 @@ dependencies = [
[[package]]
name = "sentry-panic"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eaa3ecfa3c8750c78dcfd4637cfa2598b95b52897ed184b4dc77fcf7d95060d"
checksum = "bc74f229c7186dd971a9491ffcbe7883544aa064d1589bd30b83fb856cd22d63"
dependencies = [
"sentry-backtrace",
"sentry-core",
@@ -1878,9 +1839,9 @@ dependencies = [
[[package]]
name = "sentry-tracing"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f715932bf369a61b7256687c6f0554141b7ce097287e30e3f7ed6e9de82498fe"
checksum = "cd3c5faf2103cd01eeda779ea439b68c4ee15adcdb16600836e97feafab362ec"
dependencies = [
"sentry-backtrace",
"sentry-core",
@@ -1890,9 +1851,9 @@ dependencies = [
[[package]]
name = "sentry-types"
version = "0.32.3"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4519c900ce734f7a0eb7aba0869dfb225a7af8820634a7dd51449e3b093cfb7c"
checksum = "5d68cdf6bc41b8ff3ae2a9c4671e97426dcdd154cc1d4b6b72813f285d6b163f"
dependencies = [
"debugid",
"hex",
@@ -1958,6 +1919,16 @@ dependencies = [
"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]]
name = "serde_with_macros"
version = "1.5.2"
@@ -2146,15 +2117,16 @@ checksum = "20f34339676cdcab560c9a82300c4c2581f68b9369aedf0fae86f2ff9565ff3e"
[[package]]
name = "teloxide"
version = "0.12.2"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c63345cf32a8850ebddcdd769dc2d5193d5e231262d5dada264b79da01a664da"
checksum = "5f79dd283eb21b90451c03fa7c7f83b9985130efb876b33bad89a2c208ccbc16"
dependencies = [
"aquamarine",
"axum 0.6.20",
"axum",
"bytes",
"derive_more",
"dptree",
"either",
"futures",
"log",
"mime",
@@ -2162,7 +2134,6 @@ dependencies = [
"rand",
"serde",
"serde_json",
"serde_with_macros",
"teloxide-core",
"teloxide-macros",
"thiserror",
@@ -2170,15 +2141,15 @@ dependencies = [
"tokio-stream",
"tokio-util",
"tower",
"tower-http 0.3.5",
"tower-http",
"url",
]
[[package]]
name = "teloxide-core"
version = "0.9.1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "303db260110c238e3af77bb9dff18bf7a5b5196f783059b0852aab75f91d5a16"
checksum = "b4308e2880a535d8c30e494d548af1deb573e1fc06f2574fdd01b8fccf7c801a"
dependencies = [
"bitflags 1.3.2",
"bytes",
@@ -2188,14 +2159,13 @@ dependencies = [
"futures",
"log",
"mime",
"never",
"once_cell",
"pin-project",
"rc-box",
"reqwest 0.11.27",
"serde",
"serde_json",
"serde_with_macros",
"serde_with",
"take_mut",
"takecell",
"thiserror",
@@ -2208,9 +2178,9 @@ dependencies = [
[[package]]
name = "teloxide-macros"
version = "0.7.1"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f1d653b093dba5e44cada57a516f572167df37b8a619443e59c8c517bb6d804"
checksum = "7e2d33d809c3e7161a9ab18bedddf98821245014f0a78fa4d2c9430b2ec018c1"
dependencies = [
"heck",
"proc-macro2",
@@ -2398,25 +2368,6 @@ dependencies = [
"tracing",
]
[[package]]
name = "tower-http"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858"
dependencies = [
"bitflags 1.3.2",
"bytes",
"futures-core",
"futures-util",
"http 0.2.12",
"http-body 0.4.6",
"http-range-header",
"pin-project-lite",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower-http"
version = "0.5.2"

View File

@@ -14,21 +14,21 @@ tokio-stream = "0.1.15"
futures = "0.3.30"
axum = "0.7.5"
axum-prometheus = "0.6.1"
axum-prometheus = "0.7.0"
tower = "0.4.13"
tower-http = { version = "0.5.2", features = ["trace"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"]}
sentry-tracing = "0.32.3"
sentry-tracing = "0.34.0"
reqwest = { version = "0.12.4", features = ["json", "stream"] }
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum", "cache-me", "throttle"] }
teloxide = { version = "0.13.0", features = ["macros", "webhooks-axum", "cache-me", "throttle"] }
url = "2.5.0"
@@ -48,4 +48,4 @@ smartstring = { version = "1.0.1", features = ["serde"] }
moka = { version = "0.12.7", features = ["future"] }
sentry = { version = "0.32.3", features = ["debug-images"] }
sentry = { version = "0.34.0", features = ["debug-images"] }

View File

@@ -73,7 +73,7 @@ fn update_user_activity_handler() -> BotHandler {
)
.branch(Update::filter_message().chain(dptree::filter_map_async(
|message: Message, bot: CacheMe<Throttle<Bot>>| async move {
match message.from() {
match message.from {
Some(user) => _update_activity(bot.get_me().await.unwrap(), user.clone()).await,
None => None,
}

View File

@@ -58,7 +58,7 @@ where
if annotation.get_file().is_none() && !annotation.is_normal_text() {
return match bot
.send_message(message.chat.id, "Аннотация недоступна :(")
.reply_to_message_id(message.id)
.reply_parameters(ReplyParameters::new(message.id))
.send()
.await
{
@@ -149,7 +149,7 @@ where
let keyboard =
generic_get_pagination_keyboard(page, chunked_text.len().try_into()?, callback_data, false);
bot.edit_message_text(message.chat.id, message.id, current_text)
bot.edit_message_text(message.chat().id, message.id(), current_text)
.reply_markup(keyboard)
.send()
.await?;

View File

@@ -48,7 +48,7 @@ where
};
let chat_id = message.chat.id;
let user_id = message.from().map(|from| from.id);
let user_id = message.from.map(|from| from.id);
let user_id = match user_id {
Some(v) => v,
@@ -118,9 +118,9 @@ where
BookCallbackData::Sequence { id, page } => (id, page),
};
let chat_id = cq.message.as_ref().map(|message| message.chat.id);
let chat_id = cq.message.as_ref().map(|message| message.chat().id);
let user_id = cq.from.id;
let message_id = cq.message.as_ref().map(|message| message.id);
let message_id = cq.message.as_ref().map(|message| message.id());
let (chat_id, message_id) = match (chat_id, message_id) {
(Some(chat_id), Some(message_id)) => (chat_id, message_id),

View File

@@ -60,13 +60,13 @@ fn get_check_keyboard(task_id: String) -> InlineKeyboardMarkup {
}
async fn _send_cached(
message: &Message,
message: &MaybeInaccessibleMessage,
bot: &CacheMe<Throttle<Bot>>,
cached_message: CachedMessage,
) -> BotHandlerInternal {
match bot
.copy_message(
message.chat.id,
message.chat().id,
Recipient::Id(ChatId(cached_message.chat_id)),
MessageId(cached_message.message_id),
)
@@ -79,7 +79,7 @@ async fn _send_cached(
}
async fn send_cached_message(
message: Message,
message: MaybeInaccessibleMessage,
bot: CacheMe<Throttle<Bot>>,
download_data: DownloadQueryData,
need_delete_message: bool,
@@ -94,7 +94,9 @@ async fn send_cached_message(
if _send_cached(&message, &bot, cached).await.is_ok() {
if need_delete_message {
bot.delete_message(message.chat.id, message.id).await?;
if let MaybeInaccessibleMessage::Regular(message) = message.clone() {
bot.delete_message(message.chat.id, message.id).await?;
}
}
match send_donation_notification(bot.clone(), message).await {
@@ -113,7 +115,7 @@ async fn send_cached_message(
}
async fn _send_downloaded_file(
message: &Message,
message: &MaybeInaccessibleMessage,
bot: CacheMe<Throttle<Bot>>,
downloaded_data: DownloadFile,
) -> BotHandlerInternal {
@@ -131,7 +133,7 @@ async fn _send_downloaded_file(
let document: InputFile = InputFile::read(data).file_name(filename.clone());
match bot.send_document(message.chat.id, document)
match bot.send_document(message.chat().id, document)
.caption(caption)
.send()
.await {
@@ -152,7 +154,7 @@ async fn _send_downloaded_file(
async fn send_with_download_from_channel(
message: Message,
message: MaybeInaccessibleMessage,
bot: CacheMe<Throttle<Bot>>,
download_data: DownloadQueryData,
need_delete_message: bool,
@@ -169,7 +171,9 @@ async fn send_with_download_from_channel(
_send_downloaded_file(&message, bot.clone(), download_file).await?;
if need_delete_message {
bot.delete_message(message.chat.id, message.id).await?;
if let MaybeInaccessibleMessage::Regular(message) = message {
bot.delete_message(message.chat.id, message.id).await?;
};
}
Ok(())
@@ -180,7 +184,7 @@ async fn send_with_download_from_channel(
async fn download_handler(
message: Message,
message: MaybeInaccessibleMessage,
bot: CacheMe<Throttle<Bot>>,
cache: BotCache,
download_data: DownloadQueryData,
@@ -233,7 +237,7 @@ async fn get_download_keyboard_handler(
bot.send_message(message.chat.id, "Выбери формат:")
.reply_markup(keyboard)
.reply_to_message_id(message.id)
.reply_parameters(ReplyParameters::new(message.id))
.send()
.await?;
@@ -245,7 +249,7 @@ async fn get_download_archive_keyboard_handler(
bot: CacheMe<Throttle<Bot>>,
command: DownloadArchiveCommand,
) -> BotHandlerInternal {
let allowed_langs = get_user_or_default_lang_codes(message.from().unwrap().id).await;
let allowed_langs = get_user_or_default_lang_codes(message.from.unwrap().id).await;
let available_types = match command {
DownloadArchiveCommand::Sequence { id } => {
@@ -299,7 +303,7 @@ async fn get_download_archive_keyboard_handler(
bot.send_message(message.chat.id, "Выбери формат:")
.reply_markup(keyboard)
.reply_to_message_id(message.id)
.reply_parameters(ReplyParameters::new(message.id))
.await?;
Ok(())
@@ -347,10 +351,18 @@ async fn send_archive_link(
async fn wait_archive(
bot: CacheMe<Throttle<Bot>>,
task_id: String,
message: Message,
input_message: MaybeInaccessibleMessage,
) -> BotHandlerInternal {
let mut interval = time::interval(Duration::from_secs(15));
let message = match input_message {
MaybeInaccessibleMessage::Regular(message) => message,
_ => {
send_error_message(bot, input_message.chat().id, input_message.id()).await;
return Ok(());
}
};
let task = loop {
interval.tick().await;
@@ -420,7 +432,7 @@ async fn wait_archive(
}
};
match _send_downloaded_file(&message, bot.clone(), downloaded_data).await {
match _send_downloaded_file(&MaybeInaccessibleMessage::Regular(message.clone()), bot.clone(), downloaded_data).await {
Ok(_) => (),
Err(err) => {
send_archive_link(bot.clone(), message.clone(), task).await?;
@@ -465,13 +477,13 @@ async fn download_archive(
let task = match task {
Ok(v) => v,
Err(err) => {
send_error_message(bot, message.chat.id, message.id).await;
send_error_message(bot, message.chat().id, message.id()).await;
log::error!("{:?}", err);
return Err(err);
}
};
bot.edit_message_text(message.chat.id, message.id, "⏳ Подготовка архива...")
bot.edit_message_text(message.chat().id, message.id(), "⏳ Подготовка архива...")
.reply_markup(get_check_keyboard(task.id.clone()))
.send()
.await?;

View File

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

View File

@@ -6,7 +6,7 @@ use smartstring::alias::String as SmartString;
use teloxide::{
adaptors::{CacheMe, Throttle},
prelude::*,
types::{InlineKeyboardButton, InlineKeyboardMarkup},
types::{InlineKeyboardButton, InlineKeyboardMarkup, ReplyParameters},
};
use crate::bots::{
@@ -59,7 +59,7 @@ async fn random_handler(
};
bot.send_message(message.chat.id, MESSAGE_TEXT)
.reply_to_message_id(message.id)
.reply_parameters(ReplyParameters::new(message.id))
.reply_markup(keyboard)
.send()
.await?;
@@ -99,7 +99,7 @@ where
match cq.message {
Some(message) => {
bot.edit_message_reply_markup(message.chat.id, message.id)
bot.edit_message_reply_markup(message.chat().id, message.id())
.reply_markup(InlineKeyboardMarkup {
inline_keyboard: vec![],
})
@@ -161,7 +161,7 @@ async fn get_genre_metas_handler(
.collect(),
};
bot.edit_message_reply_markup(message.chat.id, message.id)
bot.edit_message_reply_markup(message.chat().id, message.id())
.reply_markup(keyboard)
.send()
.await?;
@@ -225,7 +225,7 @@ async fn get_genres_by_meta_handler(
}
};
bot.edit_message_reply_markup(message.chat.id, message.id)
bot.edit_message_reply_markup(message.chat().id, message.id())
.reply_markup(keyboard)
.send()
.await?;

View File

@@ -9,7 +9,7 @@ use teloxide::{
adaptors::{CacheMe, Throttle},
dispatching::dialogue::GetChatId,
prelude::*,
types::{InlineKeyboardButton, InlineKeyboardMarkup},
types::{InlineKeyboardButton, InlineKeyboardMarkup, ReplyParameters},
};
use crate::bots::{
@@ -44,7 +44,7 @@ where
{
let chat_id = cq.chat_id();
let user_id = cq.from.id;
let message_id = cq.message.as_ref().map(|message| message.id);
let message_id = cq.message.as_ref().map(|message| message.id());
let query = get_query(cq);
let (chat_id, query, message_id) = match (chat_id, query, message_id) {
@@ -151,7 +151,7 @@ pub async fn message_handler(message: Message, bot: CacheMe<Throttle<Bot>>) -> B
};
bot.send_message(message.chat.id, message_text)
.reply_to_message_id(message.id)
.reply_parameters(ReplyParameters::new(message.id))
.reply_markup(keyboard)
.send()
.await?;

View File

@@ -1,16 +1,19 @@
use teloxide::types::CallbackQuery;
use teloxide::types::{CallbackQuery, MaybeInaccessibleMessage};
pub fn get_query(cq: CallbackQuery) -> Option<String> {
cq.message
.map(|message| {
message
.reply_to_message()
.map(|reply_to_message| {
reply_to_message
match cq.message {
Some(message) => {
match message {
MaybeInaccessibleMessage::Regular(message) => {
message
.text()
.map(|text| text.replace(['/', '&', '?'], ""))
})
.unwrap_or(None)
})
.unwrap_or(None)
.map_or(None, |text| Some(text.replace(['/', '&', '?'], "")))
}
MaybeInaccessibleMessage::Inaccessible(_) => None,
}
}
None => None,
}
}

View File

@@ -126,7 +126,7 @@ async fn settings_callback_handler(
)
.await
{
bot.send_message(message.chat.id, "Ошибка! Попробуйте заново(")
bot.send_message(message.chat().id, "Ошибка! Попробуйте заново(")
.send()
.await?;
return Err(err);
@@ -135,7 +135,7 @@ async fn settings_callback_handler(
let all_langs = match get_langs().await {
Ok(v) => v,
Err(err) => {
bot.send_message(message.chat.id, "Ошибка! Попробуйте заново(")
bot.send_message(message.chat().id, "Ошибка! Попробуйте заново(")
.send()
.await?;
return Err(err);
@@ -144,7 +144,7 @@ async fn settings_callback_handler(
let keyboard = get_lang_keyboard(all_langs, allowed_langs_set);
bot.edit_message_reply_markup(message.chat.id, message.id)
bot.edit_message_reply_markup(message.chat().id, message.id())
.reply_markup(keyboard)
.send()
.await?;

View File

@@ -1,9 +1,7 @@
use crate::bots::BotHandlerInternal;
use teloxide::{
adaptors::{CacheMe, Throttle},
prelude::*,
utils::command::BotCommands,
adaptors::{CacheMe, Throttle}, prelude::*, types::MaybeInaccessibleMessage, utils::command::BotCommands
};
#[derive(BotCommands, Clone)]
@@ -14,20 +12,28 @@ enum SupportCommand {
}
pub async fn support_command_handler(
message: Message,
orgingal_message: MaybeInaccessibleMessage,
bot: CacheMe<Throttle<Bot>>,
) -> BotHandlerInternal {
let is_bot = message.from().unwrap().is_bot;
let message = match orgingal_message {
MaybeInaccessibleMessage::Regular(message) => message,
MaybeInaccessibleMessage::Inaccessible(_) => return Ok(()),
};
let username = if is_bot {
&message
.reply_to_message()
.unwrap()
.from()
.unwrap()
.first_name
} else {
&message.from().unwrap().first_name
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(),
},
None => "пользователь".to_string(),
},
false => user.first_name,
}
}
None => "пользователь".to_string(),
};
let message_text = format!(
@@ -59,7 +65,6 @@ The Open Network - TON:
bot.send_message(message.chat.id, message_text)
.parse_mode(teloxide::types::ParseMode::Html)
.disable_web_page_preview(true)
.await?;
Ok(())

View File

@@ -109,7 +109,7 @@ async fn update_log_pagination_handler(
.await?;
if items_page.pages == 0 {
bot.send_message(message.chat.id, "Нет новых книг за этот период.")
bot.send_message(message.chat().id, "Нет новых книг за этот период.")
.send()
.await?;
return Ok(());
@@ -140,7 +140,7 @@ async fn update_log_pagination_handler(
let message_text = format!("{header}{formatted_page}");
let keyboard = generic_get_pagination_keyboard(page, total_pages, update_callback_data, true);
bot.edit_message_text(message.chat.id, message.id, message_text)
bot.edit_message_text(message.chat().id, message.id(), message_text)
.reply_markup(keyboard)
.send()
.await?;

View File

@@ -40,7 +40,7 @@ pub struct Task {
pub id: String,
pub status: TaskStatus,
pub status_description: String,
pub error_message: Option<String>,
// pub error_message: Option<String>,
pub result_filename: Option<String>,
pub content_size: Option<u64>,
}

View File

@@ -22,7 +22,7 @@ pub struct BookTranslator {
#[derive(Deserialize, Debug, Clone)]
pub struct BookGenre {
pub id: u32,
// pub id: u32,
pub description: String,
}
@@ -65,11 +65,11 @@ pub struct Sequence {
#[derive(Deserialize, Debug, Clone)]
pub struct Genre {
pub id: u32,
pub source: Source,
pub remote_id: u32,
pub code: String,
// pub source: Source,
// pub remote_id: u32,
// pub code: String,
pub description: String,
pub meta: String,
// pub meta: String,
}
#[derive(Default, Deserialize, Debug, Clone)]
@@ -78,11 +78,11 @@ pub struct Empty {}
#[derive(Deserialize, Debug, Clone)]
pub struct Page<T, P> {
pub items: Vec<T>,
pub total: u32,
// pub total: u32,
pub page: u32,
// pub page: u32,
pub size: u32,
// pub size: u32,
pub pages: u32,
#[serde(default)]
@@ -173,16 +173,16 @@ where
#[derive(Deserialize, Debug, Clone)]
pub struct BookAnnotation {
pub id: u32,
pub title: String,
// pub id: u32,
// pub title: String,
pub text: String,
pub file: Option<String>,
}
#[derive(Deserialize, Debug, Clone)]
pub struct AuthorAnnotation {
pub id: u32,
pub title: String,
// pub id: u32,
// pub title: String,
pub text: String,
pub file: Option<String>,
}

View File

@@ -1,7 +1,5 @@
use teloxide::{
adaptors::{CacheMe, Throttle},
types::Message,
Bot,
adaptors::{CacheMe, Throttle}, types::MaybeInaccessibleMessage, Bot
};
use crate::{
@@ -13,25 +11,25 @@ use super::user_settings::{is_need_donate_notifications, mark_donate_notificatio
pub async fn send_donation_notification(
bot: CacheMe<Throttle<Bot>>,
message: Message,
message: MaybeInaccessibleMessage,
) -> BotHandlerInternal {
if CHAT_DONATION_NOTIFICATIONS_CACHE
.get(&message.chat.id)
.get(&message.chat().id)
.await
.is_some()
{
return Ok(());
} else if !is_need_donate_notifications(message.chat.id, message.chat.is_private()).await? {
} else if !is_need_donate_notifications(message.chat().id, message.chat().is_private()).await? {
CHAT_DONATION_NOTIFICATIONS_CACHE
.insert(message.chat.id, ())
.insert(message.chat().id, ())
.await;
return Ok(());
}
CHAT_DONATION_NOTIFICATIONS_CACHE
.insert(message.chat.id, ())
.insert(message.chat().id, ())
.await;
mark_donate_notification_sent(message.chat.id).await?;
mark_donate_notification_sent(message.chat().id).await?;
support_command_handler(message, bot).await?;

View File

@@ -22,11 +22,11 @@ pub struct Lang {
#[derive(Deserialize, Debug, Clone)]
pub struct UserSettings {
pub user_id: u64,
pub last_name: SmartString,
pub first_name: SmartString,
pub username: SmartString,
pub source: SmartString,
// pub user_id: u64,
// pub last_name: SmartString,
// pub first_name: SmartString,
// pub username: SmartString,
// pub source: SmartString,
pub allowed_langs: SmallVec<[Lang; 3]>,
}

View File

@@ -1,6 +1,6 @@
use teloxide::{
adaptors::{CacheMe, Throttle},
prelude::*,
prelude::*, types::ReplyParameters,
};
use std::error::Error;
@@ -16,7 +16,7 @@ pub async fn message_handler(
message: Message,
bot: CacheMe<Throttle<Bot>>,
) -> Result<(), Box<dyn Error + Send + Sync>> {
let from_user = message.from().unwrap();
let from_user = message.clone().from.unwrap();
let text = message.text().unwrap_or("");
let result = register::register(from_user.id, text).await;
@@ -29,7 +29,7 @@ pub async fn message_handler(
};
bot.send_message(message.chat.id, message_text)
.reply_to_message_id(message.id)
.reply_parameters(ReplyParameters::new(message.id))
.await?;
Ok(())

View File

@@ -18,7 +18,7 @@ pub enum RegisterStatus {
pub enum RegisterRequestStatus {
Success,
LimitExtended,
UnknownError { status_code: u16 },
UnknownError,
}
async fn get_bot_username(token: &str) -> Option<String> {
@@ -55,7 +55,7 @@ async fn make_register_request(
Ok(match result.status().as_u16() {
200 => RegisterRequestStatus::Success,
402 => RegisterRequestStatus::LimitExtended,
status_code => RegisterRequestStatus::UnknownError { status_code },
_ => RegisterRequestStatus::UnknownError,
})
}

View File

@@ -16,7 +16,6 @@ use url::Url;
use std::convert::Infallible;
use crate::bots_manager::bot_manager_client::delete_bot;
use crate::bots_manager::BOTS_ROUTES;
use crate::config;
@@ -65,10 +64,10 @@ pub async fn set_webhook(bot_data: &BotData) -> bool {
match bot.set_webhook(url.clone()).await {
Ok(_) => true,
Err(err) => {
if let teloxide::RequestError::Api(ref err) = err {
if err == &teloxide::ApiError::NotFound {
let _ = delete_bot(bot_data.id).await;
}
if let teloxide::RequestError::Api(ref _err) = err {
// if err == &teloxide::ApiError::NotFound {
// let _ = delete_bot(bot_data.id).await;
// }
}
log::error!("Webhook set error: {}", err);

View File

@@ -6,8 +6,8 @@ pub struct Config {
pub webhook_base_url: String,
pub webhook_port: u16,
pub admin_id: String,
pub bot_token: String,
// pub admin_id: String,
// pub bot_token: String,
pub manager_url: String,
pub manager_api_key: String,
@@ -42,8 +42,8 @@ impl Config {
webhook_base_url: get_env("WEBHOOK_BASE_URL"),
webhook_port: get_env("WEBHOOK_PORT").parse().unwrap(),
admin_id: get_env("ADMIN_ID"),
bot_token: get_env("BOT_TOKEN"),
// admin_id: get_env("ADMIN_ID"),
// bot_token: get_env("BOT_TOKEN"),
manager_url: get_env("MANAGER_URL"),
manager_api_key: get_env("MANAGER_API_KEY"),