create create_callback_button function
description: utils.rs will have shortcuts for frequently used code
This commit is contained in:
parent
36c729e57b
commit
8c2d2425c4
@ -1,6 +1,7 @@
|
||||
pub mod admin;
|
||||
pub mod db;
|
||||
pub mod mongodb_storage;
|
||||
pub mod utils;
|
||||
|
||||
use db::callback_info::CallbackInfo;
|
||||
use log::{info, warn};
|
||||
|
||||
28
src/utils.rs
Normal file
28
src/utils.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use teloxide::types::InlineKeyboardButton;
|
||||
|
||||
use crate::{
|
||||
db::{callback_info::CallbackInfo, CallDB},
|
||||
BotResult,
|
||||
};
|
||||
|
||||
pub async fn create_callback_button<C, D>(
|
||||
literal: &str,
|
||||
ci: CallbackInfo<C>,
|
||||
db: &mut D,
|
||||
) -> BotResult<InlineKeyboardButton>
|
||||
where
|
||||
C: Serialize + for<'a> Deserialize<'a> + Send + Sync,
|
||||
D: CallDB + Send,
|
||||
{
|
||||
let text = db
|
||||
.get_literal_value(literal)
|
||||
.await?
|
||||
.unwrap_or("Please, set content of this message".into());
|
||||
let ci = ci.store(db).await?;
|
||||
|
||||
Ok(InlineKeyboardButton::new(
|
||||
text,
|
||||
teloxide::types::InlineKeyboardButtonKind::CallbackData(ci.get_id()),
|
||||
))
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user