FIXED: Finish message after bot action

This commit is contained in:
doryan 2024-06-02 14:22:30 +04:00
parent 820fa21878
commit f625fc7960
4 changed files with 42 additions and 12 deletions

View File

@ -50,14 +50,7 @@ pub async fn ban(
{ {
Ok(EventReturn::Cancel) Ok(EventReturn::Cancel)
} else { } else {
let banned_user_name: String = message let banned_user_name: String = user.get_user_name(&bot, &message).await.unwrap();
.reply_to_message()
.unwrap()
.from()
.unwrap()
.clone()
.username
.unwrap();
sender_builder sender_builder
.reply_to(message.id()) .reply_to(message.id())

View File

@ -7,7 +7,7 @@ use tokio::time::{sleep, Duration};
use crate::{ use crate::{
types::{ types::{
enums::target_user::TargetUser, enums::target_user::{self, TargetUser},
structs::handler_entity::{ExtractedEntityData, HandlerEntity}, structs::handler_entity::{ExtractedEntityData, HandlerEntity},
TimeValues, TimeValues,
}, },
@ -45,6 +45,7 @@ pub async fn mute(
let (unmute_date, postfix, mute_duration): ExtractedDuration = get_duration(time); let (unmute_date, postfix, mute_duration): ExtractedDuration = get_duration(time);
let demote_args: (&Bot, i64, i64) = (&bot, user_id, chat_id); let demote_args: (&Bot, i64, i64) = (&bot, user_id, chat_id);
let callback = || async { restrict(&bot, user_id, unmute_date, chat_id).await }; let callback = || async { restrict(&bot, user_id, unmute_date, chat_id).await };
sender_builder.set_text("Невозможно замьютить участника чата, демотните и попробуйте снова"); sender_builder.set_text("Невозможно замьютить участника чата, демотните и попробуйте снова");
@ -55,7 +56,7 @@ pub async fn mute(
{ {
Ok(EventReturn::Cancel) Ok(EventReturn::Cancel)
} else { } 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 sender_builder
.reply_to(message.id()) .reply_to(message.id())

View File

@ -36,9 +36,11 @@ pub async fn unmute(
.await?; .await?;
Ok(EventReturn::Cancel) Ok(EventReturn::Cancel)
} else { } else {
let muted_user_name: String = user.get_user_name(&bot, &message).await.unwrap();
sender_builder sender_builder
.reply_to(message.id()) .reply_to(message.id())
.text("С пользователя был снят мьут.") .text(format!("С пользователя {} был снят мьут.", muted_user_name))
.build() .build()
.send(&bot) .send(&bot)
.await .await

View File

@ -1,4 +1,9 @@
use telers::types::Message; use telers::{
errors::SessionErrorKind,
methods::GetChatMember,
types::{ChatMember, Message},
Bot,
};
#[derive(Clone, Default, Debug)] #[derive(Clone, Default, Debug)]
pub enum TargetUser { pub enum TargetUser {
@ -22,4 +27,33 @@ impl TargetUser {
Self::None => None, 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,
}
}
} }