mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Fix message to long for books search
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
use super::types::{Author, AuthorBook, Book, SearchBook, Sequence, Translator, TranslatorBook};
|
use super::types::{Author, AuthorBook, Book, SearchBook, Sequence, Translator, TranslatorBook};
|
||||||
|
|
||||||
pub trait Format {
|
pub trait Format {
|
||||||
@@ -143,32 +145,34 @@ impl Format for SearchBook {
|
|||||||
false => "".to_string(),
|
false => "".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let authors = match self.authors.len() != 0 {
|
let authors = if self.authors.len() != 0 {
|
||||||
true => {
|
let formated_authors = self
|
||||||
let formated_authors = self
|
|
||||||
.authors
|
.authors
|
||||||
.clone()
|
.clone()[..min(5, self.authors.len())]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|author| author.format_author())
|
.map(|author| author.format_author())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
format!("Авторы:\n{formated_authors}\n")
|
|
||||||
}
|
let post_fix = if self.authors.len() > 5 { "\nи др." } else { "" };
|
||||||
false => "".to_string(),
|
format!("Авторы:\n{formated_authors}{post_fix}\n")
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let translators = match self.translators.len() != 0 {
|
let translators = if self.translators.len() != 0 {
|
||||||
true => {
|
let formated_translators = self
|
||||||
let formated_translators = self
|
|
||||||
.translators
|
.translators
|
||||||
.clone()
|
.clone()[..min(5, self.translators.len())]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|translator| translator.format_translator())
|
.map(|translator| translator.format_translator())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
format!("Переводчики:\n{formated_translators}\n")
|
|
||||||
}
|
let post_fix = if self.translators.len() > 5 { "\nи др." } else { "" };
|
||||||
false => "".to_string(),
|
format!("Переводчики:\n{formated_translators}{post_fix}\n")
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let links: String = self
|
let links: String = self
|
||||||
|
|||||||
Reference in New Issue
Block a user