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