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