use telers::{ event::{telegram::HandlerResult, EventReturn}, methods::BanChatMember, Bot, }; use tokio::time::{sleep, Duration as DurationSleep}; use crate::{ types::{ enums::target_user::TargetUser, structs::handler_entity::{ExtractedEntityData, HandlerEntity}, }, utils::telegram::try_do::try_restrict, }; pub async fn ban_member( handler_entity: HandlerEntity, chat_id: i64, user: TargetUser, delay: u64, ) -> HandlerResult { let (bot, message, mut sender_builder): ExtractedEntityData = handler_entity.extract(); sleep(DurationSleep::from_millis(delay)).await; let user_id: i64 = user.get_id().unwrap(); let callback = || async { bot.send(BanChatMember::new(chat_id, user_id)).await }; let demote_args: (&Bot, i64, i64) = (&bot, user_id, chat_id); sender_builder.set_text("Невозможно забанить пользователя."); if try_restrict(callback, demote_args, sender_builder.clone().build()) .await .is_err() { Ok(EventReturn::Cancel) } else { let banned_user_name: String = user.get_user_name(&bot, &message).await.unwrap(); sender_builder .reply_to(message.id()) .text(format!("Пользователь {banned_user_name} забанен.")) .build() .send(&bot) .await?; Ok(EventReturn::Finish) } }