FIXED: Finish message after bot action
This commit is contained in:
parent
820fa21878
commit
f625fc7960
|
@ -50,14 +50,7 @@ pub async fn ban(
|
|||
{
|
||||
Ok(EventReturn::Cancel)
|
||||
} else {
|
||||
let banned_user_name: String = message
|
||||
.reply_to_message()
|
||||
.unwrap()
|
||||
.from()
|
||||
.unwrap()
|
||||
.clone()
|
||||
.username
|
||||
.unwrap();
|
||||
let banned_user_name: String = user.get_user_name(&bot, &message).await.unwrap();
|
||||
|
||||
sender_builder
|
||||
.reply_to(message.id())
|
||||
|
|
|
@ -7,7 +7,7 @@ use tokio::time::{sleep, Duration};
|
|||
|
||||
use crate::{
|
||||
types::{
|
||||
enums::target_user::TargetUser,
|
||||
enums::target_user::{self, TargetUser},
|
||||
structs::handler_entity::{ExtractedEntityData, HandlerEntity},
|
||||
TimeValues,
|
||||
},
|
||||
|
@ -45,6 +45,7 @@ pub async fn mute(
|
|||
|
||||
let (unmute_date, postfix, mute_duration): ExtractedDuration = get_duration(time);
|
||||
let demote_args: (&Bot, i64, i64) = (&bot, user_id, chat_id);
|
||||
|
||||
let callback = || async { restrict(&bot, user_id, unmute_date, chat_id).await };
|
||||
|
||||
sender_builder.set_text("Невозможно замьютить участника чата, демотните и попробуйте снова");
|
||||
|
@ -55,7 +56,7 @@ pub async fn mute(
|
|||
{
|
||||
Ok(EventReturn::Cancel)
|
||||
} else {
|
||||
let muted_user_name = message.from().unwrap().clone().username.unwrap();
|
||||
let muted_user_name: String = user.get_user_name(&bot, &message).await.unwrap();
|
||||
|
||||
sender_builder
|
||||
.reply_to(message.id())
|
||||
|
|
|
@ -36,9 +36,11 @@ pub async fn unmute(
|
|||
.await?;
|
||||
Ok(EventReturn::Cancel)
|
||||
} else {
|
||||
let muted_user_name: String = user.get_user_name(&bot, &message).await.unwrap();
|
||||
|
||||
sender_builder
|
||||
.reply_to(message.id())
|
||||
.text("С пользователя был снят мьут.")
|
||||
.text(format!("С пользователя {} был снят мьут.", muted_user_name))
|
||||
.build()
|
||||
.send(&bot)
|
||||
.await
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
use telers::types::Message;
|
||||
use telers::{
|
||||
errors::SessionErrorKind,
|
||||
methods::GetChatMember,
|
||||
types::{ChatMember, Message},
|
||||
Bot,
|
||||
};
|
||||
|
||||
#[derive(Clone, Default, Debug)]
|
||||
pub enum TargetUser {
|
||||
|
@ -22,4 +27,33 @@ impl TargetUser {
|
|||
Self::None => None,
|
||||
}
|
||||
}
|
||||
pub async fn get_user_name(&self, bot: &Bot, msg: &Message) -> Option<String> {
|
||||
match self {
|
||||
Self::Id(id) => {
|
||||
let get_chat_member_result: Result<ChatMember, SessionErrorKind> =
|
||||
bot.send(GetChatMember::new(msg.chat().id(), *id)).await;
|
||||
|
||||
if let Ok(member_kind) = get_chat_member_result {
|
||||
match member_kind {
|
||||
ChatMember::Owner(member) => member.user.username,
|
||||
ChatMember::Administrator(member) => member.user.username,
|
||||
ChatMember::Member(member) => member.user.username,
|
||||
ChatMember::Restricted(member) => member.user.username,
|
||||
ChatMember::Left(member) => member.user.username,
|
||||
ChatMember::Banned(member) => member.user.username,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Self::Reply(msg) => {
|
||||
if let Some(replied_msg) = msg.reply_to_message() {
|
||||
replied_msg.from().unwrap().username.clone()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue