gluon/src/handlers/dice_handler/dice.rs

51 lines
1.4 KiB
Rust

use telers::{
event::{telegram::HandlerResult, EventReturn},
types::{Dice, Message},
Bot,
};
use crate::{
handlers::actions::{ban::ban, mute::mute},
types::{
enums::time_metrics::TimeMetrics,
structs::{bot_entity::BotEntity, 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 bot_entity: BotEntity = BotEntity {
bot_instance: bot,
receive_message: message,
message_sender: MessageSender::new(chat_id),
};
let (mute_time, emoji): (TimeMetrics, &str) = (TimeMetrics::Days(dice.value), &dice.emoji);
match emoji {
"🎲" => {
mute(bot_entity, (mute_time, DICE_DELAY_MS)).await?;
}
"🎰" => {
if dice.value == 64 {
ban(bot_entity, CASINO_DELAY_MS).await?;
} else {
mute(bot_entity, (mute_time, CASINO_DELAY_MS)).await?;
}
}
_ => {
bot_entity
.message_sender
.text("Такой эмодзи не имеет привязки к какому либо действию бота.")
.send(&bot_entity.bot_instance)
.await?;
}
}
Ok(EventReturn::Finish)
}