gluon/src/actions/unmute.rs

58 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}