mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use regex::Regex;
|
||||
use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*};
|
||||
use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, adaptors::Throttle};
|
||||
|
||||
use crate::bots::approved_bot::{
|
||||
services::{
|
||||
@@ -114,7 +114,7 @@ impl GetPaginationCallbackData for BookCallbackData {
|
||||
|
||||
async fn send_book_handler<T, Fut>(
|
||||
message: Message,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
command: BookCommand,
|
||||
books_getter: fn(id: u32, page: u32, allowed_langs: Vec<String>) -> Fut,
|
||||
) -> crate::bots::BotHandlerInternal
|
||||
@@ -196,7 +196,7 @@ where
|
||||
|
||||
async fn send_pagination_book_handler<T, Fut>(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
callback_data: BookCallbackData,
|
||||
books_getter: fn(id: u32, page: u32, allowed_langs: Vec<String>) -> Fut,
|
||||
) -> crate::bots::BotHandlerInternal
|
||||
@@ -295,7 +295,7 @@ pub fn get_book_handler() -> crate::bots::BotHandler {
|
||||
Update::filter_message()
|
||||
.chain(filter_command::<BookCommand>())
|
||||
.endpoint(
|
||||
|message: Message, bot: Bot, command: BookCommand| async move {
|
||||
|message: Message, bot: Throttle<Bot>, command: BookCommand| async move {
|
||||
match command {
|
||||
BookCommand::Author { .. } => {
|
||||
send_book_handler(
|
||||
@@ -331,7 +331,7 @@ pub fn get_book_handler() -> crate::bots::BotHandler {
|
||||
.branch(
|
||||
Update::filter_callback_query()
|
||||
.chain(filter_callback_query::<BookCallbackData>())
|
||||
.endpoint(|cq: CallbackQuery, bot: Bot, callback_data: BookCallbackData| async move {
|
||||
.endpoint(|cq: CallbackQuery, bot: Throttle<Bot>, callback_data: BookCallbackData| async move {
|
||||
match callback_data {
|
||||
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,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use futures::TryStreamExt;
|
||||
use regex::Regex;
|
||||
use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*};
|
||||
use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::Throttle};
|
||||
use tokio_util::compat::FuturesAsyncReadCompatExt;
|
||||
|
||||
use crate::{
|
||||
@@ -47,7 +47,7 @@ impl CommandParse<Self> for DownloadData {
|
||||
|
||||
async fn _send_cached(
|
||||
message: &Message,
|
||||
bot: &Bot,
|
||||
bot: &Throttle<Bot>,
|
||||
cached_message: CachedMessage,
|
||||
) -> BotHandlerInternal {
|
||||
match bot
|
||||
@@ -66,7 +66,7 @@ async fn _send_cached(
|
||||
|
||||
async fn send_cached_message(
|
||||
message: Message,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
download_data: DownloadData,
|
||||
) -> BotHandlerInternal {
|
||||
if let Ok(v) = get_cached_message(&download_data).await {
|
||||
@@ -83,7 +83,7 @@ async fn send_cached_message(
|
||||
|
||||
async fn _send_downloaded_file(
|
||||
message: &Message,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
downloaded_data: DownloadFile,
|
||||
) -> BotHandlerInternal {
|
||||
let DownloadFile {
|
||||
@@ -113,7 +113,7 @@ async fn _send_downloaded_file(
|
||||
|
||||
async fn send_with_download_from_channel(
|
||||
message: Message,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
download_data: DownloadData,
|
||||
) -> BotHandlerInternal {
|
||||
match download_file(&download_data).await {
|
||||
@@ -127,7 +127,7 @@ async fn send_with_download_from_channel(
|
||||
|
||||
async fn download_handler(
|
||||
message: Message,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
cache: BotCache,
|
||||
download_data: DownloadData,
|
||||
) -> BotHandlerInternal {
|
||||
@@ -143,7 +143,7 @@ pub fn get_download_hander() -> crate::bots::BotHandler {
|
||||
.chain(filter_command::<DownloadData>())
|
||||
.endpoint(
|
||||
|message: Message,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
cache: BotCache,
|
||||
download_data: DownloadData| async move {
|
||||
download_handler(message, bot, cache, download_data).await
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::bots::BotHandlerInternal;
|
||||
|
||||
use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode};
|
||||
use teloxide::{prelude::*, utils::command::BotCommands, types::ParseMode, adaptors::Throttle};
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
@@ -10,7 +10,7 @@ enum HelpCommand {
|
||||
}
|
||||
|
||||
|
||||
pub async fn help_handler(message: Message, bot: Bot) -> BotHandlerInternal {
|
||||
pub async fn help_handler(message: Message, bot: Throttle<Bot>) -> BotHandlerInternal {
|
||||
let name = message
|
||||
.from()
|
||||
.map(|user| user.first_name.clone())
|
||||
|
||||
@@ -2,7 +2,7 @@ use strum_macros::{Display, EnumIter};
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup},
|
||||
utils::command::BotCommands,
|
||||
utils::command::BotCommands, adaptors::Throttle,
|
||||
};
|
||||
|
||||
use crate::bots::{
|
||||
@@ -75,7 +75,7 @@ impl std::str::FromStr for RandomCallbackData {
|
||||
}
|
||||
}
|
||||
|
||||
async fn random_handler(message: Message, bot: Bot) -> crate::bots::BotHandlerInternal {
|
||||
async fn random_handler(message: Message, bot: Throttle<Bot>) -> crate::bots::BotHandlerInternal {
|
||||
const MESSAGE_TEXT: &str = "Что хотим получить?";
|
||||
|
||||
let keyboard = InlineKeyboardMarkup {
|
||||
@@ -122,7 +122,7 @@ async fn random_handler(message: Message, bot: Bot) -> crate::bots::BotHandlerIn
|
||||
|
||||
async fn get_random_item_handler_internal<T>(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
item: Result<T, Box<dyn std::error::Error + Send + Sync>>,
|
||||
) -> BotHandlerInternal
|
||||
where
|
||||
@@ -176,7 +176,7 @@ where
|
||||
|
||||
async fn get_random_item_handler<T, Fut>(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
item_getter: fn(allowed_langs: Vec<String>) -> Fut,
|
||||
) -> BotHandlerInternal
|
||||
where
|
||||
@@ -190,7 +190,7 @@ where
|
||||
get_random_item_handler_internal(cq, bot, item).await
|
||||
}
|
||||
|
||||
async fn get_genre_metas_handler(cq: CallbackQuery, bot: Bot) -> BotHandlerInternal {
|
||||
async fn get_genre_metas_handler(cq: CallbackQuery, bot: Throttle<Bot>) -> BotHandlerInternal {
|
||||
let genre_metas = match book_library::get_genre_metas().await {
|
||||
Ok(v) => v,
|
||||
Err(err) => return Err(err),
|
||||
@@ -243,7 +243,7 @@ async fn get_genre_metas_handler(cq: CallbackQuery, bot: Bot) -> BotHandlerInter
|
||||
|
||||
async fn get_genres_by_meta_handler(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
genre_index: u32,
|
||||
) -> BotHandlerInternal {
|
||||
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(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
genre_id: u32,
|
||||
) -> BotHandlerInternal {
|
||||
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(
|
||||
Update::filter_callback_query()
|
||||
.chain(filter_callback_query::<RandomCallbackData>())
|
||||
.endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: Bot| async move {
|
||||
.endpoint(|cq: CallbackQuery, callback_data: RandomCallbackData, bot: Throttle<Bot>| async move {
|
||||
match callback_data {
|
||||
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,
|
||||
|
||||
@@ -4,7 +4,7 @@ use regex::Regex;
|
||||
use strum_macros::EnumIter;
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup}, dispatching::dialogue::GetChatId,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup}, dispatching::dialogue::GetChatId, adaptors::Throttle,
|
||||
};
|
||||
|
||||
use crate::bots::{
|
||||
@@ -107,7 +107,7 @@ fn get_query(cq: CallbackQuery) -> Option<String> {
|
||||
|
||||
async fn generic_search_pagination_handler<T, Fut>(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
search_data: SearchCallbackData,
|
||||
items_getter: fn(query: String, page: u32, allowed_langs: Vec<String>) -> Fut,
|
||||
) -> BotHandlerInternal
|
||||
@@ -217,7 +217,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn message_handler(message: Message, bot: Bot) -> BotHandlerInternal {
|
||||
pub async fn message_handler(message: Message, bot: Throttle<Bot>) -> BotHandlerInternal {
|
||||
let message_text = "Что ищем?";
|
||||
|
||||
let keyboard = InlineKeyboardMarkup {
|
||||
@@ -268,7 +268,7 @@ pub fn get_search_handler() -> crate::bots::BotHandler {
|
||||
).branch(
|
||||
Update::filter_callback_query()
|
||||
.chain(filter_callback_query::<SearchCallbackData>())
|
||||
.endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: Bot| async move {
|
||||
.endpoint(|cq: CallbackQuery, callback_data: SearchCallbackData, bot: Throttle<Bot>| async move {
|
||||
match callback_data {
|
||||
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,
|
||||
|
||||
@@ -14,7 +14,7 @@ use regex::Regex;
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup, Me},
|
||||
utils::command::BotCommands,
|
||||
utils::command::BotCommands, adaptors::Throttle,
|
||||
};
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
@@ -67,7 +67,7 @@ impl ToString for SettingsCallbackData {
|
||||
}
|
||||
}
|
||||
|
||||
async fn settings_handler(message: Message, bot: Bot) -> BotHandlerInternal {
|
||||
async fn settings_handler(message: Message, bot: Throttle<Bot>) -> BotHandlerInternal {
|
||||
let keyboard = InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![vec![InlineKeyboardButton {
|
||||
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(
|
||||
cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
callback_data: SettingsCallbackData,
|
||||
me: Me,
|
||||
) -> BotHandlerInternal {
|
||||
@@ -219,7 +219,7 @@ pub fn get_settings_handler() -> crate::bots::BotHandler {
|
||||
.chain(filter_callback_query::<SettingsCallbackData>())
|
||||
.endpoint(
|
||||
|cq: CallbackQuery,
|
||||
bot: Bot,
|
||||
bot: Throttle<Bot>,
|
||||
callback_data: SettingsCallbackData,
|
||||
me: Me| async move {
|
||||
settings_callback_handler(cq, bot, callback_data, me).await
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::bots::BotHandlerInternal;
|
||||
use teloxide::{
|
||||
prelude::*,
|
||||
types::{InlineKeyboardButton, InlineKeyboardMarkup},
|
||||
utils::command::BotCommands,
|
||||
utils::command::BotCommands, adaptors::Throttle,
|
||||
};
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user