Fix in eurosport (wrong attribute for event time)
And some cleanup (also removing replays)
This commit is contained in:
parent
c3e171e917
commit
04eff6824c
|
@ -1,12 +1,11 @@
|
|||
use crate::{Context, Error};
|
||||
use cached::proc_macro::cached;
|
||||
use rand::seq::IteratorRandom;
|
||||
use serde_json::{
|
||||
Map,
|
||||
Value::{self, Object},
|
||||
};
|
||||
use std::fs;
|
||||
use rand::seq::IteratorRandom;
|
||||
|
||||
|
||||
async fn autocomplete_command<'a>(
|
||||
_ctx: Context<'_>,
|
||||
|
@ -52,7 +51,6 @@ pub async fn coms(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn sky(input: &str) -> String {
|
||||
let result: String = input.to_string();
|
||||
let mut rng = rand::thread_rng();
|
||||
|
@ -62,7 +60,14 @@ fn sky(input: &str) -> String {
|
|||
Some((left, end)) => {
|
||||
match sky_closed(&end) {
|
||||
None => return result,
|
||||
Some((mid, right)) => return sky(&format!("{}{}{}", left, mid.split('|').choose(&mut rng).unwrap(), right))
|
||||
Some((mid, right)) => {
|
||||
return sky(&format!(
|
||||
"{}{}{}",
|
||||
left,
|
||||
mid.split('|').choose(&mut rng).unwrap(),
|
||||
right
|
||||
))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +85,7 @@ fn sky_open(input: &str) -> Option<(String, String)> {
|
|||
let mut end: String = end.to_string();
|
||||
end.push('{');
|
||||
end.push_str(right.as_str());
|
||||
return Some((left.to_owned(), end))
|
||||
return Some((left.to_owned(), end));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
@ -101,7 +106,7 @@ fn sky_closed(input: &str) -> Option<(String, String)> {
|
|||
let mut start: String = left.to_string();
|
||||
start.push('}');
|
||||
start.push_str(mid.as_str());
|
||||
return Some((start, right.to_owned()))
|
||||
return Some((start, right.to_owned()));
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
@ -109,4 +114,4 @@ fn sky_closed(input: &str) -> Option<(String, String)> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,23 +27,21 @@ mod es_date_time {
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct VideoAttributes {
|
||||
// #[serde(rename = "earliestPlayableStart")]
|
||||
// #[serde(with = "es_date_time")]
|
||||
// earliest_playable_start: DateTime<Utc>,
|
||||
name: String,
|
||||
#[serde(rename = "secondaryTitle")]
|
||||
#[serde(default)]
|
||||
secondary: String,
|
||||
#[serde(rename = "publishEnd")]
|
||||
#[serde(rename = "scheduleEnd")]
|
||||
#[serde(with = "es_date_time")]
|
||||
publish_end: DateTime<Utc>,
|
||||
#[serde(rename = "publishStart")]
|
||||
schedule_end: DateTime<Utc>,
|
||||
#[serde(rename = "scheduleStart")]
|
||||
#[serde(with = "es_date_time")]
|
||||
publish_start: DateTime<Utc>,
|
||||
schedule_start: DateTime<Utc>,
|
||||
#[serde(default)]
|
||||
description: String,
|
||||
// #[serde(rename = "drmEnabled")]
|
||||
// drm_enabled: bool,
|
||||
#[serde(default)]
|
||||
#[serde(rename = "broadcastType")]
|
||||
broadcast_type: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -66,7 +64,6 @@ struct VideoRelations {
|
|||
#[derive(Deserialize, Debug)]
|
||||
struct TaxonomyNodeAttributes {
|
||||
name: String,
|
||||
// kind: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -119,8 +116,6 @@ struct ESEvents {
|
|||
description: String,
|
||||
start: DateTime<Utc>,
|
||||
end: DateTime<Utc>,
|
||||
// early_start: DateTime<Utc>,
|
||||
// drm_enabled: bool,
|
||||
}
|
||||
|
||||
impl ESEvents {
|
||||
|
@ -152,6 +147,31 @@ impl ESEvents {
|
|||
_ => self.end >= now,
|
||||
}
|
||||
}
|
||||
|
||||
fn to_string(&self) -> String {
|
||||
match &self.sport {
|
||||
// None => format!("```md\n({}) {}```\n", self.name, self.secondary),
|
||||
None => format!(
|
||||
"```md\n({}) {}```(<t:{}:R>-<t:{}:R>) {}\n https://tom.al/ms/euro/{}",
|
||||
self.name,
|
||||
self.secondary,
|
||||
self.start.timestamp(),
|
||||
self.end.timestamp(),
|
||||
self.description,
|
||||
self.id,
|
||||
),
|
||||
Some(sport) => format!(
|
||||
"```md\n[{}]({}) {}```(<t:{}:R>-<t:{}:R>) {}\n https://tom.al/ms/euro/{}",
|
||||
sport,
|
||||
self.name,
|
||||
self.secondary,
|
||||
self.start.timestamp(),
|
||||
self.end.timestamp(),
|
||||
self.description,
|
||||
self.id,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_events(v: Eurosport) -> Result<Vec<ESEvents>, serde_json::Error> {
|
||||
|
@ -181,8 +201,10 @@ fn get_events(v: Eurosport) -> Result<Vec<ESEvents>, serde_json::Error> {
|
|||
relationships,
|
||||
} = node
|
||||
{
|
||||
// sports.insert(id.to_string(), attributes.name.to_string());
|
||||
|
||||
// Skip videos tagged as replay, these don't play as nicely
|
||||
if attributes.broadcast_type.eq_ignore_ascii_case("replay") {
|
||||
continue;
|
||||
};
|
||||
let sport_name = match &relationships.sport_id {
|
||||
None => None,
|
||||
Some(sport_id) => match sport_id.data.get(0) {
|
||||
|
@ -199,10 +221,8 @@ fn get_events(v: Eurosport) -> Result<Vec<ESEvents>, serde_json::Error> {
|
|||
name: attributes.name.to_string(),
|
||||
secondary: attributes.secondary.to_string(),
|
||||
description: attributes.description.to_string(),
|
||||
start: attributes.publish_start,
|
||||
end: attributes.publish_end,
|
||||
// early_start: attributes.earliest_playable_start,
|
||||
// drm_enabled: attributes.drm_enabled,
|
||||
start: attributes.schedule_start,
|
||||
end: attributes.schedule_end,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -211,38 +231,6 @@ fn get_events(v: Eurosport) -> Result<Vec<ESEvents>, serde_json::Error> {
|
|||
return Ok(events);
|
||||
}
|
||||
|
||||
fn stringify_events(events: Vec<ESEvents>) -> Vec<String> {
|
||||
let mut result = vec![];
|
||||
for event in events {
|
||||
result.push(match event.sport {
|
||||
// None => format!("```md\n({}) {}```\n", event.name, event.secondary),
|
||||
None => format!(
|
||||
"```md\n({}) {}```(<t:{}:R>-<t:{}:R>) {}\n https://tom.al/ms/euro/{} https://tom.al/ms/euro/{}",
|
||||
event.name,
|
||||
event.secondary,
|
||||
event.start.timestamp(),
|
||||
event.end.timestamp(),
|
||||
event.description,
|
||||
event.id,
|
||||
event.id
|
||||
),
|
||||
Some(sport) => format!(
|
||||
"```md\n[{}]({}) {}```(<t:{}:R>-<t:{}:R>) {}\n https://tom.al/ms/euro/{} https://tom.al/ms/euro/{}",
|
||||
sport,
|
||||
event.name,
|
||||
event.secondary,
|
||||
event.start.timestamp(),
|
||||
event.end.timestamp(),
|
||||
event.description,
|
||||
event.id,
|
||||
event.id
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#[cached(time = 3600)]
|
||||
#[allow(dead_code)]
|
||||
async fn get_eurosport_events(url: String) -> Option<Vec<ESEvents>> {
|
||||
|
@ -289,10 +277,7 @@ async fn get_eurosport_events(url: String) -> Option<Vec<ESEvents>> {
|
|||
warn!("Error getting Eurosport schedule {}", e);
|
||||
None
|
||||
}
|
||||
Ok(events) => {
|
||||
// events.sort_by(|a: ESEvents, b: ESEvents| b.start.cmp(a));
|
||||
Some(events)
|
||||
}
|
||||
Ok(events) => Some(events),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -302,65 +287,6 @@ async fn get_eurosport_events(url: String) -> Option<Vec<ESEvents>> {
|
|||
return result;
|
||||
}
|
||||
|
||||
// #[derive(Debug, poise::ChoiceParameter)]
|
||||
// pub enum Timeframe {
|
||||
// #[name = "Currently happening"]
|
||||
// Current,
|
||||
// #[name = "Currently happening or starting in the future"]
|
||||
// Future,
|
||||
// #[name = "Currently happening or already ended"]
|
||||
// Past,
|
||||
// #[name = "Everything"]
|
||||
// Everything,
|
||||
// }
|
||||
|
||||
// /// Eurosport player events
|
||||
// #[poise::command(slash_command)]
|
||||
// pub async fn eurosport(
|
||||
// ctx: Context<'_>,
|
||||
// #[description = "Filter sessions for when they are/were happening, defaults to future"]
|
||||
// timeframe: Option<Timeframe>,
|
||||
// #[description = "Content to filter on"] filter: Option<String>,
|
||||
// ) -> Result<(), Error> {
|
||||
// if !utils::high_tier(ctx.channel_id()) {
|
||||
// ctx.say("This command can only be used in high tier channels for security")
|
||||
// .await?;
|
||||
// return Ok(());
|
||||
// }
|
||||
// let url = super::super::super::SETTINGS
|
||||
// .read()
|
||||
// .unwrap()
|
||||
// .get_table("eurosport")
|
||||
// .expect("Expecting an eurosport section in the config")
|
||||
// .get("url")
|
||||
// .expect("Config error, please set the eurosport[url] value")
|
||||
// .clone()
|
||||
// .into_str()
|
||||
// .expect("Config error, please make sure eurosport[url] is a string");
|
||||
// let events = get_eurosport_events(url).await;
|
||||
// match events {
|
||||
// None => {
|
||||
// ctx.say("Oh no something went wrong").await?;
|
||||
// }
|
||||
// Some(evs) => {
|
||||
// info!("Found {} events from eurosport", evs.len());
|
||||
// let strings = stringify_events(
|
||||
// evs.into_iter()
|
||||
// .filter(|e| e.comp(&timeframe))
|
||||
// .filter(|e| match &filter {
|
||||
// None => true,
|
||||
// Some(f) => e.filter(f.as_str()),
|
||||
// })
|
||||
// .collect(),
|
||||
// );
|
||||
// let pages = utils::paginator(strings, 1900, "\n".to_string());
|
||||
|
||||
// utils::paginate_string(ctx, pages).await?;
|
||||
// }
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
// Eurosport player events
|
||||
#[poise::command(slash_command)]
|
||||
pub async fn eurosport(
|
||||
|
@ -386,15 +312,15 @@ pub async fn eurosport(
|
|||
}
|
||||
Some(evs) => {
|
||||
info!("Found {} events from eurosport", evs.len());
|
||||
let strings = stringify_events(
|
||||
evs.into_iter()
|
||||
.filter(|e| e.comp(&timeframe))
|
||||
.filter(|e| match &filter {
|
||||
None => true,
|
||||
Some(f) => e.filter(f.as_str()),
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
let strings = evs
|
||||
.into_iter()
|
||||
.filter(|e| e.comp(&timeframe))
|
||||
.filter(|e| match &filter {
|
||||
None => true,
|
||||
Some(f) => e.filter(f.as_str()),
|
||||
})
|
||||
.map(|e| e.to_string())
|
||||
.collect();
|
||||
let pages = utils::paginator(strings, 1900, "\n".to_string());
|
||||
|
||||
utils::paginate_string(ctx, pages).await?;
|
||||
|
@ -403,59 +329,6 @@ pub async fn eurosport(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// /// Eurosport olympics events
|
||||
// #[poise::command(slash_command)]
|
||||
// pub async fn olympics(
|
||||
// ctx: Context<'_>,
|
||||
// #[description = "Filter sessions for when they are/were happening, defaults to future"]
|
||||
// timeframe: Option<Timeframe>,
|
||||
// #[description = "Content to filter on"] filter: Option<String>,
|
||||
// ) -> Result<(), Error> {
|
||||
// // if !utils::high_tier(ctx.channel_id()) {
|
||||
// // ctx.say("This command can only be used in high tier channels for security")
|
||||
// // .await?;
|
||||
// // return Ok(());
|
||||
// // }
|
||||
// if !utils::high_tier_mess(ctx).await {
|
||||
// ctx.say("This command can only be used in high tier channels for security")
|
||||
// .await?;
|
||||
// return Ok(());
|
||||
// }
|
||||
// let url = super::super::super::SETTINGS
|
||||
// .read()
|
||||
// .unwrap()
|
||||
// .get_table("eurosport")
|
||||
// .expect("Expecting an eurosport section in the config")
|
||||
// .get("olympics")
|
||||
// .expect("Config error, please set the eurosport[olympics] value")
|
||||
// .clone()
|
||||
// .into_str()
|
||||
// .expect("Config error, please make sure eurosport[olympics] is a string");
|
||||
// let events = get_eurosport_events(url).await;
|
||||
// match events {
|
||||
// None => {
|
||||
// ctx.say("Oh no something went wrong").await?;
|
||||
// }
|
||||
// Some(evs) => {
|
||||
// info!("Found {} events from eurosport olympics ", evs.len());
|
||||
// let strings = stringify_events(
|
||||
// evs.into_iter()
|
||||
// .filter(|e| e.comp(&timeframe))
|
||||
// .filter(|e| match &filter {
|
||||
// None => true,
|
||||
// Some(f) => e.filter(f.as_str()),
|
||||
// })
|
||||
// .collect(),
|
||||
// );
|
||||
// let pages = utils::paginator(strings, 1900, "\n".to_string());
|
||||
|
||||
// utils::paginate_string(ctx, pages).await?;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
/// Eurosport olympics events
|
||||
#[allow(dead_code)]
|
||||
pub async fn proc_olympics(
|
||||
|
@ -480,15 +353,15 @@ pub async fn proc_olympics(
|
|||
}
|
||||
Some(evs) => {
|
||||
info!("Found {} events from eurosport olympics ", evs.len());
|
||||
let strings = stringify_events(
|
||||
evs.into_iter()
|
||||
.filter(|e| e.comp(&timeframe))
|
||||
.filter(|e| match &filter {
|
||||
None => true,
|
||||
Some(f) => e.filter(f.as_str()),
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
let strings = evs
|
||||
.into_iter()
|
||||
.filter(|e| e.comp(&timeframe))
|
||||
.filter(|e| match &filter {
|
||||
None => true,
|
||||
Some(f) => e.filter(f.as_str()),
|
||||
})
|
||||
.map(|e| e.to_string())
|
||||
.collect();
|
||||
let pages = utils::paginator(strings, 1900, "\n".to_string());
|
||||
|
||||
utils::paginate_string(ctx, pages).await?;
|
||||
|
|
Loading…
Reference in a new issue