diff --git a/src/telegram/commands/answer.rs b/src/telegram/commands/answer.rs index 86ef9234..ee329873 100644 --- a/src/telegram/commands/answer.rs +++ b/src/telegram/commands/answer.rs @@ -1,6 +1,6 @@ use std::hash::{Hash, Hasher}; use anyhow::{Context}; -use chrono::Datelike; +use chrono::{DateTime, Utc}; use rand::SeedableRng; use rand::seq::SliceRandom; use teloxide::Bot; @@ -78,22 +78,22 @@ const ANSWERS: [&str; 60] = [ "❔ [RADIO] Mantengo la posizione.", ]; -struct FortuneKey { - now: chrono::NaiveDate, +struct AnswerKey { + seed: chrono::DateTime, } -impl Hash for FortuneKey { +impl Hash for AnswerKey { fn hash(&self, state: &mut H) { - let now: i32 = self.today.num_days_from_ce(); + let seed: i64 = self.seed.timestamp(); - state.write_i32(now); + state.write_i64(seed); } } pub async fn handler(bot: &Bot, message: &Message) -> CommandResult { - let now = chrono::Local::now().date_naive(); + let seed = chrono::Utc::now(); - let key = FortuneKey {now}; + let key = AnswerKey {seed}; let mut hasher = std::hash::DefaultHasher::new(); key.hash(&mut hasher); diff --git a/src/telegram/commands/mod.rs b/src/telegram/commands/mod.rs index c84cf703..e05c3a2d 100644 --- a/src/telegram/commands/mod.rs +++ b/src/telegram/commands/mod.rs @@ -46,7 +46,7 @@ async fn handle_command(bot: Bot, command: Command, message: Message) -> Command Command::Fortune => fortune::handler(&bot, &message).await, Command::Echo(text) => echo::handler(&bot, &message, &text).await, Command::WhoAmI => whoami::handler(&bot, &message).await, - Command::Answer(question) => answer::handler(&bot, &message).await, + Command::Answer(_question) => answer::handler(&bot, &message).await, }; if result.is_ok() {