Added more compatibilty with new structure

This commit is contained in:
Vicky 2024-11-05 12:29:54 +01:00
parent f053fa222d
commit 8860dee7e6
2 changed files with 75 additions and 27 deletions

View File

@ -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<String>,
start_date: Option<String>,
non_days: Option<String>,
days: Option<String>,
date_begin: Option<String>,
date_end: Option<String>,
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<String>,
/// 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<String>,
#[description = "Jours non dispos"] non_days: Option<String>,
) -> 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<String>,
) -> 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");

View File

@ -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::*;