Added LocaleString type that can be converted to String to reduce the ammount of as_refs

This commit is contained in:
2024-04-22 15:17:51 +03:00
parent 86c7b4d0c4
commit 305b796d51
35 changed files with 202 additions and 192 deletions

View File

@@ -31,7 +31,7 @@ async fn get_master_pass(
.await?;
account.insert(&db).await?;
ids.alter_message(&bot, locale.success.as_ref(), deletion_markup(locale), None)
ids.alter_message(&bot, &locale.success, deletion_markup(locale), None)
.await?;
Ok(())
}

View File

@@ -3,7 +3,7 @@ use crate::prelude::*;
/// Handles /cancel command when there's no active state
#[inline]
pub async fn cancel(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
bot.send_message(msg.chat.id, locale.nothing_to_cancel.as_ref())
bot.send_message(msg.chat.id, &locale.nothing_to_cancel)
.reply_markup(deletion_markup(locale))
.await?;
Ok(())

View File

@@ -6,7 +6,7 @@ pub async fn change_language(
msg: Message,
locale: LocaleRef,
) -> crate::Result<()> {
bot.send_message(msg.chat.id, locale.choose_language.as_ref())
bot.send_message(msg.chat.id, &locale.choose_language)
.reply_markup(language_markup())
.await?;
Ok(())

View File

@@ -12,13 +12,13 @@ pub async fn delete(
let markup = menu_markup("delete1", user_id, &db).await?;
if markup.inline_keyboard.is_empty() {
bot.send_message(msg.chat.id, locale.no_accounts_found.as_ref())
bot.send_message(msg.chat.id, &locale.no_accounts_found)
.reply_markup(deletion_markup(locale))
.await?;
return Ok(());
}
bot.send_message(msg.chat.id, locale.choose_account.as_ref())
bot.send_message(msg.chat.id, &locale.choose_account)
.reply_markup(markup)
.await?;
Ok(())

View File

@@ -24,12 +24,12 @@ async fn get_master_pass(
let text = match result {
(Ok(()), Ok(())) => {
txn.commit().await?;
locale.everything_was_deleted.as_ref()
&locale.everything_was_deleted
}
(Err(err), _) | (_, Err(err)) => {
error!("{}", crate::Error::from(err));
txn.rollback().await?;
locale.something_went_wrong.as_ref()
&locale.something_went_wrong
}
};
ids.alter_message(&bot, text, deletion_markup(locale), None)

View File

@@ -12,13 +12,13 @@ pub async fn get_account(
let markup = menu_markup("decrypt", user_id, &db).await?;
if markup.inline_keyboard.is_empty() {
bot.send_message(msg.chat.id, locale.no_accounts_found.as_ref())
bot.send_message(msg.chat.id, &locale.no_accounts_found)
.reply_markup(deletion_markup(locale))
.await?;
return Ok(());
}
bot.send_message(msg.chat.id, locale.choose_account.as_ref())
bot.send_message(msg.chat.id, &locale.choose_account)
.reply_markup(markup)
.await?;
Ok(())

View File

@@ -14,7 +14,7 @@ pub async fn get_accounts(
let mut account_names = Account::get_names(user_id, &db);
let Some(mut text) = account_names.try_next().await? else {
bot.send_message(msg.chat.id, locale.no_accounts_found.as_ref())
bot.send_message(msg.chat.id, &locale.no_accounts_found)
.reply_markup(deletion_markup(locale))
.await?;
return Ok(());

View File

@@ -3,7 +3,7 @@ use crate::prelude::*;
/// Handles the help command by sending the passwords descryptions
#[inline]
pub async fn help(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
bot.send_message(msg.chat.id, locale.help_command.as_ref())
bot.send_message(msg.chat.id, &locale.help_command)
.reply_markup(deletion_markup(locale))
.await?;
Ok(())

View File

@@ -55,7 +55,7 @@ async fn get_master_pass(
}
let text = if failed.is_empty() {
locale.success.as_ref().to_owned()
locale.success.to_owned()
} else {
format!(
"{}:\n{}",

View File

@@ -12,13 +12,13 @@ pub async fn menu(
let markup = menu_markup("get", user_id, &db).await?;
if markup.inline_keyboard.is_empty() {
bot.send_message(msg.chat.id, locale.no_accounts_found.as_ref())
bot.send_message(msg.chat.id, &locale.no_accounts_found)
.reply_markup(deletion_markup(locale))
.await?;
return Ok(());
}
bot.send_message(msg.chat.id, locale.choose_account.as_ref())
bot.send_message(msg.chat.id, &locale.choose_account)
.reply_markup(markup)
.await?;
Ok(())

View File

@@ -22,7 +22,7 @@ async fn get_master_pass2(
if !hash.verify(master_pass.as_bytes()) {
ids.alter_message(
&bot,
locale.master_password_dont_match.as_ref(),
&locale.master_password_dont_match,
deletion_markup(locale),
None,
)
@@ -43,7 +43,7 @@ async fn get_master_pass2(
.unwrap_or_default();
model.insert(&db, locale_type).await?;
ids.alter_message(&bot, locale.success.as_ref(), deletion_markup(locale), None)
ids.alter_message(&bot, &locale.success, deletion_markup(locale), None)
.await?;
Ok(())
@@ -61,7 +61,7 @@ async fn get_master_pass(
) -> crate::Result<()> {
let hash = spawn_blocking(move || HashedBytes::new(master_pass.as_bytes())).await?;
ids.alter_message(&bot, locale.send_master_password_again.as_ref(), None, None)
ids.alter_message(&bot, &locale.send_master_password_again, None, None)
.await?;
change_state!(
@@ -86,13 +86,13 @@ pub async fn set_master_pass(
) -> crate::Result<()> {
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
if MasterPass::exists(user_id, &db).await? {
bot.send_message(msg.chat.id, locale.master_password_is_set.as_ref())
bot.send_message(msg.chat.id, &locale.master_password_is_set)
.reply_markup(deletion_markup(locale))
.await?;
return Ok(());
}
let previous = bot
.send_message(msg.chat.id, locale.send_new_master_password.as_ref())
.send_message(msg.chat.id, &locale.send_new_master_password)
.await?;
change_state!(

View File

@@ -3,7 +3,6 @@ use crate::prelude::*;
/// Handles /start command by sending the greeting message
#[inline]
pub async fn start(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
bot.send_message(msg.chat.id, locale.start_command.as_ref())
.await?;
bot.send_message(msg.chat.id, &locale.start_command).await?;
Ok(())
}