diff --git a/src/main.rs b/src/main.rs index 38d5799..a3a9adc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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}; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..0025876 --- /dev/null +++ b/src/utils.rs @@ -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( + literal: &str, + ci: CallbackInfo, + db: &mut D, +) -> BotResult +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()), + )) +}