Update teloxide lib

This commit is contained in:
2023-05-03 23:12:04 +02:00
parent 9bf9a86954
commit b7fd1cfa7c
14 changed files with 77 additions and 67 deletions

50
Cargo.lock generated
View File

@@ -48,9 +48,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.70" version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]] [[package]]
name = "aquamarine" name = "aquamarine"
@@ -95,9 +95,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.5.17" version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" checksum = "f8175979259124331c1d7bf6586ee7e0da434155e4b2d48ec2c8386281d8df39"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
@@ -113,22 +113,23 @@ dependencies = [
"mime", "mime",
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"rustversion",
"serde", "serde",
"serde_json", "serde_json",
"serde_path_to_error",
"serde_urlencoded", "serde_urlencoded",
"sync_wrapper", "sync_wrapper",
"tokio", "tokio",
"tower", "tower",
"tower-http",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
[[package]] [[package]]
name = "axum-core" name = "axum-core"
version = "0.2.9" version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bytes", "bytes",
@@ -136,6 +137,7 @@ dependencies = [
"http", "http",
"http-body", "http-body",
"mime", "mime",
"rustversion",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
] ]
@@ -912,9 +914,9 @@ checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
[[package]] [[package]]
name = "matchit" name = "matchit"
version = "0.5.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40"
[[package]] [[package]]
name = "memchr" name = "memchr"
@@ -1123,9 +1125,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.26" version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
@@ -1313,9 +1315,9 @@ dependencies = [
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.37.17" version = "0.37.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc809f704c03a812ac71f22456c857be34185cac691a4316f27ab0f633bb9009" checksum = "8bbfc1d1c7c40c01715f47d71444744a81669ca84e8b63e25a55e169b1f86433"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"errno", "errno",
@@ -1498,6 +1500,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_path_to_error"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7f05c1d5476066defcdfacce1f52fc3cae3af1d3089727100c02ae92e5abbe0"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "serde_urlencoded" name = "serde_urlencoded"
version = "0.7.1" version = "0.7.1"
@@ -1629,9 +1640,9 @@ checksum = "20f34339676cdcab560c9a82300c4c2581f68b9369aedf0fae86f2ff9565ff3e"
[[package]] [[package]]
name = "teloxide" name = "teloxide"
version = "0.10.1" version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91471f2d0f91b079b1b71dc689daac4748ded26a32c1cf0c6fc4130490c8f64e" checksum = "c63345cf32a8850ebddcdd769dc2d5193d5e231262d5dada264b79da01a664da"
dependencies = [ dependencies = [
"aquamarine", "aquamarine",
"axum", "axum",
@@ -1659,9 +1670,9 @@ dependencies = [
[[package]] [[package]]
name = "teloxide-core" name = "teloxide-core"
version = "0.7.1" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20608e89a267b68f3ac6e05228c89ebf455d6085388dd57250e3a00f1806e4e9" checksum = "303db260110c238e3af77bb9dff18bf7a5b5196f783059b0852aab75f91d5a16"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"bytes", "bytes",
@@ -1690,9 +1701,9 @@ dependencies = [
[[package]] [[package]]
name = "teloxide-macros" name = "teloxide-macros"
version = "0.6.3" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60d1f9fc42b44919d45dfcf8992d12e3df2a0d109431d2a15110d76fd3701a19" checksum = "0f1d653b093dba5e44cada57a516f572167df37b8a619443e59c8c517bb6d804"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@@ -1901,7 +1912,6 @@ dependencies = [
"http-body", "http-body",
"http-range-header", "http-range-header",
"pin-project-lite", "pin-project-lite",
"tower",
"tower-layer", "tower-layer",
"tower-service", "tower-service",
"tracing", "tracing",

View File

@@ -12,7 +12,7 @@ serde = { version = "1.0.144", features = ["derive"] }
serde_json = "1.0.85" serde_json = "1.0.85"
log = "0.4" log = "0.4"
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
teloxide = { version = "0.10.1", features = ["macros", "auto-send", "webhooks-axum"] } teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum"] }
url = "2.2.2" url = "2.2.2"
ctrlc = { version = "3.2.3", features = ["termination"] } ctrlc = { version = "3.2.3", features = ["termination"] }
strum = "0.24" strum = "0.24"

View File

@@ -162,7 +162,7 @@ async fn download_image(
pub async fn send_annotation_handler<T, Fut>( pub async fn send_annotation_handler<T, Fut>(
message: Message, message: Message,
bot: AutoSend<Bot>, bot: Bot,
command: AnnotationCommand, command: AnnotationCommand,
annotation_getter: fn(id: u32) -> Fut, annotation_getter: fn(id: u32) -> Fut,
) -> BotHandlerInternal ) -> BotHandlerInternal
@@ -248,7 +248,7 @@ where
pub async fn annotation_pagination_handler<T, Fut>( pub async fn annotation_pagination_handler<T, Fut>(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
callback_data: AnnotationCallbackData, callback_data: AnnotationCallbackData,
annotation_getter: fn(id: u32) -> Fut, annotation_getter: fn(id: u32) -> Fut,
) -> BotHandlerInternal ) -> BotHandlerInternal
@@ -308,7 +308,7 @@ pub fn get_annotations_handler() -> crate::bots::BotHandler {
Update::filter_message() Update::filter_message()
.chain(filter_command::<AnnotationCommand>()) .chain(filter_command::<AnnotationCommand>())
.endpoint( .endpoint(
|message: Message, bot: AutoSend<Bot>, command: AnnotationCommand| async move { |message: Message, bot: Bot, command: AnnotationCommand| async move {
match command { match command {
AnnotationCommand::Book { .. } => { AnnotationCommand::Book { .. } => {
send_annotation_handler(message, bot, command, get_book_annotation) send_annotation_handler(message, bot, command, get_book_annotation)
@@ -332,7 +332,7 @@ pub fn get_annotations_handler() -> crate::bots::BotHandler {
.chain(filter_callback_query::<AnnotationCallbackData>()) .chain(filter_callback_query::<AnnotationCallbackData>())
.endpoint( .endpoint(
|cq: CallbackQuery, |cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
callback_data: AnnotationCallbackData| async move { callback_data: AnnotationCallbackData| async move {
match callback_data { match callback_data {
AnnotationCallbackData::Book { .. } => { AnnotationCallbackData::Book { .. } => {

View File

@@ -114,7 +114,7 @@ impl GetPaginationCallbackData for BookCallbackData {
async fn send_book_handler<T, Fut>( async fn send_book_handler<T, Fut>(
message: Message, message: Message,
bot: AutoSend<Bot>, bot: Bot,
command: BookCommand, command: BookCommand,
books_getter: fn(id: u32, page: u32, allowed_langs: Vec<String>) -> Fut, books_getter: fn(id: u32, page: u32, allowed_langs: Vec<String>) -> Fut,
) -> crate::bots::BotHandlerInternal ) -> crate::bots::BotHandlerInternal
@@ -196,7 +196,7 @@ where
async fn send_pagination_book_handler<T, Fut>( async fn send_pagination_book_handler<T, Fut>(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
callback_data: BookCallbackData, callback_data: BookCallbackData,
books_getter: fn(id: u32, page: u32, allowed_langs: Vec<String>) -> Fut, books_getter: fn(id: u32, page: u32, allowed_langs: Vec<String>) -> Fut,
) -> crate::bots::BotHandlerInternal ) -> crate::bots::BotHandlerInternal
@@ -295,7 +295,7 @@ pub fn get_book_handler() -> crate::bots::BotHandler {
Update::filter_message() Update::filter_message()
.chain(filter_command::<BookCommand>()) .chain(filter_command::<BookCommand>())
.endpoint( .endpoint(
|message: Message, bot: AutoSend<Bot>, command: BookCommand| async move { |message: Message, bot: Bot, command: BookCommand| async move {
match command { match command {
BookCommand::Author { .. } => { BookCommand::Author { .. } => {
send_book_handler( send_book_handler(
@@ -331,7 +331,7 @@ pub fn get_book_handler() -> crate::bots::BotHandler {
.branch( .branch(
Update::filter_callback_query() Update::filter_callback_query()
.chain(filter_callback_query::<BookCallbackData>()) .chain(filter_callback_query::<BookCallbackData>())
.endpoint(|cq: CallbackQuery, bot: AutoSend<Bot>, callback_data: BookCallbackData| async move { .endpoint(|cq: CallbackQuery, bot: Bot, callback_data: BookCallbackData| async move {
match callback_data { match callback_data {
BookCallbackData::Author { .. } => send_pagination_book_handler(cq, bot, callback_data, get_author_books).await, BookCallbackData::Author { .. } => send_pagination_book_handler(cq, bot, callback_data, get_author_books).await,
BookCallbackData::Translator { .. } => send_pagination_book_handler(cq, bot, callback_data, get_translator_books).await, BookCallbackData::Translator { .. } => send_pagination_book_handler(cq, bot, callback_data, get_translator_books).await,

View File

@@ -47,14 +47,14 @@ impl CommandParse<Self> for DownloadData {
async fn _send_cached( async fn _send_cached(
message: &Message, message: &Message,
bot: &AutoSend<Bot>, bot: &Bot,
cached_message: CachedMessage, cached_message: CachedMessage,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
match bot match bot
.copy_message( .copy_message(
message.chat.id, message.chat.id,
Recipient::Id(ChatId(cached_message.data.chat_id)), Recipient::Id(ChatId(cached_message.data.chat_id)),
cached_message.data.message_id, MessageId(cached_message.data.message_id),
) )
.send() .send()
.await .await
@@ -66,7 +66,7 @@ async fn _send_cached(
async fn send_cached_message( async fn send_cached_message(
message: Message, message: Message,
bot: AutoSend<Bot>, bot: Bot,
download_data: DownloadData, download_data: DownloadData,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
if let Ok(v) = get_cached_message(&download_data).await { if let Ok(v) = get_cached_message(&download_data).await {
@@ -83,7 +83,7 @@ async fn send_cached_message(
async fn _send_downloaded_file( async fn _send_downloaded_file(
message: &Message, message: &Message,
bot: &AutoSend<Bot>, bot: Bot,
downloaded_data: DownloadFile, downloaded_data: DownloadFile,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
let DownloadFile { let DownloadFile {
@@ -113,11 +113,11 @@ async fn _send_downloaded_file(
async fn send_with_download_from_channel( async fn send_with_download_from_channel(
message: Message, message: Message,
bot: AutoSend<Bot>, bot: Bot,
download_data: DownloadData, download_data: DownloadData,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
match download_file(&download_data).await { match download_file(&download_data).await {
Ok(v) => match _send_downloaded_file(&message, &bot, v).await { Ok(v) => match _send_downloaded_file(&message, bot, v).await {
Ok(v_2) => Ok(v_2), Ok(v_2) => Ok(v_2),
Err(err) => Err(err), Err(err) => Err(err),
}, },
@@ -127,7 +127,7 @@ async fn send_with_download_from_channel(
async fn download_handler( async fn download_handler(
message: Message, message: Message,
bot: AutoSend<Bot>, bot: Bot,
cache: BotCache, cache: BotCache,
download_data: DownloadData, download_data: DownloadData,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
@@ -143,7 +143,7 @@ pub fn get_download_hander() -> crate::bots::BotHandler {
.chain(filter_command::<DownloadData>()) .chain(filter_command::<DownloadData>())
.endpoint( .endpoint(
|message: Message, |message: Message,
bot: AutoSend<Bot>, bot: Bot,
cache: BotCache, cache: BotCache,
download_data: DownloadData| async move { download_data: DownloadData| async move {
download_handler(message, bot, cache, download_data).await download_handler(message, bot, cache, download_data).await

View File

@@ -3,13 +3,14 @@ use crate::bots::BotHandlerInternal;
use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode}; use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode};
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename = "lowercase")] #[command(rename_rule = "lowercase")]
enum HelpCommand { enum HelpCommand {
Start, Start,
Help, Help,
} }
pub async fn help_handler(message: Message, bot: AutoSend<Bot>) -> BotHandlerInternal {
pub async fn help_handler(message: Message, bot: Bot) -> BotHandlerInternal {
let name = message let name = message
.from() .from()
.map(|user| user.first_name.clone()) .map(|user| user.first_name.clone())

View File

@@ -17,7 +17,7 @@ use crate::bots::{
}; };
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename = "lowercase")] #[command(rename_rule = "lowercase")]
enum RandomCommand { enum RandomCommand {
Random, Random,
} }
@@ -75,7 +75,7 @@ impl std::str::FromStr for RandomCallbackData {
} }
} }
async fn random_handler(message: Message, bot: AutoSend<Bot>) -> crate::bots::BotHandlerInternal { async fn random_handler(message: Message, bot: Bot) -> crate::bots::BotHandlerInternal {
const MESSAGE_TEXT: &str = "Что хотим получить?"; const MESSAGE_TEXT: &str = "Что хотим получить?";
let keyboard = InlineKeyboardMarkup { let keyboard = InlineKeyboardMarkup {
@@ -122,7 +122,7 @@ async fn random_handler(message: Message, bot: AutoSend<Bot>) -> crate::bots::Bo
async fn get_random_item_handler_internal<T>( async fn get_random_item_handler_internal<T>(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
item: Result<T, Box<dyn std::error::Error + Send + Sync>>, item: Result<T, Box<dyn std::error::Error + Send + Sync>>,
) -> BotHandlerInternal ) -> BotHandlerInternal
where where
@@ -176,7 +176,7 @@ where
async fn get_random_item_handler<T, Fut>( async fn get_random_item_handler<T, Fut>(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
item_getter: fn(allowed_langs: Vec<String>) -> Fut, item_getter: fn(allowed_langs: Vec<String>) -> Fut,
) -> BotHandlerInternal ) -> BotHandlerInternal
where where
@@ -190,7 +190,7 @@ where
get_random_item_handler_internal(cq, bot, item).await get_random_item_handler_internal(cq, bot, item).await
} }
async fn get_genre_metas_handler(cq: CallbackQuery, bot: AutoSend<Bot>) -> BotHandlerInternal { async fn get_genre_metas_handler(cq: CallbackQuery, bot: Bot) -> BotHandlerInternal {
let genre_metas = match book_library::get_genre_metas().await { let genre_metas = match book_library::get_genre_metas().await {
Ok(v) => v, Ok(v) => v,
Err(err) => return Err(err), Err(err) => return Err(err),
@@ -243,7 +243,7 @@ async fn get_genre_metas_handler(cq: CallbackQuery, bot: AutoSend<Bot>) -> BotHa
async fn get_genres_by_meta_handler( async fn get_genres_by_meta_handler(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
genre_index: u32, genre_index: u32,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
let genre_metas = match book_library::get_genre_metas().await { let genre_metas = match book_library::get_genre_metas().await {
@@ -323,7 +323,7 @@ async fn get_genres_by_meta_handler(
async fn get_random_book_by_genre( async fn get_random_book_by_genre(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
genre_id: u32, genre_id: u32,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
let allowed_langs = get_user_or_default_lang_codes(cq.from.id).await; let allowed_langs = get_user_or_default_lang_codes(cq.from.id).await;
@@ -350,7 +350,7 @@ pub fn get_random_hander() -> crate::bots::BotHandler {
.branch( .branch(
Update::filter_callback_query() Update::filter_callback_query()
.chain(filter_callback_query::<RandomCallbackData>()) .chain(filter_callback_query::<RandomCallbackData>())
.endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: AutoSend<Bot>| async move { .endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: Bot| async move {
match callback_data { match callback_data {
RandomCallbackData::RandomBook => get_random_item_handler(cq, bot, book_library::get_random_book).await, RandomCallbackData::RandomBook => get_random_item_handler(cq, bot, book_library::get_random_book).await,
RandomCallbackData::RandomAuthor => get_random_item_handler(cq, bot, book_library::get_random_author).await, RandomCallbackData::RandomAuthor => get_random_item_handler(cq, bot, book_library::get_random_author).await,

View File

@@ -107,7 +107,7 @@ fn get_query(cq: CallbackQuery) -> Option<String> {
async fn generic_search_pagination_handler<T, Fut>( async fn generic_search_pagination_handler<T, Fut>(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
search_data: SearchCallbackData, search_data: SearchCallbackData,
items_getter: fn(query: String, page: u32, allowed_langs: Vec<String>) -> Fut, items_getter: fn(query: String, page: u32, allowed_langs: Vec<String>) -> Fut,
) -> BotHandlerInternal ) -> BotHandlerInternal
@@ -217,7 +217,7 @@ where
} }
} }
pub async fn message_handler(message: Message, bot: AutoSend<Bot>) -> BotHandlerInternal { pub async fn message_handler(message: Message, bot: Bot) -> BotHandlerInternal {
let message_text = "Что ищем?"; let message_text = "Что ищем?";
let keyboard = InlineKeyboardMarkup { let keyboard = InlineKeyboardMarkup {
@@ -268,7 +268,7 @@ pub fn get_search_handler() -> crate::bots::BotHandler {
).branch( ).branch(
Update::filter_callback_query() Update::filter_callback_query()
.chain(filter_callback_query::<SearchCallbackData>()) .chain(filter_callback_query::<SearchCallbackData>())
.endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: AutoSend<Bot>| async move { .endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: Bot| async move {
match callback_data { match callback_data {
SearchCallbackData::SearchBook { .. } => generic_search_pagination_handler(cq, bot, callback_data, search_book).await, SearchCallbackData::SearchBook { .. } => generic_search_pagination_handler(cq, bot, callback_data, search_book).await,
SearchCallbackData::SearchAuthors { .. } => generic_search_pagination_handler(cq, bot, callback_data, search_author).await, SearchCallbackData::SearchAuthors { .. } => generic_search_pagination_handler(cq, bot, callback_data, search_author).await,

View File

@@ -18,7 +18,7 @@ use teloxide::{
}; };
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename = "lowercase")] #[command(rename_rule = "lowercase")]
enum SettingsCommand { enum SettingsCommand {
Settings, Settings,
} }
@@ -67,7 +67,7 @@ impl ToString for SettingsCallbackData {
} }
} }
async fn settings_handler(message: Message, bot: AutoSend<Bot>) -> BotHandlerInternal { async fn settings_handler(message: Message, bot: Bot) -> BotHandlerInternal {
let keyboard = InlineKeyboardMarkup { let keyboard = InlineKeyboardMarkup {
inline_keyboard: vec![vec![InlineKeyboardButton { inline_keyboard: vec![vec![InlineKeyboardButton {
text: "Языки".to_string(), text: "Языки".to_string(),
@@ -117,7 +117,7 @@ fn get_lang_keyboard(all_langs: Vec<Lang>, allowed_langs: HashSet<String>) -> In
async fn settings_callback_handler( async fn settings_callback_handler(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
callback_data: SettingsCallbackData, callback_data: SettingsCallbackData,
me: Me, me: Me,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
@@ -219,7 +219,7 @@ pub fn get_settings_handler() -> crate::bots::BotHandler {
.chain(filter_callback_query::<SettingsCallbackData>()) .chain(filter_callback_query::<SettingsCallbackData>())
.endpoint( .endpoint(
|cq: CallbackQuery, |cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
callback_data: SettingsCallbackData, callback_data: SettingsCallbackData,
me: Me| async move { me: Me| async move {
settings_callback_handler(cq, bot, callback_data, me).await settings_callback_handler(cq, bot, callback_data, me).await

View File

@@ -7,12 +7,12 @@ use teloxide::{
}; };
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename = "lowercase")] #[command(rename_rule = "lowercase")]
enum SupportCommand { enum SupportCommand {
Support, Support,
} }
pub async fn support_command_handler(message: Message, bot: AutoSend<Bot>) -> BotHandlerInternal { pub async fn support_command_handler(message: Message, bot: Bot) -> BotHandlerInternal {
const MESSAGE_TEXT: &str = " const MESSAGE_TEXT: &str = "
[Лицензии](https://github.com/flibusta-apps/book_bot/blob/main/LICENSE.md) [Лицензии](https://github.com/flibusta-apps/book_bot/blob/main/LICENSE.md)

View File

@@ -18,7 +18,7 @@ use teloxide::{
use super::utils::{generic_get_pagination_keyboard, GetPaginationCallbackData}; use super::utils::{generic_get_pagination_keyboard, GetPaginationCallbackData};
#[derive(BotCommands, Clone)] #[derive(BotCommands, Clone)]
#[command(rename = "snake_case")] #[command(rename_rule = "snake_case")]
enum UpdateLogCommand { enum UpdateLogCommand {
UpdateLog, UpdateLog,
} }
@@ -77,7 +77,7 @@ impl GetPaginationCallbackData for UpdateLogCallbackData {
} }
} }
async fn update_log_command(message: Message, bot: AutoSend<Bot>) -> BotHandlerInternal { async fn update_log_command(message: Message, bot: Bot) -> BotHandlerInternal {
let now = Utc::now().date_naive(); let now = Utc::now().date_naive();
let d3 = now - Duration::days(3); let d3 = now - Duration::days(3);
let d7 = now - Duration::days(7); let d7 = now - Duration::days(7);
@@ -134,7 +134,7 @@ async fn update_log_command(message: Message, bot: AutoSend<Bot>) -> BotHandlerI
async fn update_log_pagination_handler( async fn update_log_pagination_handler(
cq: CallbackQuery, cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
update_callback_data: UpdateLogCallbackData, update_callback_data: UpdateLogCallbackData,
) -> BotHandlerInternal { ) -> BotHandlerInternal {
let message = match cq.message { let message = match cq.message {
@@ -223,7 +223,7 @@ pub fn get_update_log_handler() -> crate::bots::BotHandler {
.chain(filter_callback_query::<UpdateLogCallbackData>()) .chain(filter_callback_query::<UpdateLogCallbackData>())
.endpoint( .endpoint(
|cq: CallbackQuery, |cq: CallbackQuery,
bot: AutoSend<Bot>, bot: Bot,
update_log_data: UpdateLogCallbackData| async move { update_log_data: UpdateLogCallbackData| async move {
update_log_pagination_handler(cq, bot, update_log_data).await update_log_pagination_handler(cq, bot, update_log_data).await
}, },

View File

@@ -10,7 +10,7 @@ pub mod utils;
pub async fn message_handler( pub async fn message_handler(
message: Message, message: Message,
bot: AutoSend<Bot>, bot: Bot,
) -> Result<(), Box<dyn Error + Send + Sync>> { ) -> Result<(), Box<dyn Error + Send + Sync>> {
let from_user = message.from().unwrap(); let from_user = message.from().unwrap();
let text = message.text().unwrap_or(""); let text = message.text().unwrap_or("");

View File

@@ -27,7 +27,7 @@ fn ignore_chat_member_update() -> crate::bots::BotHandler {
} }
fn get_pending_handler() -> BotHandler { fn get_pending_handler() -> BotHandler {
let handler = |msg: Message, bot: AutoSend<Bot>| async move { let handler = |msg: Message, bot: Bot| async move {
let message_text = " let message_text = "
Бот зарегистрирован, но не подтвержден администратором! \ Бот зарегистрирован, но не подтвержден администратором! \
Подтверждение занимает примерно 12 часов. Подтверждение занимает примерно 12 часов.
@@ -44,7 +44,7 @@ fn get_pending_handler() -> BotHandler {
} }
fn get_blocked_handler() -> BotHandler { fn get_blocked_handler() -> BotHandler {
let handler = |msg: Message, bot: AutoSend<Bot>| async move { let handler = |msg: Message, bot: Bot| async move {
let message_text = "Бот заблокирован!"; let message_text = "Бот заблокирован!";
bot.send_message(msg.chat.id, message_text).await?; bot.send_message(msg.chat.id, message_text).await?;

View File

@@ -74,10 +74,9 @@ impl BotsManager {
async fn start_bot(&mut self, bot_data: &BotData) -> bool { async fn start_bot(&mut self, bot_data: &BotData) -> bool {
let bot = Bot::new(bot_data.token.clone()) let bot = Bot::new(bot_data.token.clone())
.set_api_url(config::CONFIG.telegram_bot_api.clone()) .set_api_url(config::CONFIG.telegram_bot_api.clone());
.auto_send();
let token = bot.inner().token(); let token = bot.token();
let port = self.bot_port_map let port = self.bot_port_map
.get(&bot_data.id) .get(&bot_data.id)
.unwrap_or_else(|| panic!("Can't get bot port!")); .unwrap_or_else(|| panic!("Can't get bot port!"));
@@ -219,7 +218,7 @@ impl BotsManager {
manager.check().await; manager.check().await;
for _ in 1..30 { for _ in 1..30 {
sleep(Duration::from_secs(1)).await; sleep(Duration::from_millis(50)).await;
if !running.load(Ordering::SeqCst) { if !running.load(Ordering::SeqCst) {
manager.stop_all().await; manager.stop_all().await;