From 5e6ea6a57dc212d4bbeb1995c8480bba9cb32c37 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sun, 10 Nov 2024 12:33:25 -0500 Subject: [PATCH] added template roster and gamedetail commands --- src/commands/conference.rs | 0 src/commands/game.rs | 2 +- src/commands/gamedetail.rs | 46 +++++++++++++++++++++++++++++++++++++ src/commands/mod.rs | 3 +++ src/commands/roster.rs | 47 ++++++++++++++++++++++++++++++++++++++ src/commands/team.rs | 4 ++-- src/main.rs | 2 +- 7 files changed, 100 insertions(+), 4 deletions(-) delete mode 100644 src/commands/conference.rs create mode 100644 src/commands/gamedetail.rs create mode 100644 src/commands/roster.rs diff --git a/src/commands/conference.rs b/src/commands/conference.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/commands/game.rs b/src/commands/game.rs index 22b6b7c..c9a1925 100644 --- a/src/commands/game.rs +++ b/src/commands/game.rs @@ -73,7 +73,7 @@ pub async fn run(options: &[ResolvedOption<'_>]) -> String { pub fn register() -> CreateCommand { CreateCommand::new("game") - .description("Get the next game's information by specifying a team name") + .description("Get the upcoming/current NFL game information given a NFL team") .add_option( CreateCommandOption::new( CommandOptionType::String, diff --git a/src/commands/gamedetail.rs b/src/commands/gamedetail.rs new file mode 100644 index 0000000..2fbab6c --- /dev/null +++ b/src/commands/gamedetail.rs @@ -0,0 +1,46 @@ +use crate::{ + types, + util::{junk, nfl, request}, +}; + +use serenity::builder::{CreateCommand, CreateCommandOption}; +use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue}; + +pub async fn run(options: &[ResolvedOption<'_>]) -> String { + if let Some(ResolvedOption { + value: ResolvedValue::String(team), + .. + }) = options.first() + { + // TODO: get game detail here, like total score, game leaders, play by play, etc. + String::new() + } else { + junk::get_random_insult() + } +} + +pub fn register() -> CreateCommand { + CreateCommand::new("gamedetail") + .description("Get the upcoming/current NFL game details given a NFL team such as total score, game leaders, play-by-play, and more") + .add_option( + CreateCommandOption::new(CommandOptionType::String, "team", "The team to query") + .required(true), + ) +} + +pub struct GameDetailDiscordResponse { + pub team_name: String, + pub record: String, + pub next_event: String, + pub game_date: String, + pub standing: String, +} + +impl GameDetailDiscordResponse { + pub fn format(&self) -> String { + format!( + "## {:}\nSeason Record (W-L): {:}\nNext Game: {:}\nNext Game Date: {:}\nStanding: {:}", + self.team_name, self.record, self.next_event, self.game_date, self.standing + ) + } +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index cdd5a4d..9a04b24 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,6 @@ pub mod about; pub mod game; +pub mod gamedetail; +pub mod roster; pub mod team; + diff --git a/src/commands/roster.rs b/src/commands/roster.rs new file mode 100644 index 0000000..eec47d3 --- /dev/null +++ b/src/commands/roster.rs @@ -0,0 +1,47 @@ +use crate::{ + types, + util::{junk, nfl, request}, +}; + +use serenity::builder::{CreateCommand, CreateCommandOption}; +use serenity::model::application::{CommandOptionType, ResolvedOption, ResolvedValue}; + +pub async fn run(options: &[ResolvedOption<'_>]) -> String { + if let Some(ResolvedOption { + value: ResolvedValue::String(team), + .. + }) = options.first() + { + // TODO: get team roster and each players info if important + String::new() + } else { + junk::get_random_insult() + } +} + +pub fn register() -> CreateCommand { + CreateCommand::new("roster") + .description("Get the current NFL team's roster given a NFL team") + .add_option( + CreateCommandOption::new(CommandOptionType::String, "team", "The team to query") + .required(true), + ) +} + +pub struct RosterDiscordResponse { + pub team_name: String, + pub record: String, + pub next_event: String, + pub game_date: String, + pub standing: String, +} + +impl RosterDiscordResponse { + // TODO: get needed field for response and format them + pub fn format(&self) -> String { + format!( + "## {:}\nSeason Record (W-L): {:}\nNext Game: {:}\nNext Game Date: {:}\nStanding: {:}", + self.team_name, self.record, self.next_event, self.game_date, self.standing + ) + } +} diff --git a/src/commands/team.rs b/src/commands/team.rs index b8895c5..f884052 100644 --- a/src/commands/team.rs +++ b/src/commands/team.rs @@ -24,7 +24,7 @@ pub async fn run(options: &[ResolvedOption<'_>]) -> String { .await .unwrap(); let team_name = results.team.display_name; - let record = results.team.record.items[1].summary.clone(); + let record = results.team.record.items[0].summary.clone(); let next_event = results.team.next_event[0].name.clone(); let game_date_raw = results.team.next_event[0].date.clone(); let game_date = junk::flexible_to_epoch_seconds(game_date_raw.as_str()).unwrap(); @@ -44,7 +44,7 @@ pub async fn run(options: &[ResolvedOption<'_>]) -> String { pub fn register() -> CreateCommand { CreateCommand::new("team") - .description("Get team members for current season") + .description("Get NFL team information for current season") .add_option( CreateCommandOption::new(CommandOptionType::String, "team", "The team to query") .required(true), diff --git a/src/main.rs b/src/main.rs index 41f044e..d0f677f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ impl EventHandler for Handler { ) .await; - println!("Registered guild slash commands: {commands:#?}"); + println!("{} is ready to rock and roll!", ready.user.name); } }