Created markups.rs
This commit is contained in:
parent
925df8a5e5
commit
332356a95b
@ -1,13 +1,9 @@
|
||||
use crate::entity::{account, prelude::Account};
|
||||
use crate::handlers::{utils::package_handler, MainDialogue, State};
|
||||
use futures::TryStreamExt;
|
||||
use sea_orm::prelude::*;
|
||||
use teloxide::{
|
||||
adaptors::Throttle,
|
||||
prelude::*,
|
||||
types::ParseMode,
|
||||
types::{KeyboardButton, KeyboardMarkup},
|
||||
use crate::{
|
||||
entity::{account, prelude::Account},
|
||||
handlers::{markups, utils::package_handler, MainDialogue, State},
|
||||
};
|
||||
use sea_orm::prelude::*;
|
||||
use teloxide::{adaptors::Throttle, prelude::*, types::ParseMode};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
async fn get_master_pass(
|
||||
@ -64,13 +60,7 @@ pub async fn get_account(
|
||||
dialogue: MainDialogue,
|
||||
db: DatabaseConnection,
|
||||
) -> crate::Result<()> {
|
||||
let account_names: Vec<Vec<KeyboardButton>> = Account::get_names(msg.from().unwrap().id.0, &db)
|
||||
.await?
|
||||
.map_ok(|account| KeyboardButton::new(account))
|
||||
.try_chunks(3)
|
||||
.try_collect()
|
||||
.await?;
|
||||
let markup = KeyboardMarkup::new(account_names).resize_keyboard(true);
|
||||
let markup = markups::account_markup(msg.from().unwrap().id.0, &db).await?;
|
||||
let previous = bot
|
||||
.send_message(msg.chat.id, "Send account name")
|
||||
.reply_markup(markup)
|
||||
|
21
src/handlers/markups.rs
Normal file
21
src/handlers/markups.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use crate::entity::prelude::Account;
|
||||
use futures::TryStreamExt;
|
||||
use sea_orm::prelude::*;
|
||||
use teloxide::types::{KeyboardButton, KeyboardMarkup};
|
||||
|
||||
#[inline]
|
||||
pub async fn account_markup(
|
||||
user_id: u64,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<KeyboardMarkup> {
|
||||
let account_names: Vec<Vec<KeyboardButton>> = Account::get_names(user_id, db)
|
||||
.await?
|
||||
.map_ok(|account| KeyboardButton::new(account))
|
||||
.try_chunks(3)
|
||||
.try_collect()
|
||||
.await?;
|
||||
let markup = KeyboardMarkup::new(account_names)
|
||||
.resize_keyboard(true)
|
||||
.one_time_keyboard(true);
|
||||
Ok(markup)
|
||||
}
|
@ -10,6 +10,7 @@ use teloxide::{
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
mod commands;
|
||||
mod markups;
|
||||
mod state;
|
||||
mod utils;
|
||||
|
||||
|
@ -24,6 +24,7 @@ where
|
||||
dialogue.exit().await?;
|
||||
bot.send_message(msg.chat.id, "Successfully cancelled")
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
match check(&bot, &msg, &db, &text).await {
|
||||
Ok(true) => (),
|
||||
|
Loading…
Reference in New Issue
Block a user