52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use telers::{
|
|
event::{
|
|
EventReturn,
|
|
telegram::HandlerResult
|
|
},
|
|
filters::CommandObject,
|
|
types::Message,
|
|
Bot
|
|
};
|
|
|
|
use crate::{
|
|
assets::files::BAN_COMMAND_HELP, actions::ban::ban_member,
|
|
types::{
|
|
enums::target_user::TargetUser,
|
|
structs::handler_entity::HandlerEntity
|
|
},
|
|
utils::{
|
|
general::cast_boxed_array::cast_boxed,
|
|
telegram::{
|
|
args_parsers::get_user,
|
|
data_getters::get_chat_data,
|
|
senders::send_html
|
|
}
|
|
}
|
|
};
|
|
|
|
pub async fn ban(bot: Bot, message: Message, command: CommandObject) -> HandlerResult {
|
|
let args: Vec<&'static str> = cast_boxed(command.args);
|
|
|
|
let (chat_id, mut handler_entity): (i64, HandlerEntity) = get_chat_data(&bot, &message);
|
|
|
|
let target_user: TargetUser = get_user(
|
|
handler_entity.clone(),
|
|
args.first().copied(),
|
|
&mut 0,
|
|
);
|
|
|
|
if args.is_empty() && !target_user.exist(){
|
|
send_html(bot, message, BAN_COMMAND_HELP).await?;
|
|
|
|
return Ok(EventReturn::Cancel);
|
|
}
|
|
|
|
handler_entity
|
|
.message_sender_builder
|
|
.set_text("Нет ID или ответа на сообщение пользователя.");
|
|
|
|
ban_member(handler_entity, chat_id, target_user, 0).await?;
|
|
|
|
Ok(EventReturn::Finish)
|
|
}
|