68 lines
2.0 KiB
Rust
68 lines
2.0 KiB
Rust
use telers::{
|
|
event::{telegram::HandlerResult, EventReturn},
|
|
types::{Dice, Message},
|
|
Bot,
|
|
};
|
|
|
|
use crate::{
|
|
handlers::actions::{ban::ban_member, mute::mute_member},
|
|
types::{
|
|
enums::{target_user::TargetUser, time_metrics::TimeMetrics},
|
|
structs::{handler_entity::HandlerEntity, message_sender::MessageSender},
|
|
},
|
|
};
|
|
|
|
const DICE_DELAY_MS: u64 = 4000u64;
|
|
const CASINO_DELAY_MS: u64 = 1500u64;
|
|
|
|
pub async fn dice_handler(bot: Bot, message: Message) -> HandlerResult {
|
|
let (chat_id, dice): (i64, Dice) = (message.chat().id(), message.dice().unwrap().clone());
|
|
|
|
let sender = MessageSender::builder(chat_id);
|
|
let handler_entity: HandlerEntity = HandlerEntity::new(bot, message, sender);
|
|
|
|
let (mute_time, emoji): (TimeMetrics, &str) = (TimeMetrics::Days(dice.value), &dice.emoji);
|
|
|
|
let target: TargetUser = TargetUser::Reply(handler_entity.message_reciever.clone());
|
|
|
|
if !target.exist() {
|
|
handler_entity
|
|
.message_sender_builder
|
|
.text("Нет ответа на сообщение пользователя.")
|
|
.build()
|
|
.send(&handler_entity.bot_instance)
|
|
.await?;
|
|
|
|
return Ok(EventReturn::Cancel);
|
|
}
|
|
|
|
match emoji {
|
|
"🎲" => {
|
|
mute_member(handler_entity, chat_id, target, (mute_time, DICE_DELAY_MS)).await?;
|
|
}
|
|
"🎰" => {
|
|
if dice.value == 64 {
|
|
ban_member(handler_entity, chat_id, target, CASINO_DELAY_MS).await?;
|
|
} else {
|
|
mute_member(
|
|
handler_entity,
|
|
chat_id,
|
|
target,
|
|
(mute_time, CASINO_DELAY_MS),
|
|
)
|
|
.await?;
|
|
}
|
|
}
|
|
_ => {
|
|
handler_entity
|
|
.message_sender_builder
|
|
.text("Эмодзи не имеет привязанных действий.")
|
|
.build()
|
|
.send(&handler_entity.bot_instance)
|
|
.await?;
|
|
}
|
|
}
|
|
|
|
Ok(EventReturn::Finish)
|
|
}
|