Added LocaleString type that can be converted to String to reduce the ammount of as_refs
This commit is contained in:
parent
86c7b4d0c4
commit
305b796d51
59
Cargo.lock
generated
59
Cargo.lock
generated
@ -172,9 +172,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.94"
|
version = "1.0.95"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7"
|
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
@ -596,7 +596,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1143,6 +1143,7 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"base64 0.22.0",
|
"base64 0.22.0",
|
||||||
"cryptography",
|
"cryptography",
|
||||||
|
"derive_more",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"entity",
|
"entity",
|
||||||
"futures",
|
"futures",
|
||||||
@ -1219,7 +1220,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1314,9 +1315,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.80"
|
version = "1.0.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e"
|
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@ -1503,9 +1504,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "0.38.32"
|
version = "0.38.33"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89"
|
checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"errno",
|
"errno",
|
||||||
@ -1516,9 +1517,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustls"
|
name = "rustls"
|
||||||
version = "0.21.10"
|
version = "0.21.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba"
|
checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"ring",
|
"ring",
|
||||||
@ -1596,22 +1597,22 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.197"
|
version = "1.0.198"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
|
checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.197"
|
version = "1.0.198"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1686,9 +1687,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.1"
|
version = "1.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
|
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
@ -1994,9 +1995,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.59"
|
version = "2.0.60"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a"
|
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -2135,22 +2136,22 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.58"
|
version = "1.0.59"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
|
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.58"
|
version = "1.0.59"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
|
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2194,7 +2195,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2258,7 +2259,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2439,7 +2440,7 @@ dependencies = [
|
|||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2473,7 +2474,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
"wasm-bindgen-backend",
|
"wasm-bindgen-backend",
|
||||||
"wasm-bindgen-shared",
|
"wasm-bindgen-shared",
|
||||||
]
|
]
|
||||||
@ -2720,7 +2721,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.59",
|
"syn 2.0.60",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -27,6 +27,7 @@ anyhow = "1"
|
|||||||
arrayvec = "0.7"
|
arrayvec = "0.7"
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
cryptography = { version = "0.1", path = "cryptography" }
|
cryptography = { version = "0.1", path = "cryptography" }
|
||||||
|
derive_more = { version = "0.99.17", default-features = false, features = ["deref", "display"] }
|
||||||
dotenvy = "0.15"
|
dotenvy = "0.15"
|
||||||
entity = { version = "0.1", path = "entity" }
|
entity = { version = "0.1", path = "entity" }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
@ -58,7 +58,7 @@ async fn get_master_pass(
|
|||||||
|
|
||||||
ids.alter_message(
|
ids.alter_message(
|
||||||
&bot,
|
&bot,
|
||||||
locale.success_choose_account_to_view.as_ref(),
|
&locale.success_choose_account_to_view,
|
||||||
menu_markup("get", user_id, &db).await?,
|
menu_markup("get", user_id, &db).await?,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -89,18 +89,18 @@ pub async fn alter(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let text = match field {
|
let text: &str = match field {
|
||||||
Name => {
|
Name => {
|
||||||
change_state!(dialogue, ids, (name, field), State::GetNewName, get_field);
|
change_state!(dialogue, ids, (name, field), State::GetNewName, get_field);
|
||||||
locale.send_new_name.as_ref()
|
&locale.send_new_name
|
||||||
}
|
}
|
||||||
Login => {
|
Login => {
|
||||||
change_state!(dialogue, ids, (name, field), State::GetLogin, get_field);
|
change_state!(dialogue, ids, (name, field), State::GetLogin, get_field);
|
||||||
locale.send_new_login.as_ref()
|
&locale.send_new_login
|
||||||
}
|
}
|
||||||
Pass => {
|
Pass => {
|
||||||
change_state!(dialogue, ids, (name, field), State::GetPassword, get_field);
|
change_state!(dialogue, ids, (name, field), State::GetPassword, get_field);
|
||||||
locale.send_new_password.as_ref()
|
&locale.send_new_password
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ pub async fn change_locale(
|
|||||||
if !is_successful {
|
if !is_successful {
|
||||||
ids.alter_message(
|
ids.alter_message(
|
||||||
&bot,
|
&bot,
|
||||||
locale.something_went_wrong.as_ref(),
|
&locale.something_went_wrong,
|
||||||
deletion_markup(locale),
|
deletion_markup(locale),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -30,13 +30,8 @@ pub async fn change_locale(
|
|||||||
}
|
}
|
||||||
|
|
||||||
locale = new_locale.get_locale();
|
locale = new_locale.get_locale();
|
||||||
ids.alter_message(
|
ids.alter_message(&bot, &locale.choose_language, language_markup(), None)
|
||||||
&bot,
|
.await?;
|
||||||
locale.choose_language.as_ref(),
|
|
||||||
language_markup(),
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ async fn get_master_pass(
|
|||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
|
|
||||||
let Some(account) = Account::get(user_id, &name, &db).await? else {
|
let Some(account) = Account::get(user_id, &name, &db).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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -53,14 +53,14 @@ pub async fn decrypt(
|
|||||||
let user_id = q.from.id.0;
|
let user_id = q.from.id.0;
|
||||||
|
|
||||||
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
||||||
bot.send_message(ids.0, locale.no_accounts_found.as_ref())
|
bot.send_message(ids.0, &locale.no_accounts_found)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
bot.answer_callback_query(q.id).await?;
|
bot.answer_callback_query(q.id).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
ids.alter_message(&bot, locale.send_master_password.as_ref(), None, None)
|
ids.alter_message(&bot, &locale.send_master_password, None, None)
|
||||||
.await?;
|
.await?;
|
||||||
bot.answer_callback_query(q.id).await?;
|
bot.answer_callback_query(q.id).await?;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ async fn get_master_pass(
|
|||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
Account::delete(user_id, &name, &db).await?;
|
Account::delete(user_id, &name, &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?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -32,19 +32,19 @@ pub async fn delete(
|
|||||||
locale: LocaleRef,
|
locale: LocaleRef,
|
||||||
(hash, is_command): (super::NameHash, bool),
|
(hash, is_command): (super::NameHash, bool),
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let text = locale.send_master_pass_to_delete_account.as_ref();
|
|
||||||
|
|
||||||
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
|
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
|
||||||
let user_id = q.from.id.0;
|
let user_id = q.from.id.0;
|
||||||
|
|
||||||
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
||||||
bot.send_message(ids.0, locale.no_accounts_found.as_ref())
|
bot.send_message(ids.0, &locale.no_accounts_found)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
bot.answer_callback_query(q.id).await?;
|
bot.answer_callback_query(q.id).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let text: &str = &locale.send_master_pass_to_delete_account;
|
||||||
|
|
||||||
if is_command {
|
if is_command {
|
||||||
ids.alter_message(&bot, text, None, None).await?;
|
ids.alter_message(&bot, text, None, None).await?;
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,7 +9,7 @@ pub async fn delete_message(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
if let Some(msg) = q.message {
|
if let Some(msg) = q.message {
|
||||||
if bot.delete_message(msg.chat.id, msg.id).await.is_err() {
|
if bot.delete_message(msg.chat.id, msg.id).await.is_err() {
|
||||||
bot.send_message(msg.chat.id, locale.error_deleting_message.as_ref())
|
bot.send_message(msg.chat.id, &locale.error_deleting_message)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ pub async fn get(
|
|||||||
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
|
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
|
||||||
|
|
||||||
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
|
||||||
bot.send_message(ids.0, locale.account_not_found.as_ref())
|
bot.send_message(ids.0, &locale.account_not_found)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
bot.answer_callback_query(q.id).await?;
|
bot.answer_callback_query(q.id).await?;
|
||||||
|
@ -14,7 +14,7 @@ pub async fn get_menu(
|
|||||||
if markup.inline_keyboard.is_empty() {
|
if markup.inline_keyboard.is_empty() {
|
||||||
ids.alter_message(
|
ids.alter_message(
|
||||||
&bot,
|
&bot,
|
||||||
locale.no_accounts_found.as_ref(),
|
&locale.no_accounts_found,
|
||||||
deletion_markup(locale),
|
deletion_markup(locale),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -22,7 +22,7 @@ pub async fn get_menu(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
ids.alter_message(&bot, locale.choose_account.as_ref(), markup, None)
|
ids.alter_message(&bot, &locale.choose_account, markup, None)
|
||||||
.await?;
|
.await?;
|
||||||
bot.answer_callback_query(q.id).await?;
|
bot.answer_callback_query(q.id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -31,7 +31,7 @@ async fn get_master_pass(
|
|||||||
.await?;
|
.await?;
|
||||||
account.insert(&db).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?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||||||
/// Handles /cancel command when there's no active state
|
/// Handles /cancel command when there's no active state
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn cancel(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -6,7 +6,7 @@ pub async fn change_language(
|
|||||||
msg: Message,
|
msg: Message,
|
||||||
locale: LocaleRef,
|
locale: LocaleRef,
|
||||||
) -> crate::Result<()> {
|
) -> 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())
|
.reply_markup(language_markup())
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -12,13 +12,13 @@ pub async fn delete(
|
|||||||
let markup = menu_markup("delete1", user_id, &db).await?;
|
let markup = menu_markup("delete1", user_id, &db).await?;
|
||||||
|
|
||||||
if markup.inline_keyboard.is_empty() {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
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)
|
.reply_markup(markup)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -24,12 +24,12 @@ async fn get_master_pass(
|
|||||||
let text = match result {
|
let text = match result {
|
||||||
(Ok(()), Ok(())) => {
|
(Ok(()), Ok(())) => {
|
||||||
txn.commit().await?;
|
txn.commit().await?;
|
||||||
locale.everything_was_deleted.as_ref()
|
&locale.everything_was_deleted
|
||||||
}
|
}
|
||||||
(Err(err), _) | (_, Err(err)) => {
|
(Err(err), _) | (_, Err(err)) => {
|
||||||
error!("{}", crate::Error::from(err));
|
error!("{}", crate::Error::from(err));
|
||||||
txn.rollback().await?;
|
txn.rollback().await?;
|
||||||
locale.something_went_wrong.as_ref()
|
&locale.something_went_wrong
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ids.alter_message(&bot, text, deletion_markup(locale), None)
|
ids.alter_message(&bot, text, deletion_markup(locale), None)
|
||||||
|
@ -12,13 +12,13 @@ pub async fn get_account(
|
|||||||
let markup = menu_markup("decrypt", user_id, &db).await?;
|
let markup = menu_markup("decrypt", user_id, &db).await?;
|
||||||
|
|
||||||
if markup.inline_keyboard.is_empty() {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
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)
|
.reply_markup(markup)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -14,7 +14,7 @@ pub async fn get_accounts(
|
|||||||
let mut account_names = Account::get_names(user_id, &db);
|
let mut account_names = Account::get_names(user_id, &db);
|
||||||
|
|
||||||
let Some(mut text) = account_names.try_next().await? else {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||||||
/// Handles the help command by sending the passwords descryptions
|
/// Handles the help command by sending the passwords descryptions
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn help(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -55,7 +55,7 @@ async fn get_master_pass(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let text = if failed.is_empty() {
|
let text = if failed.is_empty() {
|
||||||
locale.success.as_ref().to_owned()
|
locale.success.to_owned()
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{}:\n{}",
|
"{}:\n{}",
|
||||||
|
@ -12,13 +12,13 @@ pub async fn menu(
|
|||||||
let markup = menu_markup("get", user_id, &db).await?;
|
let markup = menu_markup("get", user_id, &db).await?;
|
||||||
|
|
||||||
if markup.inline_keyboard.is_empty() {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
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)
|
.reply_markup(markup)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -22,7 +22,7 @@ async fn get_master_pass2(
|
|||||||
if !hash.verify(master_pass.as_bytes()) {
|
if !hash.verify(master_pass.as_bytes()) {
|
||||||
ids.alter_message(
|
ids.alter_message(
|
||||||
&bot,
|
&bot,
|
||||||
locale.master_password_dont_match.as_ref(),
|
&locale.master_password_dont_match,
|
||||||
deletion_markup(locale),
|
deletion_markup(locale),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
@ -43,7 +43,7 @@ async fn get_master_pass2(
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
model.insert(&db, locale_type).await?;
|
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?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -61,7 +61,7 @@ async fn get_master_pass(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let hash = spawn_blocking(move || HashedBytes::new(master_pass.as_bytes())).await?;
|
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?;
|
.await?;
|
||||||
|
|
||||||
change_state!(
|
change_state!(
|
||||||
@ -86,13 +86,13 @@ pub async fn set_master_pass(
|
|||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
if MasterPass::exists(user_id, &db).await? {
|
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))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let previous = bot
|
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?;
|
.await?;
|
||||||
|
|
||||||
change_state!(
|
change_state!(
|
||||||
|
@ -3,7 +3,6 @@ use crate::prelude::*;
|
|||||||
/// Handles /start command by sending the greeting message
|
/// Handles /start command by sending the greeting message
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn start(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
pub async fn start(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||||
bot.send_message(msg.chat.id, locale.start_command.as_ref())
|
bot.send_message(msg.chat.id, &locale.start_command).await?;
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use crate::prelude::*;
|
|||||||
/// Handles the messages which weren't matched by any commands or states
|
/// Handles the messages which weren't matched by any commands or states
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn default(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
pub async fn default(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||||
bot.send_message(msg.chat.id, locale.unknown_command_use_help.as_ref())
|
bot.send_message(msg.chat.id, &locale.unknown_command_use_help)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -15,7 +15,7 @@ async fn notify_about_no_user_info(
|
|||||||
state: State,
|
state: State,
|
||||||
locale: LocaleRef,
|
locale: LocaleRef,
|
||||||
) -> crate::Result<()> {
|
) -> crate::Result<()> {
|
||||||
let text = locale.couldnt_get_user_info_send_again.as_ref();
|
let text = &locale.couldnt_get_user_info_send_again;
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
State::Start => {
|
State::Start => {
|
||||||
|
151
src/locales.rs
151
src/locales.rs
@ -26,75 +26,92 @@ impl LocaleStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, derive_more::Display, derive_more::Deref)]
|
||||||
|
#[deref(forward)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct LocaleString(Box<str>);
|
||||||
|
|
||||||
|
impl LocaleString {
|
||||||
|
pub const fn as_str(&self) -> &str {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&LocaleString> for String {
|
||||||
|
fn from(value: &LocaleString) -> Self {
|
||||||
|
value.0.as_ref().to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
pub struct Locale {
|
pub struct Locale {
|
||||||
pub master_password_is_not_set: Box<str>,
|
pub master_password_is_not_set: LocaleString,
|
||||||
pub hide_button: Box<str>,
|
pub hide_button: LocaleString,
|
||||||
pub change_name_button: Box<str>,
|
pub change_name_button: LocaleString,
|
||||||
pub change_login_button: Box<str>,
|
pub change_login_button: LocaleString,
|
||||||
pub change_password_button: Box<str>,
|
pub change_password_button: LocaleString,
|
||||||
pub delete_account_button: Box<str>,
|
pub delete_account_button: LocaleString,
|
||||||
pub couldnt_get_user_info_send_again: Box<str>,
|
pub couldnt_get_user_info_send_again: LocaleString,
|
||||||
pub unknown_command_use_help: Box<str>,
|
pub unknown_command_use_help: LocaleString,
|
||||||
pub help_command: Box<str>,
|
pub help_command: LocaleString,
|
||||||
pub no_file_send: Box<str>,
|
pub no_file_send: LocaleString,
|
||||||
pub file_too_large: Box<str>,
|
pub file_too_large: LocaleString,
|
||||||
pub couldnt_get_file_name: Box<str>,
|
pub couldnt_get_file_name: LocaleString,
|
||||||
pub following_accounts_have_problems: Box<str>,
|
pub following_accounts_have_problems: LocaleString,
|
||||||
pub duplicate_names: Box<str>,
|
pub duplicate_names: LocaleString,
|
||||||
pub accounts_already_in_db: Box<str>,
|
pub accounts_already_in_db: LocaleString,
|
||||||
pub invalid_fields: Box<str>,
|
pub invalid_fields: LocaleString,
|
||||||
pub fix_that_and_send_again: Box<str>,
|
pub fix_that_and_send_again: LocaleString,
|
||||||
pub error_downloading_file: Box<str>,
|
pub error_downloading_file: LocaleString,
|
||||||
pub error_getting_account_names: Box<str>,
|
pub error_getting_account_names: LocaleString,
|
||||||
pub error_parsing_json_file: Box<str>,
|
pub error_parsing_json_file: LocaleString,
|
||||||
pub successfully_canceled: Box<str>,
|
pub successfully_canceled: LocaleString,
|
||||||
pub invalid_password: Box<str>,
|
pub invalid_password: LocaleString,
|
||||||
pub couldnt_get_message_text: Box<str>,
|
pub couldnt_get_message_text: LocaleString,
|
||||||
pub invalid_file_name: Box<str>,
|
pub invalid_file_name: LocaleString,
|
||||||
pub account_already_exists: Box<str>,
|
pub account_already_exists: LocaleString,
|
||||||
pub master_password_too_weak: Box<str>,
|
pub master_password_too_weak: LocaleString,
|
||||||
pub no_lowercase: Box<str>,
|
pub no_lowercase: LocaleString,
|
||||||
pub no_uppercase: Box<str>,
|
pub no_uppercase: LocaleString,
|
||||||
pub no_numbers: Box<str>,
|
pub no_numbers: LocaleString,
|
||||||
pub master_pass_too_short: Box<str>,
|
pub master_pass_too_short: LocaleString,
|
||||||
pub change_master_password_and_send_again: Box<str>,
|
pub change_master_password_and_send_again: LocaleString,
|
||||||
pub wrong_master_password: Box<str>,
|
pub wrong_master_password: LocaleString,
|
||||||
pub invalid_login: Box<str>,
|
pub invalid_login: LocaleString,
|
||||||
pub start_command: Box<str>,
|
pub start_command: LocaleString,
|
||||||
pub master_password_dont_match: Box<str>,
|
pub master_password_dont_match: LocaleString,
|
||||||
pub success: Box<str>,
|
pub success: LocaleString,
|
||||||
pub send_master_password_again: Box<str>,
|
pub send_master_password_again: LocaleString,
|
||||||
pub master_password_is_set: Box<str>,
|
pub master_password_is_set: LocaleString,
|
||||||
pub send_new_master_password: Box<str>,
|
pub send_new_master_password: LocaleString,
|
||||||
pub no_accounts_found: Box<str>,
|
pub no_accounts_found: LocaleString,
|
||||||
pub choose_account: Box<str>,
|
pub choose_account: LocaleString,
|
||||||
pub couldnt_create_following_accounts: Box<str>,
|
pub couldnt_create_following_accounts: LocaleString,
|
||||||
pub send_master_password: Box<str>,
|
pub send_master_password: LocaleString,
|
||||||
pub something_went_wrong: Box<str>,
|
pub something_went_wrong: LocaleString,
|
||||||
pub nothing_to_cancel: Box<str>,
|
pub nothing_to_cancel: LocaleString,
|
||||||
pub send_account_name: Box<str>,
|
pub send_account_name: LocaleString,
|
||||||
pub send_login: Box<str>,
|
pub send_login: LocaleString,
|
||||||
pub error_deleting_message: Box<str>,
|
pub error_deleting_message: LocaleString,
|
||||||
pub account_not_found: Box<str>,
|
pub account_not_found: LocaleString,
|
||||||
pub send_new_name: Box<str>,
|
pub send_new_name: LocaleString,
|
||||||
pub send_new_login: Box<str>,
|
pub send_new_login: LocaleString,
|
||||||
pub send_new_password: Box<str>,
|
pub send_new_password: LocaleString,
|
||||||
pub success_choose_account_to_view: Box<str>,
|
pub success_choose_account_to_view: LocaleString,
|
||||||
pub send_json_file: Box<str>,
|
pub send_json_file: LocaleString,
|
||||||
pub send_master_pass_to_delete_everything: Box<str>,
|
pub send_master_pass_to_delete_everything: LocaleString,
|
||||||
pub everything_was_deleted: Box<str>,
|
pub everything_was_deleted: LocaleString,
|
||||||
pub send_password: Box<str>,
|
pub send_password: LocaleString,
|
||||||
pub send_master_pass_to_delete_account: Box<str>,
|
pub send_master_pass_to_delete_account: LocaleString,
|
||||||
pub no_special_characters: Box<str>,
|
pub no_special_characters: LocaleString,
|
||||||
pub invalid_name: Box<str>,
|
pub invalid_name: LocaleString,
|
||||||
pub decrypt_button: Box<str>,
|
pub decrypt_button: LocaleString,
|
||||||
pub delete_message_button: Box<str>,
|
pub delete_message_button: LocaleString,
|
||||||
pub menu_button: Box<str>,
|
pub menu_button: LocaleString,
|
||||||
pub choose_language: Box<str>,
|
pub choose_language: LocaleString,
|
||||||
word_name: Box<str>,
|
word_name: LocaleString,
|
||||||
word_login: Box<str>,
|
word_login: LocaleString,
|
||||||
word_password: Box<str>,
|
word_password: LocaleString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Locale {
|
impl Locale {
|
||||||
|
@ -20,9 +20,7 @@ macro_rules! first_handler {
|
|||||||
dialogue: MainDialogue,
|
dialogue: MainDialogue,
|
||||||
locale: LocaleRef,
|
locale: LocaleRef,
|
||||||
) -> $crate::Result<()> {
|
) -> $crate::Result<()> {
|
||||||
let previous = bot
|
let previous = bot.send_message(msg.chat.id, &locale.$message).await?;
|
||||||
.send_message(msg.chat.id, locale.$message.as_ref())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
$crate::change_state!(dialogue, &previous, (), $next_state, $next_func);
|
$crate::change_state!(dialogue, &previous, (), $next_state, $next_func);
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ macro_rules! handler {
|
|||||||
locale: LocaleRef,
|
locale: LocaleRef,
|
||||||
$($param: $type),*
|
$($param: $type),*
|
||||||
) -> $crate::Result<()> {
|
) -> $crate::Result<()> {
|
||||||
ids.alter_message(&bot, locale.$message.as_ref(), None, None).await?;
|
ids.alter_message(&bot, &locale.$message, None, None).await?;
|
||||||
|
|
||||||
$crate::change_state!(dialogue, ids, ($($param),*), $next_state, $next_func);
|
$crate::change_state!(dialogue, ids, ($($param),*), $next_state, $next_func);
|
||||||
|
|
||||||
|
@ -57,23 +57,23 @@ pub fn account_markup(name: &str, is_encrypted: bool, locale: LocaleRef) -> Inli
|
|||||||
let hash = std::str::from_utf8(&hash).unwrap();
|
let hash = std::str::from_utf8(&hash).unwrap();
|
||||||
|
|
||||||
let encryption_button = if is_encrypted {
|
let encryption_button = if is_encrypted {
|
||||||
(locale.decrypt_button.as_ref(), "decrypt")
|
(&locale.decrypt_button, "decrypt")
|
||||||
} else {
|
} else {
|
||||||
(locale.hide_button.as_ref(), "get")
|
(&locale.hide_button, "get")
|
||||||
};
|
};
|
||||||
|
|
||||||
let main_buttons = [
|
let main_buttons = [
|
||||||
(locale.change_name_button.as_ref(), "an"),
|
(&locale.change_name_button, "an"),
|
||||||
(locale.change_login_button.as_ref(), "al"),
|
(&locale.change_login_button, "al"),
|
||||||
(locale.change_password_button.as_ref(), "ap"),
|
(&locale.change_password_button, "ap"),
|
||||||
(locale.delete_account_button.as_ref(), "delete0"),
|
(&locale.delete_account_button, "delete0"),
|
||||||
encryption_button,
|
encryption_button,
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(text, command)| make_button(text, command, hash))
|
.map(|(text, command)| make_button(text, command, hash))
|
||||||
.chunks(2);
|
.chunks(2);
|
||||||
|
|
||||||
let menu_button = InlineKeyboardButton::callback(locale.menu_button.as_ref(), "get_menu");
|
let menu_button = InlineKeyboardButton::callback(&locale.menu_button, "get_menu");
|
||||||
|
|
||||||
InlineKeyboardMarkup::new(&main_buttons).append_row([menu_button])
|
InlineKeyboardMarkup::new(&main_buttons).append_row([menu_button])
|
||||||
}
|
}
|
||||||
@ -91,7 +91,6 @@ pub fn language_markup() -> InlineKeyboardMarkup {
|
|||||||
/// This markup should be added for all messages that won't be deleted afterwards
|
/// This markup should be added for all messages that won't be deleted afterwards
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn deletion_markup(locale: LocaleRef) -> InlineKeyboardMarkup {
|
pub fn deletion_markup(locale: LocaleRef) -> InlineKeyboardMarkup {
|
||||||
let button =
|
let button = InlineKeyboardButton::callback(&locale.delete_message_button, "delete_message");
|
||||||
InlineKeyboardButton::callback(locale.delete_message_button.as_ref(), "delete_message");
|
|
||||||
InlineKeyboardMarkup::new([[button]])
|
InlineKeyboardMarkup::new([[button]])
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ async fn notify_about_no_master_pass(
|
|||||||
}
|
}
|
||||||
bot.send_message(
|
bot.send_message(
|
||||||
update.chat_id().unwrap(),
|
update.chat_id().unwrap(),
|
||||||
locale.master_password_is_not_set.as_ref(),
|
&locale.master_password_is_not_set,
|
||||||
)
|
)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -30,7 +30,7 @@ where
|
|||||||
let Some(text) = msg.text().map(str::trim) else {
|
let Some(text) = msg.text().map(str::trim) else {
|
||||||
handler
|
handler
|
||||||
.previous
|
.previous
|
||||||
.alter_message(&bot, locale.couldnt_get_message_text.as_ref(), None, None)
|
.alter_message(&bot, &locale.couldnt_get_message_text, None, None)
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
@ -41,7 +41,7 @@ where
|
|||||||
.previous
|
.previous
|
||||||
.alter_message(
|
.alter_message(
|
||||||
&bot,
|
&bot,
|
||||||
locale.successfully_canceled.as_ref(),
|
&locale.successfully_canceled,
|
||||||
deletion_markup(locale),
|
deletion_markup(locale),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ async fn check_login(
|
|||||||
) -> crate::Result<Option<String>> {
|
) -> crate::Result<Option<String>> {
|
||||||
let is_valid = validate_field(login);
|
let is_valid = validate_field(login);
|
||||||
if !is_valid {
|
if !is_valid {
|
||||||
return Ok(Some(locale.invalid_login.as_ref().into()));
|
return Ok(Some(locale.invalid_login.to_owned()));
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ async fn check_master_pass(
|
|||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
let Some(model) = MasterPass::get(user_id, db).await? else {
|
let Some(model) = MasterPass::get(user_id, db).await? else {
|
||||||
error!("User was put into the GetMasterPass state with no master password set");
|
error!("User was put into the GetMasterPass state with no master password set");
|
||||||
return Ok(Some(locale.master_password_is_not_set.as_ref().into()));
|
return Ok(Some(locale.master_password_is_not_set.to_owned()));
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_valid = {
|
let is_valid = {
|
||||||
@ -24,7 +24,7 @@ async fn check_master_pass(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if !is_valid {
|
if !is_valid {
|
||||||
return Ok(Some(locale.wrong_master_password.as_ref().into()));
|
return Ok(Some(locale.wrong_master_password.to_owned()));
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(),
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut error_text = locale.master_password_too_weak.as_ref().to_owned();
|
let mut error_text = locale.master_password_too_weak.to_owned();
|
||||||
|
|
||||||
if validity.contains(PasswordValidity::NO_LOWERCASE) {
|
if validity.contains(PasswordValidity::NO_LOWERCASE) {
|
||||||
write!(error_text, "\n* {}", locale.no_lowercase).unwrap();
|
write!(error_text, "\n* {}", locale.no_lowercase).unwrap();
|
||||||
|
@ -11,9 +11,9 @@ async fn check_new_account_name(
|
|||||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||||
|
|
||||||
if Account::exists(user_id, name, db).await? {
|
if Account::exists(user_id, name, db).await? {
|
||||||
Ok(Some(locale.account_already_exists.as_ref().into()))
|
Ok(Some(locale.account_already_exists.to_owned()))
|
||||||
} else if !validate_field(name) {
|
} else if !validate_field(name) {
|
||||||
Ok(Some(locale.invalid_name.as_ref().into()))
|
Ok(Some(locale.invalid_name.to_owned()))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ async fn check_password(
|
|||||||
) -> crate::Result<Option<String>> {
|
) -> crate::Result<Option<String>> {
|
||||||
let is_valid = validate_field(password);
|
let is_valid = validate_field(password);
|
||||||
if !is_valid {
|
if !is_valid {
|
||||||
return Ok(Some(locale.invalid_password.as_ref().into()));
|
return Ok(Some(locale.invalid_password.to_owned()));
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ enum InvalidDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl InvalidDocument {
|
impl InvalidDocument {
|
||||||
const fn into_str(self, locale: LocaleRef) -> &'static str {
|
fn into_str(self, locale: LocaleRef) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::NoFileSend => &locale.no_file_send,
|
Self::NoFileSend => &locale.no_file_send,
|
||||||
Self::FileTooLarge => &locale.file_too_large,
|
Self::FileTooLarge => &locale.file_too_large,
|
||||||
@ -102,7 +102,7 @@ fn process_accounts(
|
|||||||
return Ok(Ok(()));
|
return Ok(Ok(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut error_text = locale.following_accounts_have_problems.as_ref().to_owned();
|
let mut error_text = locale.following_accounts_have_problems.to_owned();
|
||||||
|
|
||||||
if !duplicates.is_empty() {
|
if !duplicates.is_empty() {
|
||||||
write!(
|
write!(
|
||||||
@ -162,11 +162,11 @@ async fn user_from_document(
|
|||||||
let file = &validate_document(document)
|
let file = &validate_document(document)
|
||||||
.map_err(|err| err.into_str(locale))?
|
.map_err(|err| err.into_str(locale))?
|
||||||
.file;
|
.file;
|
||||||
let data = download_file(bot, file).map_err(|_| locale.error_downloading_file.as_ref());
|
let data = download_file(bot, file).map_err(|_| locale.error_downloading_file.as_str());
|
||||||
|
|
||||||
let existing_names = Account::get_names(user_id, db)
|
let existing_names = Account::get_names(user_id, db)
|
||||||
.try_collect()
|
.try_collect()
|
||||||
.map_err(|_| locale.error_getting_account_names.as_ref());
|
.map_err(|_| locale.error_getting_account_names.as_str());
|
||||||
|
|
||||||
try_join!(data, existing_names)?
|
try_join!(data, existing_names)?
|
||||||
};
|
};
|
||||||
@ -201,7 +201,7 @@ pub async fn get_user(
|
|||||||
.previous
|
.previous
|
||||||
.alter_message(
|
.alter_message(
|
||||||
&bot,
|
&bot,
|
||||||
locale.successfully_canceled.as_ref(),
|
&locale.successfully_canceled,
|
||||||
deletion_markup(locale),
|
deletion_markup(locale),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use futures::{future::BoxFuture, TryFutureExt};
|
use futures::future::BoxFuture;
|
||||||
use std::{mem, sync::Arc};
|
use std::{mem, sync::Arc};
|
||||||
use teloxide::{
|
use teloxide::{
|
||||||
|
errors::{ApiError, RequestError},
|
||||||
requests::HasPayload,
|
requests::HasPayload,
|
||||||
types::{InlineKeyboardMarkup, MessageId, ParseMode},
|
types::{InlineKeyboardMarkup, MessageId, ParseMode},
|
||||||
RequestError,
|
|
||||||
};
|
};
|
||||||
use tokio::{sync::Mutex, try_join};
|
use tokio::{join, sync::Mutex};
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct MessageIds(pub ChatId, pub MessageId);
|
pub struct MessageIds(pub ChatId, pub MessageId);
|
||||||
@ -14,10 +14,10 @@ pub struct MessageIds(pub ChatId, pub MessageId);
|
|||||||
impl MessageIds {
|
impl MessageIds {
|
||||||
// Tries to delete the message while ignoring API errors
|
// Tries to delete the message while ignoring API errors
|
||||||
#[inline]
|
#[inline]
|
||||||
pub async fn delete(self, bot: &Throttle<Bot>) -> crate::Result<()> {
|
pub async fn delete(self, bot: &Throttle<Bot>) -> Result<(), RequestError> {
|
||||||
match bot.delete_message(self.0, self.1).await {
|
match bot.delete_message(self.0, self.1).await {
|
||||||
Ok(_) | Err(RequestError::Api(_)) => Ok(()),
|
Ok(_) | Err(RequestError::Api(_)) => Ok(()),
|
||||||
Err(err) => Err(err.into()),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,27 +29,27 @@ impl MessageIds {
|
|||||||
text: impl Into<String> + Send,
|
text: impl Into<String> + Send,
|
||||||
markup: impl Into<Option<InlineKeyboardMarkup>> + Send,
|
markup: impl Into<Option<InlineKeyboardMarkup>> + Send,
|
||||||
parse_mode: impl Into<Option<ParseMode>> + Send,
|
parse_mode: impl Into<Option<ParseMode>> + Send,
|
||||||
) -> crate::Result<()> {
|
) -> Result<(), RequestError> {
|
||||||
let mut edit = bot.edit_message_text(self.0, self.1, text);
|
let mut edit_request = bot.edit_message_text(self.0, self.1, text);
|
||||||
edit.parse_mode = parse_mode.into();
|
edit_request.parse_mode = parse_mode.into();
|
||||||
edit.reply_markup = markup.into();
|
edit_request.reply_markup = markup.into();
|
||||||
|
|
||||||
match edit.send_ref().await {
|
match edit_request.send_ref().await {
|
||||||
Ok(_) => return Ok(()),
|
Ok(_) | Err(RequestError::Api(ApiError::MessageNotModified)) => return Ok(()),
|
||||||
Err(RequestError::Api(_)) => (),
|
Err(RequestError::Api(_)) => (),
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err),
|
||||||
};
|
};
|
||||||
|
|
||||||
let send = {
|
let mut send_request = bot.send_message(self.0, mem::take(&mut edit_request.text));
|
||||||
let mut send_request = bot.send_message(self.0, mem::take(&mut edit.text));
|
let payload = send_request.payload_mut();
|
||||||
let payload = send_request.payload_mut();
|
payload.parse_mode = edit_request.parse_mode;
|
||||||
payload.parse_mode = edit.parse_mode;
|
payload.reply_markup = edit_request.reply_markup.take().map(Into::into);
|
||||||
payload.reply_markup = edit.reply_markup.take().map(Into::into);
|
|
||||||
send_request.send().map_err(Into::into)
|
|
||||||
};
|
|
||||||
|
|
||||||
let msg = try_join!(self.delete(bot), send)?.1;
|
let result = join!(self.delete(bot), send_request.send());
|
||||||
*self = Self::from(&msg);
|
if let Err(err) = result.0 {
|
||||||
|
log::error!("{err}");
|
||||||
|
}
|
||||||
|
*self = Self::from(&result.1?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user