Format schedule.rs seems to have forgotten for previous commit

This commit is contained in:
Tom 2022-08-18 20:51:37 +02:00
parent 022a1d8991
commit d54b600391

View file

@ -1,7 +1,7 @@
use crate::{commands::utils, Context, Error}; use crate::{commands::utils, Context, Error};
use cached::proc_macro::cached; use cached::proc_macro::cached;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use log::{warn}; use log::warn;
use reqwest::header::AUTHORIZATION; use reqwest::header::AUTHORIZATION;
use serde::Deserialize; use serde::Deserialize;
@ -30,11 +30,19 @@ impl MSEvent {
fn get_value(&self, high_tier: bool) -> String { fn get_value(&self, high_tier: bool) -> String {
let link = if high_tier { let link = if high_tier {
format!("[{id}](https://morningstreams.com/hightier/f1/session/{id})\n", id=self.id) format!(
"[{id}](https://morningstreams.com/hightier/f1/session/{id})\n",
id = self.id
)
} else { } else {
"".to_string() "".to_string()
}; };
format!("{link}Start: <t:{start}:R>\nEnd: <t:{end}:R>", link=link, start=self.metadata.attributes.start.timestamp(), end=self.metadata.attributes.end.timestamp()) format!(
"{link}Start: <t:{start}:R>\nEnd: <t:{end}:R>",
link = link,
start = self.metadata.attributes.start.timestamp(),
end = self.metadata.attributes.end.timestamp()
)
} }
} }
@ -50,7 +58,6 @@ struct MSMetadata {
// series: String, // series: String,
} }
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone)]
struct EmfAttributes { struct EmfAttributes {
#[serde(with = "ms_date")] #[serde(with = "ms_date")]
@ -63,11 +70,8 @@ struct EmfAttributes {
series: String, series: String,
} }
mod ms_date { mod ms_date {
use chrono::{DateTime, Utc, NaiveDateTime}; use chrono::{DateTime, NaiveDateTime, Utc};
use serde::{self, Deserialize, Deserializer}; use serde::{self, Deserialize, Deserializer};
pub fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error> pub fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
@ -78,12 +82,9 @@ mod ms_date {
// let s = String::deserialize(deserializer)?; // let s = String::deserialize(deserializer)?;
Ok(DateTime::from_utc(NaiveDateTime::from_timestamp(n, 0), Utc)) Ok(DateTime::from_utc(NaiveDateTime::from_timestamp(n, 0), Utc))
} }
} }
#[cached(time = 3600)] #[cached(time = 3600)]
async fn get_schedule() -> Option<MSReq> { async fn get_schedule() -> Option<MSReq> {
let token = super::super::SETTINGS let token = super::super::SETTINGS
@ -136,24 +137,26 @@ async fn get_schedule() -> Option<MSReq> {
} }
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub async fn schedule( pub async fn schedule(ctx: Context<'_>) -> Result<(), Error> {
ctx: Context<'_>,
) -> Result<(), Error> {
let events: Option<MSReq> = get_schedule().await; let events: Option<MSReq> = get_schedule().await;
let ht: bool = utils::high_tier(ctx).await; let ht: bool = utils::high_tier(ctx).await;
match events { match events {
None => {ctx.say("Error on fetching events :(").await?;}, None => {
ctx.say("Error on fetching events :(").await?;
}
Some(evs) => { Some(evs) => {
ctx.send(|b| {b.embed(|e| { ctx.send(|b| {
b.embed(|e| {
e.title(format!("F1 schedule: {}", evs.event_title)); e.title(format!("F1 schedule: {}", evs.event_title));
for event in evs.containers { for event in evs.containers {
e.field(event.get_title(), event.get_value(ht), true); e.field(event.get_title(), event.get_value(ht), true);
}; }
e e
})}).await?; })
})
.await?;
} }
}; };
Ok(()) Ok(())
} }