mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Fixes
This commit is contained in:
@@ -9,7 +9,7 @@ use crate::{bots::approved_bot::services::user_settings::create_or_update_user_s
|
||||
use self::{
|
||||
modules::{
|
||||
annotations::get_annotations_handler, book::get_book_handler,
|
||||
download::get_download_hander, help::get_help_handler, random::get_random_hander,
|
||||
download::get_download_handler, help::get_help_handler, random::get_random_handler,
|
||||
search::get_search_handler, settings::get_settings_handler, support::get_support_handler,
|
||||
update_history::get_update_log_handler,
|
||||
},
|
||||
@@ -81,8 +81,8 @@ pub fn get_approved_handler() -> (BotHandler, BotCommands) {
|
||||
.branch(get_help_handler())
|
||||
.branch(get_settings_handler())
|
||||
.branch(get_support_handler())
|
||||
.branch(get_random_hander())
|
||||
.branch(get_download_hander())
|
||||
.branch(get_random_handler())
|
||||
.branch(get_download_handler())
|
||||
.branch(get_annotations_handler())
|
||||
.branch(get_book_handler())
|
||||
.branch(get_update_log_handler())
|
||||
|
||||
@@ -15,23 +15,21 @@ impl FromStr for AnnotationCallbackData {
|
||||
type Err = strum::ParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let re = Regex::new(r"^(?P<an_type>a|b)_an_(?P<id>\d+)_(?P<page>\d+)$").unwrap();
|
||||
|
||||
let caps = re.captures(s);
|
||||
let caps = match caps {
|
||||
Some(v) => v,
|
||||
None => return Err(strum::ParseError::VariantNotFound),
|
||||
};
|
||||
|
||||
let annotation_type = &caps["an_type"];
|
||||
let id = caps["id"].parse::<u32>().unwrap();
|
||||
let page = caps["page"].parse::<u32>().unwrap();
|
||||
|
||||
match annotation_type {
|
||||
"a" => Ok(AnnotationCallbackData::Author { id, page }),
|
||||
"b" => Ok(AnnotationCallbackData::Book { id, page }),
|
||||
_ => Err(strum::ParseError::VariantNotFound),
|
||||
}
|
||||
Regex::new(r"^(?P<an_type>[ab])_an_(?P<id>\d+)_(?P<page>\d+)$")
|
||||
.unwrap_or_else(|_| panic!("Broken AnnotationCallbackData regex pattern!"))
|
||||
.captures(s)
|
||||
.ok_or(strum::ParseError::VariantNotFound)
|
||||
.map(|caps| (
|
||||
caps["an_type"].to_string(),
|
||||
caps["id"].parse::<u32>().unwrap(),
|
||||
caps["page"].parse::<u32>().unwrap()
|
||||
))
|
||||
.map(|(annotation_type, id, page)|
|
||||
match annotation_type.as_str() {
|
||||
"a" => AnnotationCallbackData::Author { id, page },
|
||||
"b" => AnnotationCallbackData::Book { id, page },
|
||||
_ => panic!("Unknown AnnotationCallbackData type: {}!", annotation_type),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub enum AnnotationCommand {
|
||||
|
||||
impl CommandParse<Self> for AnnotationCommand {
|
||||
fn parse(s: &str, bot_name: &str) -> Result<Self, strum::ParseError> {
|
||||
let re = Regex::new(r"^/(?P<an_type>a|b)_an_(?P<id>\d+)$")
|
||||
let re = Regex::new(r"^/(?P<an_type>[ab])_an_(?P<id>\d+)$")
|
||||
.unwrap_or_else(|_| panic!("Can't create AnnotationCommand regexp!"));
|
||||
|
||||
let full_bot_name = format!("@{bot_name}");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
pub mod commands;
|
||||
pub mod callback_data;
|
||||
pub mod formater;
|
||||
pub mod formatter;
|
||||
pub mod errors;
|
||||
|
||||
use std::convert::TryInto;
|
||||
@@ -21,7 +21,7 @@ use crate::bots::{
|
||||
BotHandlerInternal,
|
||||
};
|
||||
|
||||
use self::{commands::AnnotationCommand, formater::AnnotationFormat, callback_data::AnnotationCallbackData, errors::AnnotationError};
|
||||
use self::{commands::AnnotationCommand, formatter::AnnotationFormat, callback_data::AnnotationCallbackData, errors::AnnotationError};
|
||||
|
||||
use super::utils::{filter_command, split_text_to_chunks};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ impl FromStr for BookCallbackData {
|
||||
type Err = strum::ParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let re = Regex::new(r"^b(?P<an_type>a|t|s)_(?P<id>\d+)_(?P<page>\d+)$").unwrap();
|
||||
let re = Regex::new(r"^b(?P<an_type>[ats])_(?P<id>\d+)_(?P<page>\d+)$").unwrap();
|
||||
|
||||
let caps = re.captures(s);
|
||||
let caps = match caps {
|
||||
|
||||
@@ -12,7 +12,7 @@ pub enum BookCommand {
|
||||
|
||||
impl CommandParse<Self> for BookCommand {
|
||||
fn parse(s: &str, bot_name: &str) -> Result<Self, strum::ParseError> {
|
||||
let re = Regex::new(r"^/(?P<an_type>a|t|s)_(?P<id>\d+)$").unwrap();
|
||||
let re = Regex::new(r"^/(?P<an_type>[ats])_(?P<id>\d+)$").unwrap();
|
||||
|
||||
let full_bot_name = format!("@{bot_name}");
|
||||
let after_replace = s.replace(&full_bot_name, "");
|
||||
|
||||
@@ -12,7 +12,7 @@ use tracing::log;
|
||||
use crate::bots::approved_bot::{
|
||||
services::{
|
||||
book_library::{
|
||||
formaters::{Format, FormatTitle}, get_author_books, get_sequence_books, get_translator_books,
|
||||
formatters::{Format, FormatTitle}, get_author_books, get_sequence_books, get_translator_books,
|
||||
types::Page,
|
||||
},
|
||||
user_settings::get_user_or_default_lang_codes,
|
||||
@@ -79,7 +79,7 @@ where
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let formated_page = items_page.format(1, 4096);
|
||||
let formatted_page = items_page.format(1, 4096);
|
||||
|
||||
let callback_data = match command {
|
||||
BookCommand::Author { id } => BookCallbackData::Author { id, page: 1 },
|
||||
@@ -90,7 +90,7 @@ where
|
||||
let keyboard = generic_get_pagination_keyboard(1, items_page.pages, callback_data, true);
|
||||
|
||||
bot
|
||||
.send_message(chat_id, formated_page)
|
||||
.send_message(chat_id, formatted_page)
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
@@ -166,12 +166,12 @@ where
|
||||
};
|
||||
}
|
||||
|
||||
let formated_page = items_page.format(page, 4096);
|
||||
let formatted_page = items_page.format(page, 4096);
|
||||
|
||||
let keyboard = generic_get_pagination_keyboard(page, items_page.pages, callback_data, true);
|
||||
|
||||
bot
|
||||
.edit_message_text(chat_id, message_id, formated_page)
|
||||
.edit_message_text(chat_id, message_id, formatted_page)
|
||||
.reply_markup(keyboard)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
@@ -59,7 +59,7 @@ impl FromStr for DownloadArchiveQueryData {
|
||||
type Err = strum::ParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let re = Regex::new(r"^da_(?P<obj_type>[s|a|t])_(?P<id>\d+)_(?P<file_type>\w+)$").unwrap();
|
||||
let re = Regex::new(r"^da_(?P<obj_type>[sat])_(?P<id>\d+)_(?P<file_type>\w+)$").unwrap();
|
||||
|
||||
let caps = re.captures(s);
|
||||
let caps = match caps {
|
||||
|
||||
@@ -54,7 +54,7 @@ impl ToString for DownloadArchiveCommand {
|
||||
|
||||
impl CommandParse<Self> for DownloadArchiveCommand {
|
||||
fn parse(s: &str, bot_name: &str) -> Result<Self, strum::ParseError> {
|
||||
let re = Regex::new(r"^/da_(?P<type>[s|a|t])_(?P<id>\d+)$").unwrap();
|
||||
let re = Regex::new(r"^/da_(?P<type>[sat])_(?P<id>\d+)$").unwrap();
|
||||
|
||||
let full_bot_name = format!("@{bot_name}");
|
||||
let after_replace = s.replace(&full_bot_name, "");
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod commads;
|
||||
pub mod commands;
|
||||
pub mod callback_data;
|
||||
|
||||
use std::time::Duration;
|
||||
@@ -27,7 +27,7 @@ use crate::{
|
||||
types::{CachedMessage, DownloadFile}, download_file_by_link, get_download_link,
|
||||
},
|
||||
book_library::{get_book, get_author_books_available_types, get_translator_books_available_types, get_sequence_books_available_types},
|
||||
donation_notificatioins::send_donation_notification, user_settings::get_user_or_default_lang_codes, batch_downloader::{TaskObjectType, CreateTaskData},
|
||||
donation_notifications::send_donation_notification, user_settings::get_user_or_default_lang_codes, batch_downloader::{TaskObjectType, CreateTaskData},
|
||||
batch_downloader::{create_task, get_task, TaskStatus}
|
||||
|
||||
},
|
||||
@@ -38,7 +38,7 @@ use crate::{
|
||||
bots_manager::BotCache,
|
||||
};
|
||||
|
||||
use self::{callback_data::{CheckArchiveStatus, DownloadQueryData}, commads::{StartDownloadCommand, DownloadArchiveCommand}};
|
||||
use self::{callback_data::{CheckArchiveStatus, DownloadQueryData}, commands::{StartDownloadCommand, DownloadArchiveCommand}};
|
||||
|
||||
use super::utils::filter_command;
|
||||
|
||||
@@ -179,7 +179,6 @@ async fn send_download_link(
|
||||
.reply_markup(InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![],
|
||||
})
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -400,7 +399,6 @@ async fn wait_archive(
|
||||
.reply_markup(InlineKeyboardMarkup {
|
||||
inline_keyboard: vec![],
|
||||
})
|
||||
.send()
|
||||
.await;
|
||||
log::error!("{:?}", err);
|
||||
return Err(err);
|
||||
@@ -459,7 +457,7 @@ async fn download_archive(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_download_hander() -> crate::bots::BotHandler {
|
||||
pub fn get_download_handler() -> crate::bots::BotHandler {
|
||||
dptree::entry()
|
||||
.branch(
|
||||
Update::filter_message()
|
||||
|
||||
@@ -32,7 +32,6 @@ pub async fn help_handler(message: Message, bot: CacheMe<Throttle<Bot>>) -> BotH
|
||||
),
|
||||
)
|
||||
.parse_mode(ParseMode::Html)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(()),
|
||||
|
||||
@@ -12,7 +12,7 @@ use teloxide::{
|
||||
use crate::bots::{
|
||||
approved_bot::{
|
||||
services::{
|
||||
book_library::{self, formaters::Format},
|
||||
book_library::{self, formatters::Format},
|
||||
user_settings::get_user_or_default_lang_codes,
|
||||
},
|
||||
tools::filter_callback_query, modules::random::callback_data::RandomCallbackData,
|
||||
@@ -247,7 +247,7 @@ async fn get_random_book_by_genre(
|
||||
get_random_item_handler_internal(cq, bot, item).await
|
||||
}
|
||||
|
||||
pub fn get_random_hander() -> crate::bots::BotHandler {
|
||||
pub fn get_random_handler() -> crate::bots::BotHandler {
|
||||
dptree::entry()
|
||||
.branch(
|
||||
Update::filter_message()
|
||||
|
||||
@@ -29,7 +29,7 @@ impl FromStr for SearchCallbackData {
|
||||
type Err = strum::ParseError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let re = Regex::new(r"^(?P<search_type>s[a|b|s|t])_(?P<page>\d+)$").unwrap();
|
||||
let re = Regex::new(r"^(?P<search_type>s[abst])_(?P<page>\d+)$").unwrap();
|
||||
|
||||
let caps = re.captures(s);
|
||||
let caps = match caps {
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::bots::{
|
||||
approved_bot::{
|
||||
services::{
|
||||
book_library::{
|
||||
formaters::{Format, FormatTitle}, search_author, search_book, search_sequence, search_translator,
|
||||
formatters::{Format, FormatTitle}, search_author, search_book, search_sequence, search_translator,
|
||||
types::Page,
|
||||
},
|
||||
user_settings::get_user_or_default_lang_codes,
|
||||
|
||||
@@ -118,9 +118,9 @@ async fn update_log_pagination_handler(
|
||||
let page = update_callback_data.page;
|
||||
let total_pages = items_page.pages;
|
||||
|
||||
let formated_page = items_page.format(page, 4096);
|
||||
let formatted_page = items_page.format(page, 4096);
|
||||
|
||||
let message_text = format!("{header}{formated_page}");
|
||||
let message_text = format!("{header}{formatted_page}");
|
||||
|
||||
let keyboard = generic_get_pagination_keyboard(page, total_pages, update_callback_data, true);
|
||||
bot
|
||||
|
||||
@@ -19,7 +19,7 @@ pub enum TaskStatus {
|
||||
InProgress,
|
||||
Archiving,
|
||||
Complete,
|
||||
Failled
|
||||
Failed
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::cmp::min;
|
||||
|
||||
use crate::bots::approved_bot::modules::download::commads::{StartDownloadCommand, DownloadArchiveCommand};
|
||||
use crate::bots::approved_bot::modules::download::commands::{StartDownloadCommand, DownloadArchiveCommand};
|
||||
|
||||
use super::types::{
|
||||
Author, AuthorBook, Book, BookAuthor, BookGenre, SearchBook, Sequence, Translator,
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod formaters;
|
||||
pub mod formatters;
|
||||
pub mod types;
|
||||
|
||||
use smartstring::alias::String as SmartString;
|
||||
|
||||
@@ -2,7 +2,7 @@ use core::fmt::Debug;
|
||||
use serde::Deserialize;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use super::formaters::{Format, FormatResult, FormatTitle};
|
||||
use super::formatters::{Format, FormatResult, FormatTitle};
|
||||
|
||||
|
||||
#[derive(Default, Deserialize, Debug, Clone)]
|
||||
|
||||
@@ -2,7 +2,7 @@ use teloxide::{types::Message, adaptors::{CacheMe, Throttle}, Bot};
|
||||
|
||||
use crate::{bots::{BotHandlerInternal, approved_bot::modules::support::support_command_handler}, bots_manager::CHAT_DONATION_NOTIFICATIONS_CACHE};
|
||||
|
||||
use super::user_settings::{is_need_donate_notifications, mark_donate_notification_sended};
|
||||
use super::user_settings::{is_need_donate_notifications, mark_donate_notification_sent};
|
||||
|
||||
|
||||
pub async fn send_donation_notification(
|
||||
@@ -17,7 +17,7 @@ pub async fn send_donation_notification(
|
||||
}
|
||||
|
||||
CHAT_DONATION_NOTIFICATIONS_CACHE.insert(message.chat.id, ()).await;
|
||||
mark_donate_notification_sended(message.chat.id).await?;
|
||||
mark_donate_notification_sent(message.chat.id).await?;
|
||||
|
||||
support_command_handler(message, bot).await?;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod book_cache;
|
||||
pub mod book_library;
|
||||
pub mod user_settings;
|
||||
pub mod donation_notificatioins;
|
||||
pub mod donation_notifications;
|
||||
pub mod batch_downloader;
|
||||
|
||||
@@ -129,7 +129,7 @@ pub async fn is_need_donate_notifications(chat_id: ChatId) -> Result<bool, Box<d
|
||||
Ok(response.json::<bool>().await?)
|
||||
}
|
||||
|
||||
pub async fn mark_donate_notification_sended(chat_id: ChatId) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
pub async fn mark_donate_notification_sent(chat_id: ChatId) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
reqwest::Client::new()
|
||||
.post(format!("{}/donate_notifications/{chat_id}", &config::CONFIG.user_settings_url))
|
||||
.header("Authorization", &config::CONFIG.user_settings_api_key)
|
||||
|
||||
@@ -10,6 +10,7 @@ mod bots;
|
||||
mod bots_manager;
|
||||
mod config;
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
|
||||
Reference in New Issue
Block a user