diff --git a/src/callbacks.rs b/src/callbacks.rs index ddc9168..e884207 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -11,11 +11,11 @@ crate::export_handlers!( ); use crate::{ - entity::locale::LocaleType, errors::handle_error, errors::InvalidCommand, + entity::locale::LocaleType, + errors::{handle_error, InvalidCommand}, locales::LocaleTypeExt, }; use base64::{engine::general_purpose::STANDARD_NO_PAD as B64_ENGINE, Engine as _}; -use std::str::FromStr; use teloxide::types::CallbackQuery; type NameHash = Vec; @@ -46,7 +46,7 @@ impl CallbackCommand { } } -impl FromStr for CallbackCommand { +impl std::str::FromStr for CallbackCommand { type Err = crate::errors::InvalidCommand; fn from_str(s: &str) -> Result { diff --git a/src/callbacks/alter.rs b/src/callbacks/alter.rs index 9bd78d2..bb034ef 100644 --- a/src/callbacks/alter.rs +++ b/src/callbacks/alter.rs @@ -1,6 +1,5 @@ use super::AlterableField::{self, Login, Name, Pass}; -use crate::{change_state, prelude::*}; -use cryptography::account::Cipher; +use crate::{change_state, cryptography::account::Cipher, prelude::*}; use tokio::task::spawn_blocking; #[inline] diff --git a/src/callbacks/change_locale.rs b/src/callbacks/change_locale.rs index 1e023de..45399c4 100644 --- a/src/callbacks/change_locale.rs +++ b/src/callbacks/change_locale.rs @@ -1,5 +1,6 @@ -use crate::{locales::LocaleTypeExt, prelude::*}; -use entity::locale::LocaleType; +use crate::{ + entity::locale::LocaleType, locales::LocaleTypeExt, markups::language_markup, prelude::*, +}; #[inline] pub async fn change_locale( diff --git a/src/callbacks/decrypt.rs b/src/callbacks/decrypt.rs index 7611730..f1aa7b5 100644 --- a/src/callbacks/decrypt.rs +++ b/src/callbacks/decrypt.rs @@ -1,4 +1,4 @@ -use crate::{change_state, prelude::*}; +use crate::{change_state, markups::account_markup, prelude::*}; use teloxide::types::ParseMode; use tokio::task::spawn_blocking; diff --git a/src/callbacks/get.rs b/src/callbacks/get.rs index 874baf9..8521bc1 100644 --- a/src/callbacks/get.rs +++ b/src/callbacks/get.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{markups::account_markup, prelude::*}; use teloxide::types::ParseMode; #[inline] diff --git a/src/commands/change_language.rs b/src/commands/change_language.rs index 2aecc09..7d3aea1 100644 --- a/src/commands/change_language.rs +++ b/src/commands/change_language.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{markups::language_markup, prelude::*}; #[inline] pub async fn change_language( diff --git a/src/commands/export.rs b/src/commands/export.rs index 754a8e1..eca1b0b 100644 --- a/src/commands/export.rs +++ b/src/commands/export.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{models::User, prelude::*}; use parking_lot::Mutex; use std::sync::Arc; use teloxide::types::InputFile; @@ -46,9 +46,11 @@ async fn get_master_pass( .await?; } - accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name)); - - let json = spawn_blocking(move || serde_json::to_vec_pretty(&User { accounts })).await??; + let json = spawn_blocking(move || { + accounts.sort_unstable_by(|this, other| this.name.cmp(&other.name)); + serde_json::to_vec_pretty(&User { accounts }) + }) + .await??; let file = InputFile::memory(json).file_name("accounts.json"); bot.send_document(msg.chat.id, file) diff --git a/src/commands/gen_password.rs b/src/commands/gen_password.rs index 68d81fc..6cfcf9e 100644 --- a/src/commands/gen_password.rs +++ b/src/commands/gen_password.rs @@ -1,6 +1,5 @@ -use crate::prelude::*; +use crate::{cryptography::passwords::generate_passwords, prelude::*}; use arrayvec::ArrayString; -use cryptography::passwords::generate_passwords; use std::fmt::Write; use teloxide::types::ParseMode; use tokio::task::spawn_blocking; diff --git a/src/commands/import.rs b/src/commands/import.rs index 0463dd9..24d71fe 100644 --- a/src/commands/import.rs +++ b/src/commands/import.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{models::User, prelude::*}; use futures::stream; use itertools::Itertools; use parking_lot::Mutex; diff --git a/src/commands/set_master_pass.rs b/src/commands/set_master_pass.rs index b743f9c..2ed659c 100644 --- a/src/commands/set_master_pass.rs +++ b/src/commands/set_master_pass.rs @@ -1,6 +1,7 @@ -use crate::{change_state, locales::LocaleTypeExt, prelude::*}; -use cryptography::hashing::HashedBytes; -use entity::locale::LocaleType; +use crate::{ + change_state, cryptography::hashing::HashedBytes, entity::locale::LocaleType, + locales::LocaleTypeExt, prelude::*, +}; use tokio::task::spawn_blocking; #[inline] diff --git a/src/cryptography/account.rs b/src/cryptography/account.rs index d9366ff..f6908e6 100644 --- a/src/cryptography/account.rs +++ b/src/cryptography/account.rs @@ -22,7 +22,6 @@ impl Cipher { /// Encrypts the value with the current cipher. The 12 byte nonce is appended to the result #[inline] - #[allow(clippy::missing_panics_doc)] pub fn encrypt(&self, value: &mut Vec) { let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng); self.chacha.encrypt_in_place(&nonce, b"", value).unwrap(); diff --git a/src/dispatching/delete_mesage_handler.rs b/src/dispatching/delete_mesage_handler.rs index 466db04..9138179 100644 --- a/src/dispatching/delete_mesage_handler.rs +++ b/src/dispatching/delete_mesage_handler.rs @@ -1,7 +1,10 @@ use crate::prelude::*; -/// Deletes the message ignoring the errors +/// Deletes the message without returining errors #[inline] pub async fn delete_message(bot: Throttle, msg: Message) { - let _ = bot.delete_message(msg.chat.id, msg.id).await; + let ids = MessageIds::from(&msg); + if let Err(err) = ids.delete(&bot).await { + handle_error(err); + } } diff --git a/src/entity.rs b/src/entity.rs index 1807b6a..f2ec6fc 100644 --- a/src/entity.rs +++ b/src/entity.rs @@ -1,5 +1,4 @@ // This is fine, because all errors can only be caused by the database errors and the docs would get repetative very quickly -#![allow(clippy::missing_errors_doc)] pub mod account; pub mod locale; diff --git a/src/errors.rs b/src/errors.rs index 02ba9ef..a813c10 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -29,6 +29,9 @@ pub fn init_logger() { .init(); } +/// Handles an error. +/// This function must be as cheap and generic as possible and must remain sync. +/// If expensive or long action is required, a task should be spawned but not joined. #[inline] pub fn handle_error(error: T) where diff --git a/src/locales.rs b/src/locales.rs index e3b1653..bed6ebc 100644 --- a/src/locales.rs +++ b/src/locales.rs @@ -1,7 +1,5 @@ -use crate::prelude::*; -use entity::locale::LocaleType; -use std::future::Future; -use std::sync::OnceLock; +use crate::{entity::locale::LocaleType, prelude::*}; +use std::{future::Future, sync::OnceLock}; static LOCALES: OnceLock = OnceLock::new(); diff --git a/src/prelude.rs b/src/prelude.rs index 8f611c9..abf3807 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,14 +1,11 @@ -pub(crate) use crate::cryptography::{ - self, account::Decrypted as DecryptedAccount, validate_field, -}; -pub(crate) use crate::entity::{self, account::Account, master_pass::MasterPass, Pool}; -pub(crate) use crate::{ +pub use crate::{ + cryptography::{account::Decrypted as DecryptedAccount, validate_field}, + entity::{account::Account, master_pass::MasterPass, Pool}, errors::{handle_error, NoUserInfo}, first_handler, handler, locales::LocaleRef, - markups::*, - models::*, + markups::{deletion_markup, menu_markup}, state::{Handler, MainDialogue, MessageIds, PackagedHandler, State}, }; -pub(crate) use futures::{StreamExt, TryStreamExt}; -pub(crate) use teloxide::{adaptors::Throttle, prelude::*}; +pub use futures::{StreamExt as _, TryStreamExt as _}; +pub use teloxide::{adaptors::Throttle, prelude::*}; diff --git a/src/state.rs b/src/state.rs index fc19466..119b7de 100644 --- a/src/state.rs +++ b/src/state.rs @@ -26,7 +26,7 @@ pub enum State { GetNewMasterPass(PackagedHandler), GetLogin(PackagedHandler), GetPassword(PackagedHandler), - GetUser(PackagedHandler), + GetUser(PackagedHandler), } pub type MainDialogue = Dialogue>; diff --git a/src/state/get_master_pass.rs b/src/state/get_master_pass.rs index a90bdb9..b9b89e4 100644 --- a/src/state/get_master_pass.rs +++ b/src/state/get_master_pass.rs @@ -1,5 +1,4 @@ -use crate::prelude::*; -use cryptography::hashing::HashedBytes; +use crate::{cryptography::hashing::HashedBytes, prelude::*}; use tokio::task::spawn_blocking; /// Returns true if the provided master password is valid diff --git a/src/state/get_new_master_pass.rs b/src/state/get_new_master_pass.rs index 851a10b..8104e13 100644 --- a/src/state/get_new_master_pass.rs +++ b/src/state/get_new_master_pass.rs @@ -1,5 +1,7 @@ -use crate::prelude::*; -use cryptography::passwords::{check_master_pass, PasswordValidity}; +use crate::{ + cryptography::passwords::{check_master_pass, PasswordValidity}, + prelude::*, +}; use std::fmt::Write as _; #[inline] diff --git a/src/state/get_user.rs b/src/state/get_user.rs index 1884e1d..f3d04ff 100644 --- a/src/state/get_user.rs +++ b/src/state/get_user.rs @@ -1,4 +1,4 @@ -use crate::{errors::HandlerUsed, prelude::*}; +use crate::{errors::HandlerUsed, models::User, prelude::*}; use futures::TryFutureExt; use itertools::Itertools; use std::{borrow::Cow, fmt::Write, path::Path};