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]
name = "dorya"
version = "0.2"
version = "0.2.0"
edition = "2021"
# 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;
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 };

View File

@ -25,7 +25,10 @@ pub async fn mute_member(
) -> HandlerResult {
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;

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());
handler_entity
.message_sender_builder
.set_text("Нет ответа на сообщение пользователя.");
match emoji {
"🎲" => {
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 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 {
MessageSender::builder(chat_id)
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(),