fix alreadyhitleet check and add time command
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
419335f78f
commit
269630115b
31
src/main.rs
31
src/main.rs
@ -1,7 +1,7 @@
|
||||
mod lib;
|
||||
use crate::lib::{text_is_leet, time_is_leet};
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
use chrono::{NaiveDateTime, NaiveTime, Local};
|
||||
use sqlx::AnyPool;
|
||||
use sqlx::any::AnyPoolOptions;
|
||||
use teloxide::{prelude::*, RequestError, dispatching::UpdateFilterExt, utils::command::BotCommands};
|
||||
@ -61,7 +61,7 @@ async fn check_leet(username: &str, sent_time: NaiveDateTime, pool: &AnyPool) ->
|
||||
if let Some(latest_leet) = latest_leet {
|
||||
let distance = sent_time - latest_leet.2;
|
||||
|
||||
if distance.num_hours() < 24 {
|
||||
if distance.num_hours() < 1 {
|
||||
return Err(LeetError::AlreadyHitLeet);
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,9 @@ fn message_ok() -> Result<(), MessageHandlerError> {
|
||||
#[command(rename = "lowercase", description = "score commands")]
|
||||
enum LeetCommand {
|
||||
#[command(description = "get scores")]
|
||||
Scores
|
||||
Scores,
|
||||
#[command(description = "get current time info")]
|
||||
Time
|
||||
}
|
||||
|
||||
#[derive(Error,Debug)]
|
||||
@ -132,7 +134,9 @@ async fn leet_message_handler(message: Message, bot: AutoSend<Bot>, pool: AnyPoo
|
||||
.username.clone()
|
||||
.ok_or(MessageHandlerError::NoUsername)?;
|
||||
|
||||
let message_sent_time = message.date.naive_local();
|
||||
let message_sent_time = message.date
|
||||
.with_timezone(&Local)
|
||||
.naive_local();
|
||||
|
||||
let leet_check = check_leet(&username, message_sent_time, &pool).await;
|
||||
|
||||
@ -171,6 +175,25 @@ async fn leet_command_handler(message: Message, cmd: LeetCommand, bot: AutoSend<
|
||||
|
||||
let msg = format!("Leet scores:\n{}", scores_str);
|
||||
|
||||
bot.send_message(message.chat.id, msg).await?;
|
||||
},
|
||||
LeetCommand::Time => {
|
||||
let message_time = message.date
|
||||
.with_timezone(&Local)
|
||||
.naive_local();
|
||||
let current_time = Local::now().time();
|
||||
let leet_time = NaiveTime::from_hms(13,37,30);
|
||||
let distance_to_leet = leet_time - current_time;
|
||||
|
||||
let msg = format!("My current time is: {}
|
||||
message was sent at: {}
|
||||
leet is at: {}, in {} seconds",
|
||||
current_time,
|
||||
message_time,
|
||||
leet_time,
|
||||
distance_to_leet.num_seconds()
|
||||
);
|
||||
|
||||
bot.send_message(message.chat.id, msg).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user