Locale bug fixing

This commit is contained in:
StNicolay 2024-05-02 17:01:24 +03:00
parent e8be611404
commit 9af37f78b2
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
2 changed files with 8 additions and 5 deletions

View File

@ -5,13 +5,11 @@ use std::fmt::Write;
use teloxide::types::ParseMode;
use tokio::task::spawn_blocking;
const MESSAGE_HEADER: &str = "Passwords:";
const PASSWORD_LENGTH: usize = 32;
const PASSWORD_PADDING_LENGTH: usize = 3;
const AMOUNT_OF_PASSWORDS: usize = 10;
type PasswordArray = [ArrayString<PASSWORD_LENGTH>; AMOUNT_OF_PASSWORDS];
const BUFFER_LENGTH: usize =
MESSAGE_HEADER.len() + (PASSWORD_LENGTH + PASSWORD_PADDING_LENGTH) * AMOUNT_OF_PASSWORDS;
const BUFFER_LENGTH: usize = (PASSWORD_LENGTH + PASSWORD_PADDING_LENGTH) * AMOUNT_OF_PASSWORDS;
/// Handles /`gen_password` command by generating 10 copyable passwords and sending them to the user
#[inline]
@ -20,7 +18,7 @@ pub async fn gen_password(
msg: Message,
locale: LocaleRef,
) -> crate::Result<()> {
let mut message: ArrayString<BUFFER_LENGTH> = MESSAGE_HEADER.try_into().unwrap();
let mut message = ArrayString::<BUFFER_LENGTH>::new();
let passwords: PasswordArray = spawn_blocking(generate_passwords).await?;
for password in passwords {
write!(message, "\n`{password}`").unwrap();

View File

@ -26,7 +26,12 @@ fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(),
write!(error_text, "\n* {}", locale.master_pass_too_short).unwrap();
}
error_text.push_str(&locale.change_master_password_and_send_again);
write!(
error_text,
"\n{}",
locale.change_master_password_and_send_again
)
.unwrap();
Err(error_text)
}