From 8860dee7e6ea76aca0a0103ac6fb38e45c8dca06 Mon Sep 17 00:00:00 2001 From: Vicky Date: Tue, 5 Nov 2024 12:29:54 +0100 Subject: [PATCH] Added more compatibilty with new structure --- src/io.rs | 96 ++++++++++++++++++++++++++++++++++++-------------- src/modules.rs | 6 ++++ 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/src/io.rs b/src/io.rs index 7b4b267..05456f0 100644 --- a/src/io.rs +++ b/src/io.rs @@ -19,6 +19,7 @@ //! } //! ``` //! +use crate::modules::handler; use poise::serenity_prelude::{self as serenity}; /// User data, which is stored and accessible in all command invocations @@ -37,10 +38,12 @@ pub struct VoteContainer { short_name: Option, start_date: Option, non_days: Option, - days: Option, - date_begin: Option, - date_end: Option, + days: String, + date_begin: String, + date_end: String, identifier: VoteTypeIdentifier, + // ctx: Context<'_>, + // Context needs a "lifetime" parameter, I have no idea what that is } /// Only title, description and identifier are mandatory @@ -66,9 +69,9 @@ impl Default for VoteContainer { short_name: None, start_date: None, non_days: None, - days: None, - date_begin: None, - date_end: None, + days: "".to_string(), + date_begin: "".to_string(), + date_end: "".to_string(), identifier: VoteTypeIdentifier::Uninitialised, } } @@ -88,6 +91,10 @@ pub enum VoteTypeIdentifier { #[allow(dead_code)] // fields only used for Debug print #[name = "Créer un nouveau Vote"] pub(crate) struct WeeklyVoteModal { + /// The title of the event + #[name = "Titre"] + #[placeholder = "Titre de votre événement"] + title: String, /// The description of the event #[paragraph] #[name = "Description"] @@ -105,10 +112,6 @@ pub(crate) struct WeeklyVoteModal { #[name = "Nom du jeu"] #[placeholder = "'FFXIV', 'MHW', 'D&D'..."] short_name: Option, - /// The title of the event - #[name = "Titre"] - #[placeholder = "Titre de votre événement"] - title: String, // Max fields is 5 so the two below will have to be command-exclusive // #[name = "Date de début du vote"] // #[placeholder = "'ven', '10', '21 jan', vide pour la prochaine période de votes"] @@ -122,11 +125,11 @@ pub(crate) struct WeeklyVoteModal { impl Default for WeeklyVoteModal { fn default() -> Self { WeeklyVoteModal { + title: "The base test vote".into(), description: "Dummy vote".into(), group: Some("Base group".into()), hours: Some("21h - 23".into()), short_name: Some("Base vote".into()), - title: "The base test vote".into(), } } } @@ -172,6 +175,8 @@ pub async fn vote_modal( ..Default::default() }; + handler(serotoninenjoyer); + // let reply = poise::CreateReply::default().content(format!( // "@{} **{}**\n{}\n{}, {}", // group, title, description, short_name, hours @@ -210,11 +215,25 @@ pub async fn vote_command( #[description = "Date de début du vote"] start_date: Option, #[description = "Jours non dispos"] non_days: Option, ) -> Result<(), GenericError> { - ctx.say(format!( - "{:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?}", - title, short_name, group, description, hours, start_date, non_days - )) - .await?; + let rhubarb = VoteContainer { + title, + description, + // group, + hours, + short_name, + start_date, + non_days, + identifier: VoteTypeIdentifier::WeeklyVote, + ..Default::default() + }; + + handler(rhubarb); + + // ctx.say(format!( + // "{:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?}", + // title, short_name, group, description, hours, start_date, non_days + // )) + // .await?; Ok(()) } @@ -234,11 +253,23 @@ pub async fn short_vote( #[description = "Jours"] days: String, #[description = "Date de début du vote"] start_date: Option, ) -> Result<(), GenericError> { - ctx.say(format!( - "{:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?}", - title, group, description, hours, start_date, days - )) - .await?; + let aortavalve = VoteContainer { + title, + // group, + description, + hours, + days, + start_date, + ..Default::default() + }; + + handler(aortavalve); + + // ctx.say(format!( + // "{:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?}", + // title, group, description, hours, start_date, days + // )) + // .await?; Ok(()) } @@ -257,18 +288,29 @@ pub async fn long_vote( #[description = "Date de début de la période de l'événement"] date_begin: String, #[description = "Date de fin de la période de l'événement"] date_end: String, ) -> Result<(), GenericError> { - ctx.say(format!( - "{:?} ; {:?} ; {:?} ; {:?} ; {:?}", - title, description, start_date, date_begin, date_end - )) - .await?; + let cartoy = VoteContainer { + title, + description, + start_date, + date_begin, + date_end, + ..Default::default() + }; + + handler(cartoy); + + // ctx.say(format!( + // "{:?} ; {:?} ; {:?} ; {:?} ; {:?}", + // title, description, start_date, date_begin, date_end + // )) + // .await?; Ok(()) } /// The main discord interaction loop /// /// Registers all functions and starts a bot client -// As an async loop it is untestable by nature, however thsi loop aims to stay as simple as possible to be "self testing" +// As an async loop it is untestable by nature, however this loop aims to stay as simple as possible to be "self testing" #[cfg(not(tarpaulin_include))] pub async fn discord_main_loop() { let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"); diff --git a/src/modules.rs b/src/modules.rs index 979c55a..cce54b5 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -5,6 +5,8 @@ //! Many handler functions //! Every module encompassing a feature +use crate::io::VoteContainer; + struct LongVote { // todo } @@ -15,6 +17,10 @@ struct WeeklyVote { // todo } +pub fn handler(vc: VoteContainer) { + todo!() +} + #[cfg(test)] mod tests { // use super::*;