Add commands to title

This commit is contained in:
2023-06-07 04:18:42 +02:00
parent c5a969384a
commit 4083df0030
2 changed files with 22 additions and 16 deletions

View File

@@ -128,23 +128,23 @@ impl FromStr for DownloadQueryData {
}
#[derive(Clone, EnumIter)]
pub enum DownloadArchiveCommands {
Sequence { id: u32, file_format: String },
Author { id: u32, file_format: String },
Translator { id: u32, file_format: String }
pub enum DownloadArchiveCommand {
Sequence { id: u32},
Author { id: u32 },
Translator { id: u32 }
}
impl ToString for DownloadArchiveCommands {
impl ToString for DownloadArchiveCommand {
fn to_string(&self) -> String {
match self {
DownloadArchiveCommands::Sequence { id, file_format } => format!("da_s_{id}_{file_format}"),
DownloadArchiveCommands::Author { id, file_format } => format!("da_a_{id}_{file_format}"),
DownloadArchiveCommands::Translator { id, file_format } => format!("da_t_{id}_{file_format}"),
DownloadArchiveCommand::Sequence { id } => format!("da_s_{id}"),
DownloadArchiveCommand::Author { id } => format!("da_a_{id}"),
DownloadArchiveCommand::Translator { id } => format!("da_t_{id}"),
}
}
}
impl FromStr for DownloadArchiveCommands {
impl FromStr for DownloadArchiveCommand {
type Err = strum::ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -160,9 +160,9 @@ impl FromStr for DownloadArchiveCommands {
let file_type: String = caps["file_type"].to_string();
match &caps["type"] {
"s" => Ok(DownloadArchiveCommands::Sequence { id: obj_id, file_format: file_type }),
"a" => Ok(DownloadArchiveCommands::Author { id: obj_id, file_format: file_type }),
"t" => Ok(DownloadArchiveCommands::Translator { id: obj_id, file_format: file_type }),
"s" => Ok(DownloadArchiveCommand::Sequence { id: obj_id }),
"a" => Ok(DownloadArchiveCommand::Author { id: obj_id }),
"t" => Ok(DownloadArchiveCommand::Translator { id: obj_id }),
_ => Err(strum::ParseError::VariantNotFound)
}
}

View File

@@ -1,6 +1,6 @@
use std::cmp::min;
use crate::bots::approved_bot::modules::download::StartDownloadCommand;
use crate::bots::approved_bot::modules::download::{StartDownloadCommand, DownloadArchiveCommand};
use super::types::{
Author, AuthorBook, Book, BookAuthor, BookGenre, SearchBook, Sequence, Translator,
@@ -48,7 +48,9 @@ impl FormatTitle for BookAuthor {
return "".to_string()
}
format!("👤 {last_name} {first_name} {middle_name}")
let command = (DownloadArchiveCommand::Author { id: *id }).to_string();
format!("👤 {last_name} {first_name} {middle_name}\n{command}")
}
}
@@ -65,7 +67,9 @@ impl FormatTitle for BookTranslator {
return "".to_string()
}
format!("👤 {last_name} {first_name} {middle_name}")
let command = (DownloadArchiveCommand::Translator { id: *id }).to_string();
format!("👤 {last_name} {first_name} {middle_name}\n{command}")
}
}
@@ -77,7 +81,9 @@ impl FormatTitle for Sequence {
return "".to_string()
}
format!("📚 {name}")
let command = (DownloadArchiveCommand::Sequence { id: *id }).to_string();
format!("📚 {name}\n{command}")
}
}