Removed utils mod, moved hexing the name to entity library

This commit is contained in:
2024-02-03 16:31:19 +03:00
parent e8f0fcd819
commit a359364606
12 changed files with 18 additions and 26 deletions

View File

@ -80,7 +80,7 @@ pub async fn alter(
let user_id = q.from.id.0;
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
let Some(name) = name_from_hash(&db, user_id, &hash).await? else {
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
try_join!(
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())

View File

@ -52,7 +52,7 @@ pub async fn decrypt(
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
let user_id = q.from.id.0;
let Some(name) = name_from_hash(&db, user_id, &hash).await? else {
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
try_join!(
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())

View File

@ -40,7 +40,7 @@ pub async fn delete(
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
let user_id = q.from.id.0;
let Some(name) = name_from_hash(&db, user_id, &hash).await? else {
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
try_join!(
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())

View File

@ -12,7 +12,7 @@ pub async fn get(
let user_id = q.from.id.0;
let mut ids: MessageIds = q.message.as_ref().unwrap().into();
let Some(name) = name_from_hash(&db, user_id, &hash).await? else {
let Some(name) = Account::get_name_by_hash(user_id, &hash, &db).await? else {
try_join!(
bot.send_message(ids.0, "Account wasn't found")
.reply_markup(deletion_markup())

View File

@ -0,0 +1,7 @@
use crate::prelude::*;
/// Deletes the message ignoring the errors
#[inline]
pub async fn delete_message(bot: Throttle<Bot>, msg: Message) {
let _ = bot.delete_message(msg.chat.id, msg.id).await;
}

View File

@ -1,6 +1,7 @@
mod callbacks;
mod commands;
mod default;
mod delete_mesage_handler;
mod errors;
mod filter_user_info;
mod macros;
@ -9,7 +10,6 @@ mod master_password_check;
mod models;
mod prelude;
mod state;
mod utils;
use anyhow::{Error, Result};
use dotenvy::dotenv;
@ -45,7 +45,7 @@ fn get_dispatcher(
.branch(case![Command::Import].endpoint(commands::import));
let message_handler = Update::filter_message()
.map_async(utils::delete_message)
.map_async(delete_mesage_handler::delete_message)
// Filters out the messages without user information
.branch(filter_user_info::get_handler())
.branch(case![State::GetNewName(next)].endpoint(state::get_new_name))

View File

@ -5,7 +5,6 @@ pub use crate::{
markups::*,
models::*,
state::{Handler, MainDialogue, MessageIds, PackagedHandler, State},
utils::*,
};
pub use cryptography::prelude::*;
pub use entity::{prelude::*, Pool};

View File

@ -1,15 +0,0 @@
use crate::prelude::*;
/// Deletes the message ignoring the errors
#[inline]
pub async fn delete_message(bot: Throttle<Bot>, msg: Message) {
let _ = bot.delete_message(msg.chat.id, msg.id).await;
}
#[inline]
pub async fn name_from_hash(db: &Pool, user_id: u64, hash: &[u8]) -> crate::Result<Option<String>> {
let hash = hex::encode(hash);
Account::get_name_by_hash(user_id, hash, db)
.await
.map_err(Into::into)
}