From 6ae745fcd4617dfd03cd7e02c96e605d241ee7b3 Mon Sep 17 00:00:00 2001 From: StNicolay Date: Thu, 16 Nov 2023 21:51:46 +0300 Subject: [PATCH] Enabled clippy warnings and fixed them --- Cargo.lock | 8 +++---- cryptography/src/passwords.rs | 2 +- src/callbacks.rs | 33 +++++++++++++------------ src/callbacks/alter.rs | 25 +++++++++---------- src/callbacks/decrypt.rs | 32 ++++++++++--------------- src/callbacks/delete.rs | 23 ++++++++---------- src/callbacks/get.rs | 19 +++++++-------- src/commands/gen_password.rs | 2 +- src/commands/get_accounts.rs | 2 +- src/commands/set_master_pass.rs | 2 +- src/filter_user_info.rs | 17 ++++++------- src/main.rs | 7 ++++-- src/markups.rs | 2 +- src/master_password_check.rs | 41 ++++++++------------------------ src/models.rs | 4 ++-- src/prelude.rs | 15 ++++++------ src/state.rs | 2 +- src/state/generic.rs | 15 ++++++------ src/state/get_new_master_pass.rs | 10 ++++---- src/state/get_user.rs | 21 ++++++++-------- src/state/handler.rs | 10 ++++---- 21 files changed, 129 insertions(+), 163 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8a6848..ad89314 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1909,9 +1909,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.8" +version = "0.21.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c" +checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9" dependencies = [ "log", "ring", @@ -3336,6 +3336,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12a3946ecfc929b583800f4629b6c25b88ac6e92a40ea5670f77112a85d40a8b" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/cryptography/src/passwords.rs b/cryptography/src/passwords.rs index ada5ce7..54e0cb3 100644 --- a/cryptography/src/passwords.rs +++ b/cryptography/src/passwords.rs @@ -12,7 +12,7 @@ bitflags::bitflags! { const SPECIAL_CHARACTER = 0b1000; } - #[derive(PartialEq, Eq)] + #[derive(PartialEq, Eq, Clone, Copy)] pub struct PasswordValidity: u8 { const NO_LOWERCASE = 0b00001; const NO_UPPERCASE = 0b00010; diff --git a/src/callbacks.rs b/src/callbacks.rs index 5f5c292..1fc8888 100644 --- a/src/callbacks.rs +++ b/src/callbacks.rs @@ -9,7 +9,7 @@ use teloxide::types::CallbackQuery; type NameHash = Vec; -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum AlterableField { Name, Login, @@ -38,37 +38,36 @@ impl FromStr for CallbackCommand { type Err = crate::errors::InvalidCommand; fn from_str(s: &str) -> Result { - use AlterableField::*; - use CallbackCommand::*; - match s { - "delete_message" => return Ok(DeleteMessage), - "get_menu" => return Ok(GetMenu), + "delete_message" => return Ok(Self::DeleteMessage), + "get_menu" => return Ok(Self::GetMenu), _ => (), }; let mut substrings = s.split(' '); - let (command, name) = match (substrings.next(), substrings.next(), substrings.next()) { - (Some(command), Some(name), None) => (command, name), - _ => return Err(InvalidCommand::InvalidParams), + let (Some(command), Some(name), None) = + (substrings.next(), substrings.next(), substrings.next()) + else { + return Err(InvalidCommand::InvalidParams); }; + let name_hash = B64_ENGINE.decode(name)?; if name_hash.len() != 32 { return Err(InvalidCommand::InvalidOutputLength); } match command { - "get" => Ok(Get(name_hash)), - "decrypt" => Ok(Decrypt(name_hash)), - "hide" => Ok(Hide(name_hash)), - "an" => Ok(Alter(name_hash, Name)), - "al" => Ok(Alter(name_hash, Login)), - "ap" => Ok(Alter(name_hash, Pass)), - "delete0" => Ok(DeleteAccount { + "get" => Ok(Self::Get(name_hash)), + "decrypt" => Ok(Self::Decrypt(name_hash)), + "hide" => Ok(Self::Hide(name_hash)), + "an" => Ok(Self::Alter(name_hash, AlterableField::Name)), + "al" => Ok(Self::Alter(name_hash, AlterableField::Login)), + "ap" => Ok(Self::Alter(name_hash, AlterableField::Pass)), + "delete0" => Ok(Self::DeleteAccount { name: name_hash, is_command: false, }), - "delete1" => Ok(DeleteAccount { + "delete1" => Ok(Self::DeleteAccount { name: name_hash, is_command: true, }), diff --git a/src/callbacks/alter.rs b/src/callbacks/alter.rs index 46cad24..1bc8330 100644 --- a/src/callbacks/alter.rs +++ b/src/callbacks/alter.rs @@ -1,4 +1,4 @@ -use super::AlterableField::{self, *}; +use super::AlterableField::{self, Login, Name, Pass}; use crate::{change_state, prelude::*}; use account::ActiveModel; use futures::TryFutureExt; @@ -14,7 +14,7 @@ async fn update_account( field_value: String, master_pass: String, ) -> crate::Result<()> { - if let Name = field { + if field == Name { Account::update_name(user_id, name, field_value, db).await?; return Ok(()); @@ -37,7 +37,7 @@ async fn update_account( match field { Login => model.enc_login = Set(field_value), Pass => model.enc_password = Set(field_value), - _ => unreachable!(), + Name => unreachable!(), } model.update(db).await?; @@ -87,18 +87,15 @@ pub async fn alter( let user_id = q.from.id.0; let mut ids: MessageIds = q.message.as_ref().unwrap().into(); - let name = match name_from_hash(&db, user_id, &hash).await? { - Some(name) => name, - None => { - try_join!( - bot.send_message(ids.0, "Account wasn't found") - .reply_markup(deletion_markup()) - .send(), - bot.answer_callback_query(q.id).send() - )?; + let Some(name) = name_from_hash(&db, user_id, &hash).await? else { + try_join!( + bot.send_message(ids.0, "Account wasn't found") + .reply_markup(deletion_markup()) + .send(), + bot.answer_callback_query(q.id).send() + )?; - return Ok(()); - } + return Ok(()); }; let text = match field { diff --git a/src/callbacks/decrypt.rs b/src/callbacks/decrypt.rs index f4f153d..16c213e 100644 --- a/src/callbacks/decrypt.rs +++ b/src/callbacks/decrypt.rs @@ -16,14 +16,11 @@ async fn get_master_pass( let user_id = msg.from().ok_or(NoUserInfo)?.id.0; - let account = match Account::get(user_id, &name, &db).await? { - Some(account) => account, - None => { - bot.send_message(msg.chat.id, "Account not found") - .reply_markup(deletion_markup()) - .await?; - return Ok(()); - } + let Some(account) = Account::get(user_id, &name, &db).await? else { + bot.send_message(msg.chat.id, "Account not found") + .reply_markup(deletion_markup()) + .await?; + return Ok(()); }; let (login, password) = spawn_blocking(move || account.decrypt(&master_pass)).await??; @@ -50,18 +47,15 @@ pub async fn decrypt( let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let user_id = q.from.id.0; - let name = match name_from_hash(&db, user_id, &hash).await? { - Some(name) => name, - None => { - try_join!( - bot.send_message(ids.0, "Account wasn't found") - .reply_markup(deletion_markup()) - .send(), - bot.answer_callback_query(q.id).send() - )?; + let Some(name) = name_from_hash(&db, user_id, &hash).await? else { + try_join!( + bot.send_message(ids.0, "Account wasn't found") + .reply_markup(deletion_markup()) + .send(), + bot.answer_callback_query(q.id).send() + )?; - return Ok(()); - } + return Ok(()); }; ids.alter_message(&bot, "Send master password", None, None) diff --git a/src/callbacks/delete.rs b/src/callbacks/delete.rs index c09c3e8..bf4ccd0 100644 --- a/src/callbacks/delete.rs +++ b/src/callbacks/delete.rs @@ -40,18 +40,15 @@ pub async fn delete( let mut ids: MessageIds = q.message.as_ref().unwrap().into(); let user_id = q.from.id.0; - let name = match name_from_hash(&db, user_id, &hash).await? { - Some(name) => name, - None => { - try_join!( - bot.send_message(ids.0, "Account wasn't found") - .reply_markup(deletion_markup()) - .send(), - bot.answer_callback_query(q.id).send() - )?; + let Some(name) = name_from_hash(&db, user_id, &hash).await? else { + try_join!( + bot.send_message(ids.0, "Account wasn't found") + .reply_markup(deletion_markup()) + .send(), + bot.answer_callback_query(q.id).send() + )?; - return Ok(()); - } + return Ok(()); }; let response = async { @@ -59,10 +56,10 @@ pub async fn delete( Once you send the master password the account is unrecoverable"; if is_command { - ids.alter_message(&bot, TEXT, None, None).await? + ids.alter_message(&bot, TEXT, None, None).await?; } else { let msg = bot.send_message(ids.0, TEXT).await?; - ids = MessageIds::from(&msg) + ids = MessageIds::from(&msg); }; Ok::<_, crate::Error>(()) diff --git a/src/callbacks/get.rs b/src/callbacks/get.rs index b6d8ddc..560a432 100644 --- a/src/callbacks/get.rs +++ b/src/callbacks/get.rs @@ -12,17 +12,14 @@ pub async fn get( let user_id = q.from.id.0; let mut ids: MessageIds = q.message.as_ref().unwrap().into(); - let name = match name_from_hash(&db, user_id, &hash).await? { - Some(name) => name, - None => { - try_join!( - bot.send_message(ids.0, "Account wasn't found") - .reply_markup(deletion_markup()) - .send(), - bot.answer_callback_query(q.id).send() - )?; - return Ok(()); - } + let Some(name) = name_from_hash(&db, user_id, &hash).await? else { + try_join!( + bot.send_message(ids.0, "Account wasn't found") + .reply_markup(deletion_markup()) + .send(), + bot.answer_callback_query(q.id).send() + )?; + return Ok(()); }; let text = format!("Name:\n`{name}`\nLogin:\n\\*\\*\\*\nPassword:\n\\*\\*\\*"); diff --git a/src/commands/gen_password.rs b/src/commands/gen_password.rs index c045268..104c885 100644 --- a/src/commands/gen_password.rs +++ b/src/commands/gen_password.rs @@ -13,7 +13,7 @@ type PasswordArray = [ArrayString; AMOUNT_OF_PASSWORDS]; const BUFFER_LENGTH: usize = MESSAGE_HEADER.len() + (PASSWORD_LENGTH + PASSWORD_PADDING_LENGTH) * AMOUNT_OF_PASSWORDS; -/// Handles /gen_password command by generating 10 copyable passwords and sending them to the user +/// Handles /`gen_password` command by generating 10 copyable passwords and sending them to the user #[inline] pub async fn gen_password(bot: Throttle, msg: Message) -> crate::Result<()> { let mut message: ArrayString = MESSAGE_HEADER.try_into().unwrap(); diff --git a/src/commands/get_accounts.rs b/src/commands/get_accounts.rs index ed899be..436d8eb 100644 --- a/src/commands/get_accounts.rs +++ b/src/commands/get_accounts.rs @@ -3,7 +3,7 @@ use futures::future; use std::fmt::Write; use teloxide::types::ParseMode; -/// Handles /get_accounts command by sending the list of copyable account names to the user +/// Handles /`get_accounts` command by sending the list of copyable account names to the user #[inline] pub async fn get_accounts( bot: Throttle, diff --git a/src/commands/set_master_pass.rs b/src/commands/set_master_pass.rs index d8150ab..85ab954 100644 --- a/src/commands/set_master_pass.rs +++ b/src/commands/set_master_pass.rs @@ -66,7 +66,7 @@ async fn get_master_pass( Ok(()) } -/// Handles /set_master_pass command +/// Handles /`set_master_pass` command #[inline] pub async fn set_master_pass( bot: Throttle, diff --git a/src/filter_user_info.rs b/src/filter_user_info.rs index d4e15a1..c30ea80 100644 --- a/src/filter_user_info.rs +++ b/src/filter_user_info.rs @@ -2,37 +2,38 @@ use crate::prelude::*; use teloxide::{dispatching::DpHandlerDescription, dptree::Handler}; #[inline] +#[allow(clippy::needless_pass_by_value)] fn has_no_user_info(msg: Message) -> bool { msg.from().is_none() } #[inline] +#[allow(clippy::significant_drop_tightening)] async fn notify_about_no_user_info( bot: Throttle, msg: Message, state: State, ) -> crate::Result<()> { - use State::*; const TEXT: &str = "Invalid message. Couldn't get the user information. Send the message again"; match state { - Start => { + State::Start => { bot.send_message(msg.chat.id, TEXT) .reply_markup(deletion_markup()) .await?; } - GetNewName(handler) - | GetMasterPass(handler) - | GetNewMasterPass(handler) - | GetLogin(handler) - | GetPassword(handler) => { + State::GetNewName(handler) + | State::GetMasterPass(handler) + | State::GetNewMasterPass(handler) + | State::GetLogin(handler) + | State::GetPassword(handler) => { let mut handler = handler.lock().await; handler .previous .alter_message(&bot, TEXT, None, None) .await?; } - GetUser(handler) => { + State::GetUser(handler) => { let mut handler = handler.lock().await; handler .previous diff --git a/src/main.rs b/src/main.rs index 1eaaeb4..68439ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#![warn(clippy::pedantic, clippy::all, clippy::nursery)] +#![allow(clippy::single_match_else)] + mod callbacks; mod commands; mod default; @@ -36,7 +39,7 @@ fn get_dispatcher( .branch(case![Command::GenPassword].endpoint(commands::gen_password)) .branch(case![Command::Cancel].endpoint(commands::cancel)) // This branch filters out the users that don't have a master password set - .branch(master_password_check::get_handler::()) + .branch(master_password_check::get_handler()) .branch(case![Command::Menu].endpoint(commands::menu)) .branch(case![Command::AddAccount].endpoint(commands::add_account)) .branch(case![Command::GetAccount].endpoint(commands::get_account)) @@ -62,7 +65,7 @@ fn get_dispatcher( let callback_handler = Update::filter_callback_query() .filter_map(CallbackCommand::from_query) .branch(case![CallbackCommand::DeleteMessage].endpoint(callbacks::delete_message)) - .branch(master_password_check::get_handler::()) + .branch(master_password_check::get_handler()) .branch(case![CallbackCommand::GetMenu].endpoint(callbacks::get_menu)) .branch(case![CallbackCommand::Get(hash)].endpoint(callbacks::get)) .branch(case![CallbackCommand::Decrypt(hash)].endpoint(callbacks::decrypt)) diff --git a/src/markups.rs b/src/markups.rs index 3aa193a..f2aa501 100644 --- a/src/markups.rs +++ b/src/markups.rs @@ -27,7 +27,7 @@ pub fn menu_markup_sync( #[inline] pub async fn menu_markup( - command: impl Into, + command: impl Into + Send, user_id: u64, db: &DatabaseConnection, ) -> crate::Result { diff --git a/src/master_password_check.rs b/src/master_password_check.rs index 23eac81..abc1b6e 100644 --- a/src/master_password_check.rs +++ b/src/master_password_check.rs @@ -3,39 +3,19 @@ use std::sync::Arc; use teloxide::{ dispatching::{dialogue::GetChatId, DpHandlerDescription}, dptree::Handler, - types::User, }; -pub trait GetUserInfo: GetChatId + Clone + Send + Sync + 'static { - fn user(&self) -> Option<&User>; -} +type DynError = Arc; -impl GetUserInfo for Message { - fn user(&self) -> Option<&User> { - self.from() - } -} - -impl GetUserInfo for CallbackQuery { - fn user(&self) -> Option<&User> { - Some(&self.from) - } -} - -/// A wierd filter that checks for the existance of a master password. +/// Filters out the messages from users without master passwords /// /// # Returns /// /// Returns None if account exists, Some(None) if there's an account and Some(Some(String)) if an error occures. /// The String represents the error that occured #[inline] -async fn master_pass_exists( - msg: T, - db: DatabaseConnection, -) -> Option>> { - msg.chat_id()?; - - let user_id = match msg.user() { +async fn master_pass_exists(update: Update, db: DatabaseConnection) -> Option> { + let user_id = match update.user() { Some(user) => user.id.0, None => return Some(Some(Arc::new(NoUserInfo))), }; @@ -47,16 +27,16 @@ async fn master_pass_exists( } #[inline] -async fn notify_about_no_master_pass( +async fn notify_about_no_master_pass( bot: Throttle, - result: Option>, - msg: T, + result: Option, + update: Update, ) -> crate::Result<()> { if let Some(error) = result { return Err(error.into()); } bot.send_message( - msg.chat_id().unwrap(), + update.chat_id().unwrap(), "No master password set. Use /set_master_pass to set it", ) .reply_markup(deletion_markup()) @@ -66,7 +46,6 @@ async fn notify_about_no_master_pass( /// Gets a handler that filters out the messages of users that don't have a master password set #[inline] -pub fn get_handler( -) -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> { - dptree::filter_map_async(master_pass_exists::).endpoint(notify_about_no_master_pass::) +pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> { + dptree::filter_map_async(master_pass_exists).endpoint(notify_about_no_master_pass) } diff --git a/src/models.rs b/src/models.rs index 7ba2a69..0edd51f 100644 --- a/src/models.rs +++ b/src/models.rs @@ -11,7 +11,7 @@ pub struct DecryptedAccount { } impl DecryptedAccount { - /// Constructs DecryptedAccount by decrypting the provided account + /// Constructs `DecryptedAccount` by decrypting the provided account #[inline] pub fn from_account(account: account::Model, master_pass: &str) -> crate::Result { let (login, password) = account.decrypt(master_pass)?; @@ -22,7 +22,7 @@ impl DecryptedAccount { }) } - /// Constructs ActiveModel with eath field Set by encrypting `self` + /// Constructs `ActiveModel` with eath field Set by encrypting `self` #[inline] pub fn into_account( self, diff --git a/src/prelude.rs b/src/prelude.rs index 8329a98..8ded9c2 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,15 +1,14 @@ -pub(crate) use crate::{ +pub use crate::{ commands::Command, errors::*, first_handler, handler, markups::*, models::*, - state::State, - state::{Handler, MainDialogue, MessageIds, PackagedHandler}, + state::{Handler, MainDialogue, MessageIds, PackagedHandler, State}, utils::*, }; -pub(crate) use cryptography::prelude::*; -pub(crate) use entity::prelude::*; -pub(crate) use futures::{StreamExt, TryStreamExt}; -pub(crate) use sea_orm::prelude::*; -pub(crate) use teloxide::{adaptors::Throttle, prelude::*}; +pub use cryptography::prelude::*; +pub use entity::prelude::*; +pub use futures::{StreamExt, TryStreamExt}; +pub use sea_orm::prelude::*; +pub use teloxide::{adaptors::Throttle, prelude::*}; diff --git a/src/state.rs b/src/state.rs index 349d2d7..fc19466 100644 --- a/src/state.rs +++ b/src/state.rs @@ -3,7 +3,7 @@ mod generic; mod handler; -pub use handler::{Handler, MessageIds, PackagedHandler}; +pub use handler::{Handler, MessageIds, Packaged as PackagedHandler}; crate::export_handlers!( get_login, diff --git a/src/state/generic.rs b/src/state/generic.rs index 713f454..3c46304 100644 --- a/src/state/generic.rs +++ b/src/state/generic.rs @@ -9,17 +9,18 @@ pub async fn generic( db: DatabaseConnection, dialogue: MainDialogue, check: F, - no_text_message: impl Into, - next: PackagedHandler, + no_text_message: impl Into + Send, + handler: PackagedHandler, ) -> crate::Result<()> where for<'a> F: FnOnce( - &'a Message, - &'a DatabaseConnection, - &'a str, - ) -> BoxFuture<'a, crate::Result>>, + &'a Message, + &'a DatabaseConnection, + &'a str, + ) -> BoxFuture<'a, crate::Result>> + + Send, { - let mut handler = next.lock().await; + let mut handler = handler.lock().await; if handler.func.is_none() { let _ = dialogue.exit().await; return Err(HandlerUsed.into()); diff --git a/src/state/get_new_master_pass.rs b/src/state/get_new_master_pass.rs index 539e5a7..0a87ed5 100644 --- a/src/state/get_new_master_pass.rs +++ b/src/state/get_new_master_pass.rs @@ -10,19 +10,19 @@ fn process_validity(validity: PasswordValidity) -> Result<(), String> { let mut error_text = "Your master password is invalid:\n".to_owned(); if validity.contains(PasswordValidity::NO_LOWERCASE) { - error_text.push_str("\n* It doesn't have any lowercase characters") + error_text.push_str("\n* It doesn't have any lowercase characters"); } if validity.contains(PasswordValidity::NO_UPPERCASE) { - error_text.push_str("\n* It doesn't have any uppercase characters") + error_text.push_str("\n* It doesn't have any uppercase characters"); } if validity.contains(PasswordValidity::NO_NUMBER) { - error_text.push_str("\n* It doesn't have any numbers") + error_text.push_str("\n* It doesn't have any numbers"); } if validity.contains(PasswordValidity::NO_SPECIAL_CHARACTER) { - error_text.push_str("\n* It doesn't have any special characters") + error_text.push_str("\n* It doesn't have any special characters"); } if validity.contains(PasswordValidity::TOO_SHORT) { - error_text.push_str("\n* It is shorter than 8 characters") + error_text.push_str("\n* It is shorter than 8 characters"); } error_text.push_str("\n\nModify your password and send it again"); diff --git a/src/state/get_user.rs b/src/state/get_user.rs index f9f720d..b79fe06 100644 --- a/src/state/get_user.rs +++ b/src/state/get_user.rs @@ -10,9 +10,8 @@ use trim_in_place::TrimInPlace; #[inline] fn validate_document(document: Option<&Document>) -> Result<&Document, &'static str> { - let document = match document { - Some(document) => document, - None => return Err("You didn't send a file. Try again"), + let Some(document) = document else { + return Err("You didn't send a file. Try again"); }; if document.file.size > 1024 * 1024 * 200 { @@ -70,7 +69,7 @@ fn process_accounts( duplicates.push(account.name.as_str()); } if exists { - existing.push(account.name.as_str()) + existing.push(account.name.as_str()); } // If it already exists or if it is a duplicate there's no need to check the account's validity if !duplicate && !exists && !account.validate() { @@ -91,7 +90,7 @@ fn process_accounts( error_text, "\n\nDuplicate names:\n{:?}", duplicates.into_iter().format("\n") - )? + )?; } if !existing.is_empty() { @@ -99,7 +98,7 @@ fn process_accounts( error_text, "\n\nAccounts with these names already exist in the database:\n{:?}", existing.into_iter().format("\n") - )? + )?; } if !invalid.is_empty() { @@ -107,7 +106,7 @@ fn process_accounts( error_text, "\n\nInvalid account fields:\n{:?}", invalid.into_iter().format("\n") - )? + )?; } error_text.push_str("\n\nFix these problems and send the file again"); @@ -128,23 +127,23 @@ fn user_from_vec( } } -/// Function to handle GetUser state. It doesn't actually validate anything +/// Function to handle `GetUser` state. It doesn't actually validate anything pub async fn get_user( bot: Throttle, msg: Message, db: DatabaseConnection, dialogue: MainDialogue, - next: PackagedHandler, + handler: PackagedHandler, ) -> crate::Result<()> { let user_id = msg.from().ok_or(NoUserInfo)?.id.0; - let mut handler = next.lock().await; + let mut handler = handler.lock().await; if handler.func.is_none() { let _ = dialogue.exit().await; return Err(HandlerUsed.into()); } - if let Some("/cancel") = msg.text().map(str::trim) { + if msg.text().map(str::trim) == Some("/cancel") { dialogue.exit().await?; handler .previous diff --git a/src/state/handler.rs b/src/state/handler.rs index 36d0bf0..4c20f96 100644 --- a/src/state/handler.rs +++ b/src/state/handler.rs @@ -26,9 +26,9 @@ impl MessageIds { pub async fn alter_message( &mut self, bot: &Throttle, - text: impl Into, - markup: impl Into>, - parse_mode: impl Into>, + text: impl Into + Send, + markup: impl Into> + Send, + parse_mode: impl Into> + Send, ) -> crate::Result<()> { let mut edit = bot.edit_message_text(self.0, self.1, text); edit.parse_mode = parse_mode.into(); @@ -76,10 +76,10 @@ pub struct Handler { pub previous: MessageIds, } -pub type PackagedHandler = Arc>>; +pub type Packaged = Arc>>; impl Handler { - /// Convinience method to convert a simple async function and a previous message into PackagedHandler + /// Convinience method to convert a simple async function and a previous message into `PackagedHandler` #[inline] pub fn new(f: H, previous: impl Into) -> PackagedHandler where