feat(dice): skip only dice message

This commit is contained in:
doryan 2024-08-31 23:30:42 +04:00
parent 2c7abf251f
commit 613b4f10ce

View File

@ -1,8 +1,8 @@
use async_trait::async_trait;
use telers::{
errors::{EventErrorKind, HandlerError},
event::telegram::{HandlerRequest, HandlerResponse},
middlewares::{InnerMiddleware, Next},
event::{telegram::{HandlerRequest, HandlerResponse}, EventReturn},
middlewares::{InnerMiddleware, Next}, types::Message,
};
use anyhow::Error as Reject;
@ -24,6 +24,11 @@ impl InnerMiddleware for AdminCheck {
) -> Result<HandlerResponse, EventErrorKind> {
let (bot, message) = (request.clone().bot, request.clone().update);
let is_replying_dice: Option<Message> = match message.kind().message().unwrap() {
Message::Dice(dice) => dice.reply_to_message.clone(),
_ => None
};
let admins_list = get_all_admins(&bot, message.chat().unwrap().id())
.await
.unwrap();
@ -34,12 +39,13 @@ impl InnerMiddleware for AdminCheck {
let response = next(request).await?;
return Ok(response);
} else {
if is_replying_dice.is_some() {
MessageSender::builder(chat_id)
.text("Недостаточно прав для использования данной команды.")
.build()
.send(&bot)
.build().send(&bot)
.await
.unwrap();
}
return Err(EventErrorKind::Handler(HandlerError::new(Reject::msg(
"User isn't admin.".to_string(),