REFACTORED: mute and ban action
This commit is contained in:
parent
561d2deb70
commit
820fa21878
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
enums::target_user::TargetUser,
|
enums::target_user::TargetUser,
|
||||||
structs::handler_entity::{ExtractedEntityData, HandlerEntity},
|
structs::handler_entity::{ExtractedEntityData, HandlerEntity},
|
||||||
},
|
},
|
||||||
utils::telegram::try_do::try_restrict,
|
utils::telegram::{get_bot_response_text::get_bot_response_text, try_do::try_restrict},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::telegram::ban_member::ban_chat_member;
|
use crate::utils::telegram::ban_member::ban_chat_member;
|
||||||
|
@ -27,7 +27,7 @@ pub async fn ban(
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => {
|
None => {
|
||||||
sender_builder
|
sender_builder
|
||||||
.text("Ответьте на сообщение, чтобы забанить участника чата.")
|
.text(get_bot_response_text(&message, "забанить", "/ban [ID | REPLY]").unwrap())
|
||||||
.reply_to(message.id())
|
.reply_to(message.id())
|
||||||
.build()
|
.build()
|
||||||
.send(&bot)
|
.send(&bot)
|
||||||
|
|
|
@ -13,7 +13,9 @@ use crate::{
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{
|
||||||
general::get_duration::{get_duration, ExtractedDuration},
|
general::get_duration::{get_duration, ExtractedDuration},
|
||||||
telegram::{restrict::restrict, try_do::try_restrict},
|
telegram::{
|
||||||
|
get_bot_response_text::get_bot_response_text, restrict::restrict, try_do::try_restrict,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ pub async fn mute(
|
||||||
Some(id) => id,
|
Some(id) => id,
|
||||||
None => {
|
None => {
|
||||||
sender_builder
|
sender_builder
|
||||||
.text("Ответьте на сообщение, чтобы замьютить участника чата.")
|
.text(get_bot_response_text(&message, "замьютить", "/mute [ID | REPLY]").unwrap())
|
||||||
.reply_to(message.id())
|
.reply_to(message.id())
|
||||||
.build()
|
.build()
|
||||||
.send(&bot)
|
.send(&bot)
|
||||||
|
|
|
@ -12,7 +12,13 @@ impl TargetUser {
|
||||||
pub fn get_id(&self) -> Option<i64> {
|
pub fn get_id(&self) -> Option<i64> {
|
||||||
match self {
|
match self {
|
||||||
Self::Id(id) => Some(*id),
|
Self::Id(id) => Some(*id),
|
||||||
Self::Reply(msg) => Some(msg.reply_to_message().unwrap().from().unwrap().id),
|
Self::Reply(msg) => {
|
||||||
|
if let Some(replied_msg) = msg.reply_to_message() {
|
||||||
|
replied_msg.from().map(|user| user.id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
Self::None => None,
|
Self::None => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
use telers::{
|
||||||
|
types::Message,
|
||||||
|
utils::text::{html_formatter::Formatter as HTMLFormatter, Builder as TextBuilder},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn get_bot_response_text(
|
||||||
|
msg: &Message,
|
||||||
|
action: impl Into<String>,
|
||||||
|
command: impl Into<String>,
|
||||||
|
) -> Option<String> {
|
||||||
|
match msg {
|
||||||
|
Message::Dice(_) => Some(format!(
|
||||||
|
"Ответьте на сообщение, чтобы {} участника чата.",
|
||||||
|
action.into()
|
||||||
|
)),
|
||||||
|
Message::Text(_) => {
|
||||||
|
let help_response_builder: TextBuilder<HTMLFormatter> =
|
||||||
|
TextBuilder::new(HTMLFormatter::default())
|
||||||
|
.monowidth(command.into())
|
||||||
|
.text(format!(
|
||||||
|
"
|
||||||
|
\n\nВведите либо ID юзера, либо ответьте на \
|
||||||
|
сообщение участника чата, с которого вы хотите {}.
|
||||||
|
",
|
||||||
|
action.into()
|
||||||
|
));
|
||||||
|
|
||||||
|
Some(help_response_builder.get_text().into())
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,5 +2,6 @@ pub mod admin_check;
|
||||||
pub mod ban_member;
|
pub mod ban_member;
|
||||||
pub mod demote;
|
pub mod demote;
|
||||||
pub mod get_all_admins;
|
pub mod get_all_admins;
|
||||||
|
pub mod get_bot_response_text;
|
||||||
pub mod restrict;
|
pub mod restrict;
|
||||||
pub mod try_do;
|
pub mod try_do;
|
||||||
|
|
Loading…
Reference in New Issue