From 4859e72929229e46664a698264f6aa9ba9c5ddce Mon Sep 17 00:00:00 2001 From: Cookie-CHR Date: Wed, 10 Jul 2024 23:33:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=91=20No=20need=20for=20seed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/telegram/commands/answer.rs | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/src/telegram/commands/answer.rs b/src/telegram/commands/answer.rs index ee329873..01f35aac 100644 --- a/src/telegram/commands/answer.rs +++ b/src/telegram/commands/answer.rs @@ -1,6 +1,5 @@ use std::hash::{Hash, Hasher}; use anyhow::{Context}; -use chrono::{DateTime, Utc}; use rand::SeedableRng; use rand::seq::SliceRandom; use teloxide::Bot; @@ -78,38 +77,8 @@ const ANSWERS: [&str; 60] = [ "❔ [RADIO] Mantengo la posizione.", ]; -struct AnswerKey { - seed: chrono::DateTime, -} - -impl Hash for AnswerKey { - fn hash(&self, state: &mut H) { - let seed: i64 = self.seed.timestamp(); - - state.write_i64(seed); - } -} - pub async fn handler(bot: &Bot, message: &Message) -> CommandResult { - let seed = chrono::Utc::now(); - - let key = AnswerKey {seed}; - - let mut hasher = std::hash::DefaultHasher::new(); - key.hash(&mut hasher); - let hash = hasher.finish() - .to_le_bytes() - .into_iter() - .cycle() - .take(32) - .collect::>() - .try_into(); - if hash.is_err() { - anyhow::bail!("Non è stato possibile determinare una risposta."); - } - let hash = hash.unwrap(); - - let mut rng = rand::rngs::SmallRng::from_seed(hash); + let mut rng = rand::rngs::SmallRng::from_entropy(); let answer = ANSWERS.choose(&mut rng) .context("Non è stato possibile selezionare una risposta.")?;