Update deps and refactor

This commit is contained in:
2025-08-09 23:10:40 +02:00
parent ae292b180c
commit 34f0c9feb6
18 changed files with 387 additions and 358 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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