feat(fn): remove try_admin_action function
This commit is contained in:
parent
d570cfb1f9
commit
673887e72e
|
@ -3,4 +3,3 @@ pub mod args_parser;
|
|||
pub mod data_getters;
|
||||
pub mod member_rights;
|
||||
pub mod senders;
|
||||
pub mod try_admin_action;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
use telers::{
|
||||
errors::{HandlerError, SessionErrorKind},
|
||||
event::simple::HandlerResult,
|
||||
methods::SendMessage,
|
||||
Bot,
|
||||
};
|
||||
|
||||
use super::member_rights::demote_user;
|
||||
|
||||
const DEMOTE_ERROR: &str = "Невозможно снять привелегий администратора в силу того, что права были выданы одним из администраторов или основателем";
|
||||
|
||||
pub async fn try_admin_action<F>(
|
||||
callback: F,
|
||||
bot: &Bot,
|
||||
chat_id: i64,
|
||||
user_id: i64,
|
||||
) -> HandlerResult
|
||||
where
|
||||
F: Copy + AsyncFnOnce(i64) -> Result<bool, SessionErrorKind>,
|
||||
{
|
||||
if callback(user_id).await.is_err() {
|
||||
if demote_user(bot, user_id, chat_id).await.is_err() {
|
||||
bot.send(SendMessage::new(chat_id, DEMOTE_ERROR)).await?;
|
||||
return Err(HandlerError::from_display("DemoteFailure"));
|
||||
} else {
|
||||
callback(user_id).await;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue