From d54b6003915d84d527b8f63a2b1b869f238afb2c Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 18 Aug 2022 20:51:37 +0200 Subject: [PATCH] Format schedule.rs seems to have forgotten for previous commit --- src/commands/schedule.rs | 65 +++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/commands/schedule.rs b/src/commands/schedule.rs index f155c38..ce5da4c 100644 --- a/src/commands/schedule.rs +++ b/src/commands/schedule.rs @@ -1,7 +1,7 @@ use crate::{commands::utils, Context, Error}; use cached::proc_macro::cached; use chrono::{DateTime, Utc}; -use log::{warn}; +use log::warn; use reqwest::header::AUTHORIZATION; use serde::Deserialize; @@ -30,11 +30,19 @@ impl MSEvent { fn get_value(&self, high_tier: bool) -> String { 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 { "".to_string() }; - format!("{link}Start: \nEnd:  ", link=link, start=self.metadata.attributes.start.timestamp(), end=self.metadata.attributes.end.timestamp()) + format!( + "{link}Start: \nEnd:  ", + link = link, + start = self.metadata.attributes.start.timestamp(), + end = self.metadata.attributes.end.timestamp() + ) } } @@ -42,48 +50,41 @@ impl MSEvent { struct MSMetadata { // id: String, // system: System, - #[serde(rename="emfAttributes")] + #[serde(rename = "emfAttributes")] attributes: EmfAttributes, - #[serde(rename="titleBrief")] + #[serde(rename = "titleBrief")] brief: String, // #[serde(rename="Series")] // series: String, } - #[derive(Deserialize, Clone)] struct EmfAttributes { #[serde(with = "ms_date")] - #[serde(rename="sessionStartDate")] + #[serde(rename = "sessionStartDate")] start: DateTime, #[serde(with = "ms_date")] - #[serde(rename="sessionEndDate")] + #[serde(rename = "sessionEndDate")] end: DateTime, - #[serde(rename="Series")] + #[serde(rename = "Series")] series: String, } - - - mod ms_date { - use chrono::{DateTime, Utc, NaiveDateTime}; + use chrono::{DateTime, NaiveDateTime, Utc}; use serde::{self, Deserialize, Deserializer}; pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { - let n = i64::deserialize(deserializer)?/1000; + let n = i64::deserialize(deserializer)? / 1000; // let s = String::deserialize(deserializer)?; - + Ok(DateTime::from_utc(NaiveDateTime::from_timestamp(n, 0), Utc)) - - } } - #[cached(time = 3600)] async fn get_schedule() -> Option { let token = super::super::SETTINGS @@ -136,24 +137,26 @@ async fn get_schedule() -> Option { } #[poise::command(slash_command)] -pub async fn schedule( - ctx: Context<'_>, -) -> Result<(), Error> { +pub async fn schedule(ctx: Context<'_>) -> Result<(), Error> { let events: Option = get_schedule().await; let ht: bool = utils::high_tier(ctx).await; match events { - None => {ctx.say("Error on fetching events :(").await?;}, + None => { + ctx.say("Error on fetching events :(").await?; + } Some(evs) => { - ctx.send(|b| {b.embed(|e| { - e.title(format!("F1 schedule: {}", evs.event_title)); - for event in evs.containers { - e.field(event.get_title(), event.get_value(ht), true); - }; - e - })}).await?; + ctx.send(|b| { + b.embed(|e| { + e.title(format!("F1 schedule: {}", evs.event_title)); + for event in evs.containers { + e.field(event.get_title(), event.get_value(ht), true); + } + e + }) + }) + .await?; } }; Ok(()) - -} \ No newline at end of file +}