This commit is contained in:
2023-05-09 00:08:02 +02:00
parent 0785cf6a21
commit 0b875cee25
12 changed files with 35 additions and 36 deletions

View File

@@ -108,7 +108,7 @@ impl AnnotationFormat for BookAnnotation {
}
fn is_normal_text(&self) -> bool {
self.text.replace('\n', "").replace(' ', "").len() != 0
!self.text.replace(['\n', ' '], "").is_empty()
}
}
@@ -116,11 +116,11 @@ impl GetPaginationCallbackData for AnnotationCallbackData {
fn get_pagination_callback_data(&self, target_page: u32) -> String {
match self {
AnnotationCallbackData::Book { id, .. } => AnnotationCallbackData::Book {
id: id.clone(),
id: *id,
page: target_page,
},
AnnotationCallbackData::Author { id, .. } => AnnotationCallbackData::Author {
id: id.clone(),
id: *id,
page: target_page,
},
}
@@ -138,7 +138,7 @@ impl AnnotationFormat for AuthorAnnotation {
}
fn is_normal_text(&self) -> bool {
self.text.replace("\n", "").replace(' ', "").len() != 0
!self.text.replace(['\n', ' '], "").is_empty()
}
}

View File

@@ -96,15 +96,15 @@ impl GetPaginationCallbackData for BookCallbackData {
fn get_pagination_callback_data(&self, target_page: u32) -> String {
match self {
BookCallbackData::Author { id, .. } => BookCallbackData::Author {
id: id.clone(),
id: *id,
page: target_page,
},
BookCallbackData::Translator { id, .. } => BookCallbackData::Translator {
id: id.clone(),
id: *id,
page: target_page,
},
BookCallbackData::Sequence { id, .. } => BookCallbackData::Sequence {
id: id.clone(),
id: *id,
page: target_page,
},
}

View File

@@ -71,7 +71,7 @@ impl std::str::FromStr for RandomCallbackData {
}
}
return Err(strum::ParseError::VariantNotFound);
Err(strum::ParseError::VariantNotFound)
}
}
@@ -169,7 +169,7 @@ where
Err(int_error) => return Err(Box::new(int_error)),
}
return Err(err);
Err(err)
}
}
}
@@ -210,7 +210,6 @@ async fn get_genre_metas_handler(cq: CallbackQuery, bot: CacheMe<Throttle<Bot>>)
RandomCallbackData::Genres {
index: index as u32
}
.to_string()
)),
text: genre_meta,
}]
@@ -277,7 +276,7 @@ async fn get_genres_by_meta_handler(
vec![InlineKeyboardButton {
kind: teloxide::types::InlineKeyboardButtonKind::CallbackData(format!(
"{}_{}",
RandomCallbackData::RandomBookByGenre { id: genre.id }.to_string(),
RandomCallbackData::RandomBookByGenre { id: genre.id },
genre.id
)),
text: genre.description,

View File

@@ -98,7 +98,7 @@ fn get_query(cq: CallbackQuery) -> Option<String> {
.map(|reply_to_message| {
reply_to_message
.text()
.map(|text| text.replace('/', "").replace('&', "").replace('?', ""))
.map(|text| text.replace(['/', '&', '?'], ""))
})
.unwrap_or(None)
})

View File

@@ -150,7 +150,7 @@ async fn settings_callback_handler(
}
};
if allowed_langs_set.len() == 0 {
if allowed_langs_set.is_empty() {
return match bot
.answer_callback_query(cq.id)
.text("Должен быть активен, хотя бы один язык!")

View File

@@ -69,8 +69,8 @@ impl GetPaginationCallbackData for UpdateLogCallbackData {
fn get_pagination_callback_data(&self, target_page: u32) -> String {
let UpdateLogCallbackData { from, to, .. } = self;
UpdateLogCallbackData {
from: from.clone(),
to: to.clone(),
from: *from,
to: *to,
page: target_page,
}
.to_string()

View File

@@ -73,14 +73,14 @@ where
&search_data,
))
}
if t_page + 1 <= total_pages.into() {
if t_page < total_pages.into() {
one_page_row.push(generic_get_pagination_button(
page + 1,
PaginationDelta::OnePlus,
&search_data,
))
}
if one_page_row.len() != 0 {
if !one_page_row.is_empty() {
result.push(one_page_row);
}
@@ -93,14 +93,14 @@ where
&search_data,
))
}
if t_page + 1 <= total_pages.into() {
if t_page < total_pages.into() {
five_page_row.push(generic_get_pagination_button(
page + 5,
PaginationDelta::FivePlus,
&search_data,
))
}
if five_page_row.len() != 0 {
if !five_page_row.is_empty() {
result.push(five_page_row);
}
}
@@ -118,7 +118,7 @@ pub fn split_text_to_chunks(text: &str, width: usize) -> Vec<String> {
let chunks = textwrap::wrap(text, 512)
.into_iter()
.filter(|text| text.replace('\r', "").len() != 0)
.filter(|text| !text.replace('\r', "").is_empty())
.map(|text| text.to_string());
let mut index = 0;

View File

@@ -26,7 +26,7 @@ impl Format for Book {
false => "".to_string(),
};
let authors = match self.authors.len() != 0 {
let authors = match !self.authors.is_empty() {
true => {
let formated_authors = self
.authors
@@ -40,7 +40,7 @@ impl Format for Book {
false => "".to_string(),
};
let translators = match self.translators.len() != 0 {
let translators = match !self.translators.is_empty() {
true => {
let formated_translators = self
.translators
@@ -54,7 +54,7 @@ impl Format for Book {
false => "".to_string(),
};
let sequences = match self.sequences.len() != 0 {
let sequences = match !self.sequences.is_empty() {
true => {
let formated_sequences: String = self
.sequences
@@ -68,7 +68,7 @@ impl Format for Book {
false => "".to_string(),
};
let genres = match self.genres.len() != 0 {
let genres = match !self.genres.is_empty() {
true => {
let formated_genres: String = self
.genres
@@ -145,11 +145,11 @@ impl Format for SearchBook {
false => "".to_string(),
};
let authors = if self.authors.len() != 0 {
let authors = if !self.authors.is_empty() {
let formated_authors = self
.authors
.clone()[..min(5, self.authors.len())]
.into_iter()
.iter()
.map(|author| author.format_author())
.collect::<Vec<String>>()
.join("\n");
@@ -160,11 +160,11 @@ impl Format for SearchBook {
"".to_string()
};
let translators = if self.translators.len() != 0 {
let translators = if !self.translators.is_empty() {
let formated_translators = self
.translators
.clone()[..min(5, self.translators.len())]
.into_iter()
.iter()
.map(|translator| translator.format_translator())
.collect::<Vec<String>>()
.join("\n");
@@ -227,7 +227,7 @@ impl Format for AuthorBook {
false => "".to_string(),
};
let translators = match self.translators.len() != 0 {
let translators = match !self.translators.is_empty() {
true => {
let formated_translators = self
.translators
@@ -272,7 +272,7 @@ impl Format for TranslatorBook {
false => "".to_string(),
};
let authors = match self.authors.len() != 0 {
let authors = match !self.authors.is_empty() {
true => {
let formated_authors = self
.authors

View File

@@ -18,7 +18,7 @@ pub async fn message_handler(
let result = register::register(from_user.id, text).await;
let message_text = match result {
register::RegisterStatus::Success { ref username } => format_registered_message(&username),
register::RegisterStatus::Success { ref username } => format_registered_message(username),
register::RegisterStatus::WrongToken => strings::ERROR_MESSAGE.to_string(),
register::RegisterStatus::RegisterFail => strings::ALREADY_REGISTERED.to_string(),
};
@@ -30,7 +30,7 @@ pub async fn message_handler(
.await;
}
return Ok(());
Ok(())
}
pub fn get_manager_handler() -> Handler<

View File

@@ -68,5 +68,5 @@ pub async fn register(user_id: UserId, message_text: &str) -> RegisterStatus {
return RegisterStatus::RegisterFail;
}
return RegisterStatus::Success { username: bot_username };
RegisterStatus::Success { username: bot_username }
}

View File

@@ -1,5 +1,5 @@
pub fn format_registered_message(username: &str) -> String {
return format!("@{username} зарегистрирован и через несколько минут будет подключен!", username = username);
format!("@{username} зарегистрирован и через несколько минут будет подключен!", username = username)
}
pub const ALREADY_REGISTERED: &str= "Ошибка! Возможно бот уже зарегистрирован!";

View File

@@ -157,8 +157,8 @@ impl BotsManager {
async fn update_data(&mut self, bots_data: Vec<BotData>) {
for bot_data in bots_data.iter() {
if !self.bot_port_map.contains_key(&bot_data.id) {
self.bot_port_map.insert(bot_data.id, self.next_port);
if let std::collections::hash_map::Entry::Vacant(e) = self.bot_port_map.entry(bot_data.id) {
e.insert(self.next_port);
self.next_port += 1;
}