mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-24 20:14:19 +00:00
🐛 Made it actually work
This commit is contained in:
parent
2db26854c9
commit
0d14f25b98
2 changed files with 9 additions and 9 deletions
|
@ -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<Utc>,
|
||||
}
|
||||
|
||||
impl Hash for FortuneKey {
|
||||
impl Hash for AnswerKey {
|
||||
fn hash<H: Hasher>(&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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue