#[macro_export] macro_rules! change_state { ($dialogue: expr, $previous: expr, ($($param: ident),*), $next_state: expr, $next_func: ident) => {{ $dialogue .update($next_state(Handler::new( move |bot, msg, db, dialogue, ids, param| Box::pin($next_func(bot, msg, db, dialogue, ids, $($param,)* param)), $previous, ))) .await?; Ok(()) }}; } #[macro_export] macro_rules! first_handler { ($function_name: ident, $message: expr, $next_state: expr, $next_func: ident) => { #[inline] pub async fn $function_name( bot: Throttle, msg: Message, dialogue: MainDialogue, ) -> $crate::Result<()> { let previous = bot.send_message(msg.chat.id, $message).await?; $crate::change_state!(dialogue, &previous, (), $next_state, $next_func) } }; } #[macro_export] macro_rules! handler { ($function_name: ident ($($param: ident: $type: ty),*), $message: literal, $next_state: expr, $next_func: ident) => { #[allow(clippy::too_many_arguments)] #[inline] async fn $function_name( bot: Throttle, msg: Message, _: DatabaseConnection, dialogue: MainDialogue, mut ids: MessageIds, $($param: $type),* ) -> $crate::Result<()> { ids.alter_message(&bot, $message, None, None).await?; $crate::change_state!(dialogue, ids, ($($param),*), $next_state, $next_func) } }; } #[macro_export] macro_rules! ask_name_handler { ($function_name: ident, $message: literal, $next_func: ident) => { #[inline] pub async fn $function_name( bot: Throttle, msg: Message, dialogue: MainDialogue, db: DatabaseConnection, ) -> $crate::Result<()> { let user_id = msg.from().ok_or(NoUserInfo)?.id.0; let markup = account_list_markup(user_id, &db).await?; if markup.keyboard.is_empty() { bot.send_message(msg.chat.id, "No accounts found") .reply_markup(deletion_markup()) .await?; return Ok(()); } let previous = bot .send_message(msg.chat.id, $message) .reply_markup(markup) .await?; $crate::change_state!(dialogue, &previous, (), State::GetExistingName, $next_func) } }; } #[macro_export] macro_rules! simple_state_handler { ($function_name: ident, $check: ident, $no_text_message: literal) => { #[inline] pub async fn $function_name( bot: Throttle, msg: Message, db: DatabaseConnection, dialogue: MainDialogue, next: PackagedHandler, ) -> $crate::Result<()> { super::generic::generic( bot, msg, db, dialogue, |msg, db, param| Box::pin($check(msg, db, param)), $no_text_message, next, ) .await } }; }