use tokio::task::spawn_blocking; use crate::{ markups::{account_markup, menu_markup_sync}, prelude::*, }; /// Handles the messages which weren't matched by any commands or states pub async fn default( bot: Throttle, msg: Message, db: Pool, locale: LocaleRef, ) -> crate::Result<()> { let user_id = msg.get_user_id()?; if msg.text().is_none() || !MasterPass::exists(user_id, &db).await? { bot.send_message(msg.chat.id, &locale.unknown_command_use_help) .reply_markup(deletion_markup(locale)) .await?; return Ok(()); } let names = Account::search(user_id, msg.text().unwrap().to_owned(), &db).await?; match names.as_slice() { [] => { bot.send_message(msg.chat.id, &locale.no_accounts_found) .reply_markup(deletion_markup(locale)) .await?; } [name] => { let text = locale.show_hidden_account(name); bot.send_message(msg.chat.id, text) .reply_markup(account_markup(name, true, locale)) .parse_mode(teloxide::types::ParseMode::MarkdownV2) .await?; } _ => { let markup = spawn_blocking(|| menu_markup_sync("get", names)).await?; bot.send_message(msg.chat.id, &locale.choose_account) .reply_markup(markup) .await?; } } Ok(()) }