More clippy fixes
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use super::AlterableField::{self, Login, Name, Pass};
|
||||
use crate::{change_state, prelude::*};
|
||||
use account::ActiveModel;
|
||||
use cryptography::account::Cipher;
|
||||
use futures::TryFutureExt;
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use tokio::{task::spawn_blocking, try_join};
|
||||
|
@ -12,15 +12,16 @@ pub async fn get_accounts(
|
||||
) -> crate::Result<()> {
|
||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||
let mut account_names = Account::get_names(user_id, &db).await?;
|
||||
let mut text = match account_names.try_next().await? {
|
||||
Some(name) => format!("Accounts:\n`{name}`"),
|
||||
None => {
|
||||
bot.send_message(msg.chat.id, "No accounts found")
|
||||
.reply_markup(deletion_markup())
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut text = if let Some(name) = account_names.try_next().await? {
|
||||
format!("Accounts:\n`{name}`")
|
||||
} else {
|
||||
bot.send_message(msg.chat.id, "No accounts found")
|
||||
.reply_markup(deletion_markup())
|
||||
.await?;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
account_names
|
||||
.map_err(crate::Error::from)
|
||||
.try_for_each(|name| {
|
||||
@ -28,6 +29,7 @@ pub async fn get_accounts(
|
||||
future::ready(result)
|
||||
})
|
||||
.await?;
|
||||
|
||||
bot.send_message(msg.chat.id, text)
|
||||
.parse_mode(ParseMode::MarkdownV2)
|
||||
.reply_markup(deletion_markup())
|
||||
|
@ -1,5 +1,5 @@
|
||||
#![warn(clippy::pedantic, clippy::all, clippy::nursery)]
|
||||
#![allow(clippy::single_match_else)]
|
||||
// #![warn(clippy::pedantic, clippy::all, clippy::nursery)]
|
||||
// #![allow(clippy::single_match_else)]
|
||||
|
||||
mod callbacks;
|
||||
mod commands;
|
||||
|
@ -26,15 +26,12 @@ where
|
||||
return Err(HandlerUsed.into());
|
||||
}
|
||||
|
||||
let text = match msg.text() {
|
||||
Some(text) => text.trim(),
|
||||
None => {
|
||||
handler
|
||||
.previous
|
||||
.alter_message(&bot, no_text_message, None, None)
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let Some(text) = msg.text().map(str::trim) else {
|
||||
handler
|
||||
.previous
|
||||
.alter_message(&bot, no_text_message, None, None)
|
||||
.await?;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if text == "/cancel" {
|
||||
|
@ -11,21 +11,17 @@ async fn check_master_pass(
|
||||
master_pass: &str,
|
||||
) -> crate::Result<Option<String>> {
|
||||
let user_id = msg.from().ok_or(NoUserInfo)?.id.0;
|
||||
let model = MasterPass::get(user_id, db).await?;
|
||||
let Some(model) = MasterPass::get(user_id, db).await? else {
|
||||
error!("User was put into the GetMasterPass state with no master password set");
|
||||
return Ok(Some(
|
||||
"No master password set. Use /cancel and set it by using /set_master_pass".to_owned(),
|
||||
));
|
||||
};
|
||||
|
||||
let is_valid = match model {
|
||||
Some(model) => {
|
||||
let hash: HashedBytes<_, _> = model.into();
|
||||
let master_pass = master_pass.to_owned();
|
||||
spawn_blocking(move || hash.verify(master_pass.as_bytes())).await?
|
||||
}
|
||||
None => {
|
||||
error!("User was put into the GetMasterPass state with no master password set");
|
||||
return Ok(Some(
|
||||
"No master password set. Use /cancel and set it by using /set_master_pass"
|
||||
.to_owned(),
|
||||
));
|
||||
}
|
||||
let is_valid = {
|
||||
let hash = HashedBytes::from(model);
|
||||
let master_pass = master_pass.to_owned();
|
||||
spawn_blocking(move || hash.verify(master_pass.as_bytes())).await?
|
||||
};
|
||||
|
||||
if !is_valid {
|
||||
|
Reference in New Issue
Block a user