63 lines
2.1 KiB
Rust
63 lines
2.1 KiB
Rust
use telers::{
|
|
enums::ParseMode,
|
|
event::{telegram::HandlerResult, EventReturn},
|
|
filters::CommandObject,
|
|
types::Message,
|
|
Bot,
|
|
};
|
|
|
|
use crate::{
|
|
assets::files::UNMUTE_COMMAND_HELP,
|
|
handlers::actions::unmute::unmute_member,
|
|
types::{
|
|
enums::target_user::TargetUser,
|
|
structs::{handler_entity::HandlerEntity, message_sender::MessageSender},
|
|
},
|
|
utils::general::parse_boxed_array::parse_boxed,
|
|
};
|
|
|
|
pub async fn unmute(bot: Bot, message: Message, command: CommandObject) -> HandlerResult {
|
|
let args: Vec<&'static str> = parse_boxed(command.args);
|
|
|
|
let (message_id, chat_id): (i64, i64) = (message.id(), message.chat().id());
|
|
let sender = MessageSender::builder(chat_id).reply_to(message_id);
|
|
let mut handler_entity: HandlerEntity = HandlerEntity::new(bot, message, sender);
|
|
|
|
match args.first().cloned() {
|
|
Some(raw_id) => {
|
|
handler_entity
|
|
.message_sender_builder
|
|
.set_text("unmute: ID пользователя не указан.");
|
|
|
|
if let Ok(parsed_id) = raw_id.parse::<i64>() {
|
|
let on_id: TargetUser = TargetUser::Id(parsed_id);
|
|
unmute_member(handler_entity, chat_id, on_id).await?;
|
|
} else {
|
|
handler_entity
|
|
.message_sender_builder
|
|
.build()
|
|
.send(&handler_entity.bot_instance)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
}
|
|
None => {
|
|
if handler_entity.message_reciever.reply_to_message().is_none() {
|
|
handler_entity
|
|
.message_sender_builder
|
|
.text(UNMUTE_COMMAND_HELP)
|
|
.parse_mode(ParseMode::HTML)
|
|
.build()
|
|
.send(&handler_entity.bot_instance)
|
|
.await
|
|
.unwrap();
|
|
} else {
|
|
let on_reply = TargetUser::Reply(handler_entity.message_reciever.clone());
|
|
unmute_member(handler_entity, chat_id, on_reply).await?;
|
|
}
|
|
}
|
|
}
|
|
|
|
Ok(EventReturn::Finish)
|
|
}
|