58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
use telers::{
|
||
event::{telegram::HandlerResult, EventReturn},
|
||
methods::RestrictChatMember,
|
||
types::ChatPermissions,
|
||
};
|
||
|
||
use crate::types::{
|
||
enums::target_user::TargetUser,
|
||
structs::handler_entity::{ExtractedEntityData, HandlerEntity},
|
||
};
|
||
|
||
pub async fn unmute_member(
|
||
handler_entity: HandlerEntity,
|
||
chat_id: i64,
|
||
user: TargetUser,
|
||
) -> HandlerResult {
|
||
let (bot, message, sender_builder): ExtractedEntityData = handler_entity.extract();
|
||
|
||
let user_id: i64;
|
||
|
||
if let Some(id) = user.get_id() {
|
||
user_id = id;
|
||
} else {
|
||
sender_builder.build().send(&bot).await?;
|
||
|
||
return Ok(EventReturn::Cancel);
|
||
}
|
||
|
||
let default_member_permissions = ChatPermissions::all()
|
||
.can_change_info(false)
|
||
.can_manage_topics(false)
|
||
.can_invite_users(false)
|
||
.can_pin_messages(false);
|
||
|
||
let bot_action = RestrictChatMember::new(chat_id, user_id, default_member_permissions);
|
||
|
||
if let Err(error) = bot.send(bot_action).await {
|
||
sender_builder
|
||
.text(format!("Невозможно снять мут с пользователя: {error:?}."))
|
||
.build()
|
||
.send(&bot)
|
||
.await?;
|
||
|
||
Ok(EventReturn::Cancel)
|
||
} else {
|
||
let muted_user_name: Box<str> = user.get_user_name(&bot, &message).await.unwrap();
|
||
|
||
sender_builder
|
||
.reply_to(message.id())
|
||
.text(format!("С пользователя {muted_user_name} снят мут."))
|
||
.build()
|
||
.send(&bot)
|
||
.await?;
|
||
|
||
Ok(EventReturn::Finish)
|
||
}
|
||
}
|