Removed inlines
This commit is contained in:
parent
064ec22e51
commit
25b02ba99a
@ -2,7 +2,6 @@ use super::AlterableField::{self, Login, Name, Pass};
|
||||
use crate::{change_state, cryptography::account::Cipher, prelude::*};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[inline]
|
||||
async fn update_account(
|
||||
user_id: u64,
|
||||
db: &Pool,
|
||||
@ -38,7 +37,6 @@ async fn update_account(
|
||||
Ok(updated)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
@ -72,7 +70,6 @@ async fn get_master_pass(
|
||||
|
||||
handler!(get_field(name:String, field:AlterableField, field_value:String),send_master_password, State::GetMasterPass, get_master_pass);
|
||||
|
||||
#[inline]
|
||||
pub async fn alter(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -2,7 +2,6 @@ use crate::{
|
||||
entity::locale::LocaleType, locales::LocaleTypeExt, markups::language_markup, prelude::*,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
pub async fn change_locale(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -2,7 +2,6 @@ use crate::{change_state, markups::account_markup, prelude::*};
|
||||
use teloxide::types::ParseMode;
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
@ -40,7 +39,6 @@ async fn get_master_pass(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn decrypt(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::{change_state, prelude::*};
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
@ -23,7 +22,6 @@ async fn get_master_pass(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn delete(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Deletes the message from the callback
|
||||
#[inline]
|
||||
pub async fn delete_message(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::{markups::account_markup, prelude::*};
|
||||
use teloxide::types::ParseMode;
|
||||
|
||||
#[inline]
|
||||
pub async fn get(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[inline]
|
||||
pub async fn get_menu(
|
||||
bot: Throttle<Bot>,
|
||||
q: CallbackQuery,
|
||||
|
@ -3,7 +3,6 @@ use tokio::task::spawn_blocking;
|
||||
|
||||
/// Gets the name of the master password, encryptes the account and adds it to the DB
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[inline]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -1,7 +1,6 @@
|
||||
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)
|
||||
.reply_markup(deletion_markup(locale))
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::{markups::language_markup, prelude::*};
|
||||
|
||||
#[inline]
|
||||
pub async fn change_language(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[inline]
|
||||
pub async fn delete(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -2,7 +2,6 @@ use crate::prelude::*;
|
||||
|
||||
/// Gets the master password, deletes the accounts and the master password from DB.
|
||||
/// Although it doesn't use the master password, we get it to be sure that it's the user who used that command
|
||||
#[inline]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -5,7 +5,6 @@ use teloxide::types::InputFile;
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
/// Decryptes the account on a worker thread and adds it to the accounts vector
|
||||
#[inline]
|
||||
async fn decrypt_account(
|
||||
account: Account,
|
||||
master_pass: Arc<str>,
|
||||
@ -18,7 +17,6 @@ async fn decrypt_account(
|
||||
}
|
||||
|
||||
/// Gets the master password, decryptes the account and sends the json file to the user
|
||||
#[inline]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -11,7 +11,6 @@ type PasswordArray = [ArrayString<PASSWORD_LENGTH>; AMOUNT_OF_PASSWORDS];
|
||||
const BUFFER_LENGTH: usize = (PASSWORD_LENGTH + PASSWORD_PADDING_LENGTH) * AMOUNT_OF_PASSWORDS;
|
||||
|
||||
/// Handles /`gen_password` command by generating 10 copyable passwords and sending them to the user
|
||||
#[inline]
|
||||
pub async fn gen_password(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[inline]
|
||||
pub async fn get_account(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -3,7 +3,6 @@ use std::fmt::Write;
|
||||
use teloxide::types::ParseMode;
|
||||
|
||||
/// Handles /`get_accounts` command by sending the list of copyable account names to the user
|
||||
#[inline]
|
||||
pub async fn get_accounts(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -1,7 +1,6 @@
|
||||
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)
|
||||
.reply_markup(deletion_markup(locale))
|
||||
|
@ -7,7 +7,6 @@ use tokio::task::spawn_blocking;
|
||||
|
||||
/// Ecryptes the account and adds it to the database
|
||||
/// If any of these steps fail, the account name will be added to the failed vector
|
||||
#[inline]
|
||||
async fn encrypt_account(
|
||||
account: DecryptedAccount,
|
||||
user_id: u64,
|
||||
@ -26,7 +25,6 @@ async fn encrypt_account(
|
||||
}
|
||||
|
||||
/// Gets the master password, encryptes and adds the accounts to the DB
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[inline]
|
||||
pub async fn menu(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -4,7 +4,6 @@ use crate::{
|
||||
};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn get_master_pass2(
|
||||
bot: Throttle<Bot>,
|
||||
@ -50,7 +49,6 @@ async fn get_master_pass2(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn get_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
_: Message,
|
||||
@ -77,7 +75,6 @@ async fn get_master_pass(
|
||||
}
|
||||
|
||||
/// Handles /`set_master_pass` command
|
||||
#[inline]
|
||||
pub async fn set_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -1,7 +1,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).await?;
|
||||
Ok(())
|
||||
|
@ -5,7 +5,6 @@ pub mod hashing;
|
||||
pub mod passwords;
|
||||
|
||||
/// Returns true if the field is valid
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn validate_field(field: &str) -> bool {
|
||||
if field.len() > 255 {
|
||||
|
@ -10,7 +10,6 @@ pub struct Cipher {
|
||||
|
||||
impl Cipher {
|
||||
/// Creates a new cipher from a master password and the salt
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn new(password: &[u8], salt: &[u8]) -> Self {
|
||||
let key = pbkdf2_hmac_array::<Sha256, 32>(password, salt, 480_000);
|
||||
@ -21,7 +20,6 @@ impl Cipher {
|
||||
}
|
||||
|
||||
/// Encrypts the value with the current cipher. The 12 byte nonce is appended to the result
|
||||
#[inline]
|
||||
pub fn encrypt(&self, value: &mut Vec<u8>) {
|
||||
let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng);
|
||||
self.chacha.encrypt_in_place(&nonce, b"", value).unwrap();
|
||||
@ -33,7 +31,6 @@ impl Cipher {
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the tag doesn't match the ciphertext
|
||||
#[inline]
|
||||
#[allow(clippy::missing_panics_doc)]
|
||||
pub fn decrypt(&self, value: &mut Vec<u8>) -> super::Result<()> {
|
||||
if value.len() <= 12 {
|
||||
@ -61,7 +58,6 @@ impl Decrypted {
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the tag doesn't match the ciphertext or if the decrypted data isn't valid UTF-8
|
||||
#[inline]
|
||||
pub fn from_account(mut account: Account, master_pass: &str) -> super::Result<Self> {
|
||||
let cipher = Cipher::new(master_pass.as_bytes(), &account.salt);
|
||||
cipher.decrypt(&mut account.enc_login)?;
|
||||
@ -75,7 +71,6 @@ impl Decrypted {
|
||||
}
|
||||
|
||||
/// Constructs `ActiveModel` with eath field Set by encrypting `self`
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn into_account(self, user_id: u64, master_pass: &str) -> Account {
|
||||
let mut enc_login = self.login.into_bytes();
|
||||
@ -97,7 +92,6 @@ impl Decrypted {
|
||||
}
|
||||
|
||||
/// Returns true if the account's fields are valid
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn validate(&self) -> bool {
|
||||
[
|
||||
|
@ -10,7 +10,6 @@ pub const SALT_LENGTH: usize = 64;
|
||||
static PARAMS: Lazy<Params> = Lazy::new(|| Params::new(14, 8, 1, HASH_LENGTH).unwrap());
|
||||
|
||||
/// Hashes the bytes with Scrypt with the given salt
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[allow(clippy::missing_panics_doc)]
|
||||
pub fn hash_scrypt(bytes: &[u8], salt: &[u8]) -> [u8; HASH_LENGTH] {
|
||||
@ -30,7 +29,6 @@ where
|
||||
}
|
||||
|
||||
impl HashedBytes<[u8; HASH_LENGTH], [u8; SALT_LENGTH]> {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn new(bytes: &[u8]) -> Self {
|
||||
let mut salt = [0; 64];
|
||||
@ -47,7 +45,6 @@ where
|
||||
T: AsRef<[u8]>,
|
||||
U: AsRef<[u8]>,
|
||||
{
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn verify(&self, bytes: &[u8]) -> bool {
|
||||
let hash = hash_scrypt(bytes, self.salt.as_ref());
|
||||
@ -56,7 +53,6 @@ where
|
||||
}
|
||||
|
||||
impl<'a> From<&'a MasterPass> for HashedBytes<&'a [u8], &'a [u8]> {
|
||||
#[inline]
|
||||
fn from(value: &'a MasterPass) -> Self {
|
||||
HashedBytes {
|
||||
hash: &value.password_hash,
|
||||
|
@ -24,7 +24,6 @@ bitflags::bitflags! {
|
||||
|
||||
/// Returns true if the generated master password is valid.
|
||||
/// It checks that it has at least one lowercase, one uppercase, one number and one punctuation char
|
||||
#[inline]
|
||||
#[must_use]
|
||||
fn check_generated_password<const LENGTH: usize>(password: &[u8; LENGTH]) -> bool {
|
||||
let mut flags = PasswordFlags::empty();
|
||||
@ -46,7 +45,6 @@ fn check_generated_password<const LENGTH: usize>(password: &[u8; LENGTH]) -> boo
|
||||
}
|
||||
|
||||
/// Continuously generates the password until it passes the checks
|
||||
#[inline]
|
||||
#[must_use]
|
||||
fn generate_password<R, const LENGTH: usize>(rng: &mut R) -> ArrayString<LENGTH>
|
||||
where
|
||||
@ -60,7 +58,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub fn generate_passwords<const AMOUNT: usize, const LENGTH: usize>(
|
||||
@ -69,7 +66,6 @@ pub fn generate_passwords<const AMOUNT: usize, const LENGTH: usize>(
|
||||
array::from_fn(|_| generate_password(&mut rng))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn check_master_pass(password: &str) -> PasswordValidity {
|
||||
let mut count = 0;
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Handles the messages which weren't matched by any commands or states
|
||||
#[inline]
|
||||
pub async fn default(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||
bot.send_message(msg.chat.id, &locale.unknown_command_use_help)
|
||||
.reply_markup(deletion_markup(locale))
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Deletes the message without returning errors
|
||||
#[inline]
|
||||
pub async fn delete_message(bot: Throttle<Bot>, msg: Message) {
|
||||
let ids = MessageIds::from(&msg);
|
||||
if let Err(err) = ids.delete(&bot).await {
|
||||
|
@ -1,13 +1,11 @@
|
||||
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]
|
||||
async fn notify_about_no_user_info(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
@ -48,7 +46,6 @@ async fn notify_about_no_user_info(
|
||||
}
|
||||
|
||||
/// Gets a handler that filters out the messages without user information
|
||||
#[inline]
|
||||
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
|
||||
dptree::filter(has_no_user_info).endpoint(notify_about_no_user_info)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ type DynError = Arc<dyn std::error::Error + Send + Sync>;
|
||||
///
|
||||
/// Returns None if account exists, Some(None) if there's an account and Some(Some(DynError)) if an error occures.
|
||||
/// The String represents the error that occured
|
||||
#[inline]
|
||||
async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>> {
|
||||
let user_id = match update.user() {
|
||||
Some(user) => user.id.0,
|
||||
@ -26,7 +25,6 @@ async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn notify_about_no_master_pass(
|
||||
bot: Throttle<Bot>,
|
||||
locale: LocaleRef,
|
||||
@ -46,7 +44,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)
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ pub struct Account {
|
||||
|
||||
impl Account {
|
||||
// Inserts the account into DB
|
||||
#[inline]
|
||||
pub async fn insert(&self, pool: &Pool) -> super::Result<()> {
|
||||
query!(
|
||||
"INSERT INTO account VALUES (?, ?, ?, ?, ?)",
|
||||
@ -29,7 +28,6 @@ impl Account {
|
||||
}
|
||||
|
||||
/// Gets all user's account from DB
|
||||
#[inline]
|
||||
pub fn get_all(user_id: u64, pool: &Pool) -> impl Stream<Item = super::Result<Self>> + '_ {
|
||||
query_as("SELECT * FROM account WHERE user_id = ?")
|
||||
.bind(user_id)
|
||||
@ -37,7 +35,6 @@ impl Account {
|
||||
}
|
||||
|
||||
/// Streams the names of the user accounts
|
||||
#[inline]
|
||||
pub fn get_names(user_id: u64, pool: &Pool) -> impl Stream<Item = super::Result<String>> + '_ {
|
||||
query_as::<_, (String,)>("SELECT name FROM account WHERE user_id = ? ORDER BY name")
|
||||
.bind(user_id)
|
||||
@ -46,7 +43,6 @@ impl Account {
|
||||
}
|
||||
|
||||
/// Checks if the account exists
|
||||
#[inline]
|
||||
pub async fn exists(user_id: u64, account_name: &str, pool: &Pool) -> super::Result<bool> {
|
||||
query_as::<_, (bool,)>(
|
||||
"SELECT EXISTS(SELECT * FROM account WHERE user_id = ? AND name = ? LIMIT 1) as value",
|
||||
@ -59,7 +55,6 @@ impl Account {
|
||||
}
|
||||
|
||||
/// Gets the account from the DB
|
||||
#[inline]
|
||||
pub async fn get(user_id: u64, account_name: &str, pool: &Pool) -> super::Result<Option<Self>> {
|
||||
query_as("SELECT * FROM account WHERE user_id = ? AND name = ?")
|
||||
.bind(user_id)
|
||||
@ -69,7 +64,6 @@ impl Account {
|
||||
}
|
||||
|
||||
// Deletes the account from DB
|
||||
#[inline]
|
||||
pub async fn delete(user_id: u64, name: &str, pool: &Pool) -> super::Result<()> {
|
||||
query!(
|
||||
"DELETE FROM account WHERE user_id = ? AND name = ?",
|
||||
@ -82,7 +76,6 @@ impl Account {
|
||||
}
|
||||
|
||||
/// Deletes all the user's accounts from DB
|
||||
#[inline]
|
||||
pub async fn delete_all(
|
||||
user_id: u64,
|
||||
pool: impl Executor<'_, Database = MySql>,
|
||||
@ -94,7 +87,6 @@ impl Account {
|
||||
}
|
||||
|
||||
/// Gets a name by a SHA256 hash of the name
|
||||
#[inline]
|
||||
pub async fn get_name_by_hash(
|
||||
user_id: u64,
|
||||
hash: &[u8],
|
||||
@ -111,8 +103,6 @@ impl Account {
|
||||
|
||||
Ok(name.map(|(name,)| name))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn get_salt(user_id: u64, name: &str, pool: &Pool) -> super::Result<Option<Vec<u8>>> {
|
||||
let salt =
|
||||
query_as::<_, (Vec<u8>,)>("SELECT salt FROM account WHERE user_id = ? AND name = ?")
|
||||
@ -123,8 +113,6 @@ impl Account {
|
||||
|
||||
Ok(salt.map(|(salt,)| salt))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn update_name(
|
||||
user_id: u64,
|
||||
original_name: &str,
|
||||
@ -141,8 +129,6 @@ impl Account {
|
||||
.await
|
||||
.map(|result| result.rows_affected() != 0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn update_login(
|
||||
user_id: u64,
|
||||
name: &str,
|
||||
@ -159,8 +145,6 @@ impl Account {
|
||||
.await
|
||||
.map(|result| result.rows_affected() != 0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn update_password(
|
||||
user_id: u64,
|
||||
name: &str,
|
||||
|
@ -10,7 +10,6 @@ pub struct MasterPass {
|
||||
|
||||
impl MasterPass {
|
||||
// Inserts the master password into DB
|
||||
#[inline]
|
||||
pub async fn insert(&self, pool: &Pool, locale: LocaleType) -> super::Result<()> {
|
||||
let locale: u8 = locale.into();
|
||||
query!(
|
||||
@ -26,7 +25,6 @@ impl MasterPass {
|
||||
}
|
||||
|
||||
/// Gets the master password from the database
|
||||
#[inline]
|
||||
pub async fn get(user_id: u64, pool: &Pool) -> super::Result<Option<Self>> {
|
||||
query_as("SELECT user_id, salt, password_hash FROM master_pass WHERE user_id = ?")
|
||||
.bind(user_id)
|
||||
@ -35,7 +33,6 @@ impl MasterPass {
|
||||
}
|
||||
|
||||
/// Checks if the master password for the user exists
|
||||
#[inline]
|
||||
pub async fn exists(user_id: u64, pool: &Pool) -> super::Result<bool> {
|
||||
query_as::<_, (bool,)>(
|
||||
"SELECT EXISTS(SELECT * FROM master_pass WHERE user_id = ? LIMIT 1) as value",
|
||||
|
@ -21,7 +21,6 @@ pub enum InvalidCommand {
|
||||
UnknownLocale,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn init_logger() {
|
||||
tracing_subscriber::registry()
|
||||
.with(fmt::layer().pretty())
|
||||
@ -32,7 +31,6 @@ pub fn init_logger() {
|
||||
/// 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<T>(error: T)
|
||||
where
|
||||
T: Debug + Display,
|
||||
@ -43,7 +41,6 @@ where
|
||||
pub struct ErrorHandler;
|
||||
|
||||
impl teloxide::error_handlers::ErrorHandler<crate::Error> for ErrorHandler {
|
||||
#[inline]
|
||||
fn handle_error(
|
||||
self: std::sync::Arc<Self>,
|
||||
error: crate::Error,
|
||||
|
@ -13,7 +13,6 @@ macro_rules! change_state {
|
||||
#[macro_export]
|
||||
macro_rules! first_handler {
|
||||
($function_name: ident, $message: ident, $next_state: expr, $next_func: ident) => {
|
||||
#[inline]
|
||||
pub async fn $function_name(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
@ -33,7 +32,6 @@ macro_rules! first_handler {
|
||||
macro_rules! handler {
|
||||
($function_name: ident ($($param: ident: $type: ty),*), $message: ident, $next_state: expr, $next_func: ident) => {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[inline]
|
||||
async fn $function_name(
|
||||
bot: Throttle<Bot>,
|
||||
_: Message,
|
||||
@ -55,7 +53,6 @@ macro_rules! handler {
|
||||
#[macro_export]
|
||||
macro_rules! simple_state_handler {
|
||||
($function_name: ident, $check: ident) => {
|
||||
#[inline]
|
||||
pub async fn $function_name(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -5,7 +5,6 @@ use sha2::{Digest, Sha256};
|
||||
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[inline]
|
||||
pub fn menu_markup_sync(
|
||||
command: &str,
|
||||
names: impl IntoIterator<Item = String>,
|
||||
@ -25,7 +24,6 @@ pub fn menu_markup_sync(
|
||||
InlineKeyboardMarkup::new(&names)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn menu_markup(
|
||||
command: impl Into<String> + Send,
|
||||
user_id: u64,
|
||||
@ -39,7 +37,6 @@ pub async fn menu_markup(
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn make_button(text: &str, command: &str, param: &str) -> InlineKeyboardButton {
|
||||
let mut data = command.to_owned();
|
||||
data.reserve(param.len() + 1);
|
||||
@ -48,7 +45,6 @@ fn make_button(text: &str, command: &str, param: &str) -> InlineKeyboardButton {
|
||||
InlineKeyboardButton::callback(text, data)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn account_markup(name: &str, is_encrypted: bool, locale: LocaleRef) -> InlineKeyboardMarkup {
|
||||
let mut hash = [0; 43];
|
||||
B64_ENGINE
|
||||
@ -78,7 +74,6 @@ pub fn account_markup(name: &str, is_encrypted: bool, locale: LocaleRef) -> Inli
|
||||
InlineKeyboardMarkup::new(&main_buttons).append_row([menu_button])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn language_markup() -> InlineKeyboardMarkup {
|
||||
let languages = [("🇷🇺 Русский", "ru"), ("🇬🇧 English", "en")]
|
||||
.into_iter()
|
||||
@ -89,7 +84,6 @@ pub fn language_markup() -> InlineKeyboardMarkup {
|
||||
|
||||
/// Creates a markup with a "Delete message" button.
|
||||
/// This markup should be added for all messages that won't be deleted afterwards
|
||||
#[inline]
|
||||
pub fn deletion_markup(locale: LocaleRef) -> InlineKeyboardMarkup {
|
||||
let button = InlineKeyboardButton::callback(&locale.delete_message_button, "delete_message");
|
||||
InlineKeyboardMarkup::new([[button]])
|
||||
|
@ -2,7 +2,6 @@ use crate::{errors::HandlerUsed, prelude::*};
|
||||
use futures::future::BoxFuture;
|
||||
|
||||
/// A generic state handler. It checks for "/cancel" messages and runs the provided validation function
|
||||
#[inline]
|
||||
pub async fn generic<F>(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[inline]
|
||||
async fn check_login(
|
||||
_: &Message,
|
||||
_: &Pool,
|
||||
|
@ -2,7 +2,6 @@ use crate::{cryptography::hashing::HashedBytes, prelude::*};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
/// Returns true if the provided master password is valid
|
||||
#[inline]
|
||||
async fn check_master_pass(
|
||||
msg: &Message,
|
||||
db: &Pool,
|
||||
|
@ -4,7 +4,6 @@ use crate::{
|
||||
};
|
||||
use std::fmt::Write as _;
|
||||
|
||||
#[inline]
|
||||
fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(), String> {
|
||||
if validity.is_empty() {
|
||||
return Ok(());
|
||||
@ -39,7 +38,6 @@ fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(),
|
||||
}
|
||||
|
||||
/// Checks that the account with that name exists
|
||||
#[inline]
|
||||
async fn check_new_master_pass(
|
||||
_: &Message,
|
||||
_: &Pool,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
/// Validates a new account
|
||||
#[inline]
|
||||
async fn check_new_account_name(
|
||||
msg: &Message,
|
||||
db: &Pool,
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[inline]
|
||||
async fn check_password(
|
||||
_: &Message,
|
||||
_: &Pool,
|
||||
|
@ -28,7 +28,6 @@ impl InvalidDocument {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn validate_document(document: Option<&Document>) -> Result<&Document, InvalidDocument> {
|
||||
let Some(document) = document else {
|
||||
return Err(InvalidDocument::NoFileSend);
|
||||
@ -49,7 +48,6 @@ fn validate_document(document: Option<&Document>) -> Result<&Document, InvalidDo
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn download_file(bot: &Throttle<Bot>, file: &FileMeta) -> crate::Result<Box<[u8]>> {
|
||||
let path = bot.get_file(&file.id).await?.path;
|
||||
let mut data = Vec::with_capacity(file.size as usize);
|
||||
@ -60,7 +58,6 @@ async fn download_file(bot: &Throttle<Bot>, file: &FileMeta) -> crate::Result<Bo
|
||||
Ok(data.into_boxed_slice())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn process_accounts(
|
||||
accounts: &mut [DecryptedAccount],
|
||||
existing_names: ahash::HashSet<String>,
|
||||
@ -136,7 +133,6 @@ fn process_accounts(
|
||||
Ok(Err(error_text))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn user_from_bytes(
|
||||
bytes: impl AsRef<[u8]>,
|
||||
existing_names: ahash::HashSet<String>,
|
||||
@ -150,7 +146,6 @@ fn user_from_bytes(
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn user_from_document(
|
||||
bot: &Throttle<Bot>,
|
||||
db: &Pool,
|
||||
@ -178,7 +173,6 @@ async fn user_from_document(
|
||||
}
|
||||
|
||||
/// Function to handle `GetUser` state. It doesn't actually validate anything
|
||||
#[inline]
|
||||
pub async fn get_user(
|
||||
bot: Throttle<Bot>,
|
||||
msg: Message,
|
||||
|
@ -13,7 +13,6 @@ pub struct MessageIds(pub ChatId, pub MessageId);
|
||||
|
||||
impl MessageIds {
|
||||
// Tries to delete the message while ignoring API errors
|
||||
#[inline]
|
||||
pub async fn delete(self, bot: &Throttle<Bot>) -> Result<(), RequestError> {
|
||||
match bot.delete_message(self.0, self.1).await {
|
||||
Ok(_) | Err(RequestError::Api(_)) => Ok(()),
|
||||
@ -22,7 +21,6 @@ impl MessageIds {
|
||||
}
|
||||
|
||||
/// Tries to alter the message or sends a new one
|
||||
#[inline]
|
||||
pub async fn alter_message(
|
||||
&mut self,
|
||||
bot: &Throttle<Bot>,
|
||||
@ -55,7 +53,6 @@ impl MessageIds {
|
||||
}
|
||||
|
||||
impl From<&Message> for MessageIds {
|
||||
#[inline]
|
||||
fn from(value: &Message) -> Self {
|
||||
Self(value.chat.id, value.id)
|
||||
}
|
||||
@ -84,7 +81,6 @@ pub type Packaged<T> = Arc<Mutex<Handler<T>>>;
|
||||
|
||||
impl<T> Handler<T> {
|
||||
/// Convinience method to convert a simple async function and a previous message into `PackagedHandler`
|
||||
#[inline]
|
||||
pub fn new<H>(f: H, previous: impl Into<MessageIds>) -> PackagedHandler<T>
|
||||
where
|
||||
H: FnOnce(
|
||||
|
Loading…
Reference in New Issue
Block a user