From 0d14f25b98eaccd7c6a7a7df22afa47fd2b07097 Mon Sep 17 00:00:00 2001 From: Cookie-CHR Date: Wed, 10 Jul 2024 00:06:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Made=20it=20actually=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/telegram/commands/answer.rs | 16 ++++++++-------- src/telegram/commands/mod.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) 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() {