Add pre-commit

This commit is contained in:
2023-09-24 22:37:40 +02:00
parent 0afe3acfcd
commit 452040e83a
51 changed files with 771 additions and 596 deletions

View File

@@ -1,30 +1,36 @@
pub mod commands;
pub mod callback_data;
pub mod formatter;
pub mod commands;
pub mod errors;
pub mod formatter;
use std::convert::TryInto;
use futures::TryStreamExt;
use teloxide::{dispatching::UpdateFilterExt, dptree, prelude::*, types::*, adaptors::{Throttle, CacheMe}};
use teloxide::{
adaptors::{CacheMe, Throttle},
dispatching::UpdateFilterExt,
dptree,
prelude::*,
types::*,
};
use tokio_util::compat::FuturesAsyncReadCompatExt;
use crate::bots::{
approved_bot::{
modules::utils::pagination::generic_get_pagination_keyboard,
services::book_library::{
get_author_annotation, get_book_annotation,
},
services::book_library::{get_author_annotation, get_book_annotation},
tools::filter_callback_query,
},
BotHandlerInternal,
};
use self::{commands::AnnotationCommand, formatter::AnnotationFormat, callback_data::AnnotationCallbackData, errors::AnnotationFormatError};
use super::utils::{split_text::split_text_to_chunks, filter_command::filter_command};
use self::{
callback_data::AnnotationCallbackData, commands::AnnotationCommand,
errors::AnnotationFormatError, formatter::AnnotationFormat,
};
use super::utils::{filter_command::filter_command, split_text::split_text_to_chunks};
async fn download_image(
file: &String,
@@ -32,7 +38,6 @@ async fn download_image(
Ok(reqwest::get(file).await?.error_for_status()?)
}
pub async fn send_annotation_handler<T, Fut>(
message: Message,
bot: CacheMe<Throttle<Bot>>,
@@ -72,9 +77,9 @@ where
.into_async_read()
.compat();
#[allow(unused_must_use)] {
bot
.send_photo(message.chat.id, InputFile::read(data))
#[allow(unused_must_use)]
{
bot.send_photo(message.chat.id, InputFile::read(data))
.send()
.await;
}
@@ -82,26 +87,24 @@ where
};
if !annotation.is_normal_text() {
return Err(Box::new(AnnotationFormatError { command, text: annotation.get_text().to_string() }));
return Err(Box::new(AnnotationFormatError {
command,
text: annotation.get_text().to_string(),
}));
}
let annotation_text = annotation.get_text();
let chunked_text = split_text_to_chunks(annotation_text, 512);
let current_text = chunked_text.get(0).unwrap();
let current_text = chunked_text.get(0).unwrap();
let callback_data = match command {
AnnotationCommand::Book { id } => AnnotationCallbackData::Book { id, page: 1 },
AnnotationCommand::Author { id } => AnnotationCallbackData::Author { id, page: 1 },
};
let keyboard = generic_get_pagination_keyboard(
1,
chunked_text.len().try_into()?,
callback_data,
false,
);
let keyboard =
generic_get_pagination_keyboard(1, chunked_text.len().try_into()?, callback_data, false);
bot
.send_message(message.chat.id, current_text)
bot.send_message(message.chat.id, current_text)
.reply_markup(keyboard)
.send()
.await?;
@@ -109,7 +112,6 @@ where
Ok(())
}
pub async fn annotation_pagination_handler<T, Fut>(
cq: CallbackQuery,
bot: CacheMe<Throttle<Bot>>,
@@ -144,15 +146,10 @@ where
};
let current_text = chunked_text.get(page_index - 1).unwrap();
let keyboard = generic_get_pagination_keyboard(
page,
chunked_text.len().try_into()?,
callback_data,
false,
);
let keyboard =
generic_get_pagination_keyboard(page, chunked_text.len().try_into()?, callback_data, false);
bot
.edit_message_text(message.chat.id, message.id, current_text)
bot.edit_message_text(message.chat.id, message.id, current_text)
.reply_markup(keyboard)
.send()
.await?;
@@ -160,7 +157,6 @@ where
Ok(())
}
pub fn get_annotations_handler() -> crate::bots::BotHandler {
dptree::entry()
.branch(