Compare commits

...

4 Commits

Author SHA1 Message Date
doryan 9029d4397a feat: change version 2024-08-31 23:30:53 +04:00
doryan 613b4f10ce feat(dice): skip only dice message 2024-08-31 23:30:42 +04:00
doryan 2c7abf251f feat(id): add user_id check 2024-08-31 23:30:17 +04:00
doryan f81bc8d3ce feat(msg): remove redundant message 2024-08-31 23:29:29 +04:00
5 changed files with 20 additions and 12 deletions

View File

@ -5,7 +5,7 @@ overflow-checks = false
[package] [package]
name = "dorya" name = "dorya"
version = "0.2" version = "0.2.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -24,7 +24,10 @@ pub async fn ban_member(
sleep(DurationSleep::from_millis(delay)).await; sleep(DurationSleep::from_millis(delay)).await;
let user_id: i64 = user.get_id().unwrap(); let user_id: i64 = match user.get_id() {
Some(id) => id,
None => return Ok(EventReturn::Skip)
};
let callback = || async { bot.send(BanChatMember::new(chat_id, user_id)).await }; let callback = || async { bot.send(BanChatMember::new(chat_id, user_id)).await };

View File

@ -25,7 +25,10 @@ pub async fn mute_member(
) -> HandlerResult { ) -> HandlerResult {
let (bot, message, mut sender_builder): ExtractedEntityData = handler_entity.extract(); let (bot, message, mut sender_builder): ExtractedEntityData = handler_entity.extract();
let user_id: i64 = user.get_id().unwrap(); let user_id: i64 = match user.get_id() {
Some(id) => id,
None => return Ok(EventReturn::Skip)
};
sleep(Duration::from_millis(time.1)).await; sleep(Duration::from_millis(time.1)).await;

View File

@ -25,10 +25,6 @@ pub async fn dice_handler(bot: Bot, message: Message) -> HandlerResult {
let target = TargetUser::Reply(handler_entity.message_reciever.clone()); let target = TargetUser::Reply(handler_entity.message_reciever.clone());
handler_entity
.message_sender_builder
.set_text("Нет ответа на сообщение пользователя.");
match emoji { match emoji {
"🎲" => { "🎲" => {
mute_member(handler_entity, chat_id, target, (mute_time, DICE_DELAY_MS)).await?; mute_member(handler_entity, chat_id, target, (mute_time, DICE_DELAY_MS)).await?;

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 {
MessageSender::builder(chat_id) if is_replying_dice.is_some() {
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(),