From 43990f43a0b649fdb4e7c87bd36ff19e0c83481d Mon Sep 17 00:00:00 2001 From: Vicky Date: Wed, 30 Oct 2024 14:09:41 +0100 Subject: [PATCH] Renames the modal command to vote_modal and creates vote_command --- FEATURES.md | 50 +++++++++++++++++++++++++++++++++++++++++ README.md | 5 ++++- src/main.rs | 64 +++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 FEATURES.md diff --git a/FEATURES.md b/FEATURES.md new file mode 100644 index 0000000..a86327a --- /dev/null +++ b/FEATURES.md @@ -0,0 +1,50 @@ +# List of commands and their inner workings +## `/vote_modal` +*Creates a new discord modal to walk the user through the creation of a new vote* +### Input +* title (String): The title for the futur event; +* short_name (Option): Optional short name for the event; +* group (Option): If specified, **must** be among the existing guildRoles in order for the bot to tag said guildRole; +* description (String): Description for the event; +* hours(Option): Time window for the event. +### Output +> ## {title} +> @{group} {description} +> **{short_name} ; **{hours}** + +Should the optional fields be left out, it could look like this: +> ## {title} +> {description} +> **21h - 23h** + +## `/vote_command` +*More comprehensive, only-textual, version of vote_modal to create a new vote* +### Input +* title (String): The title for the futur event; +* short_name (Option): Optional short name for the event; +* group (Option): If specified, **must** be among the existing guildRoles in order for the bot to tag said guildRole; +* description (String): Description for the event; +* hours(Option): Time window for the event; +* start_date(Option): Date after which the bot will publish the vote in the first open-voting window (if it exists); +* non_days(Option): Days for which the bot should replace the reaction from a number to a neutral emoji. + + +### Parsing logic +30/10/2024 +> lun mar mer jeu ven sam dim + > le prochain jour qui correspond (a ce jour) + > ex: lun -> lun 4 nov +> 10, 21, 2 + > le prochain jour qui correspond (a cette date) + > ex: 10 -> dim 10 nov +> 30 nov, 1 jan, 10 aou + > cette date exacte + > ex: 30 nov -> sam 30 nov + +### Long votes +> Nouvel event! +> Description +> id: xxx +[Voter mes dispos] -> t'ouvre un modal +-> /dispo id: xxx date: 10 jan - 20 jan, 23 jan, 25 jan, 1 fev - 30 fev omit: 15 fev +-> /dispo id: xxx omit: 30 fev diff --git a/README.md b/README.md index f869ab7..1129ea6 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,7 @@ A Rust Discord Bot, in charge of greatly simplifying the process of finding a me A great emphasis is put on organizing the votes themselves, delaying posting them and editing the answers as time goes. -This bot also spins a web interface to allow real time monitoring of all activities and (for admins) close the votes via said interface \ No newline at end of file +This bot also spins a web interface to allow real time monitoring of all activities and (for admins) close the votes via said interface + +## List of commands +* `/vote_modal` Pops up a modal (discord form) helping the user through creating a vote. diff --git a/src/main.rs b/src/main.rs index 5e1bf68..1275e60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,17 +19,18 @@ struct Data {} // User data, which is stored and accessible in all command invoc type Error = Box; type Context<'a> = poise::Context<'a, Data, Error>; -/// Displays your or another user's account creation date -#[poise::command(slash_command, prefix_command)] -async fn how_old( - ctx: Context<'_>, - #[description = "Selected user"] user: Option, -) -> Result<(), Error> { - let u = user.as_ref().unwrap_or_else(|| ctx.author()); - let response = format!("{}'s account was created at {}", u.name, u.created_at()); - ctx.say(response).await?; - Ok(()) -} +// // Displays your or another user's account creation date +// // Dummy command from poise documentation +// #[poise::command(slash_command, prefix_command)] +// async fn how_old( +// ctx: Context<'_>, +// #[description = "Selected user"] user: Option, +// ) -> Result<(), Error> { +// let u = user.as_ref().unwrap_or_else(|| ctx.author()); +// let response = format!("{}'s account was created at {}", u.name, u.created_at()); +// ctx.say(response).await?; +// Ok(()) +// } #[derive(Debug, poise::Modal)] #[allow(dead_code)] // fields only used for Debug print @@ -51,10 +52,18 @@ struct VoteCreation { #[name = "Horaires"] #[placeholder = "'21h - 23h' par défaut"] hours: Option, + // 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"] + // start_date: Option, + // #[name = "Jours non dispos"] + // #[placeholder = "'lun', '30', '2 dec'"] + // non_days: Option, } +// vote_modal #[poise::command(slash_command)] -pub async fn modal(ctx: poise::ApplicationContext<'_, Data, Error>) -> Result<(), Error> { +pub async fn vote_modal(ctx: poise::ApplicationContext<'_, Data, Error>) -> Result<(), Error> { use poise::Modal as _; let data = VoteCreation::execute(ctx).await?; @@ -76,6 +85,34 @@ pub async fn modal(ctx: poise::ApplicationContext<'_, Data, Error>) -> Result<() Ok(()) } +// List of choices for all the roles +#[derive(Debug, poise::ChoiceParameter)] +pub enum ListOfRoles { + // This needs to be a list of all guildRoles under Users (included) + #[name = "hunters"] + Hunters, +} + +// vote_command +#[poise::command(prefix_command, slash_command)] +pub async fn vote_command( + ctx: Context<'_>, + #[description = "Titre"] title: String, + #[description = "Nom du jeu"] short_name: Option, + #[description = "Groupe"] group: ListOfRoles, + #[description = "Description"] description: String, + #[description = "Horaires"] hours: Option, + #[description = "Date de début du vote"] start_date: Option, + #[description = "Jours non dispos"] non_days: Option, +) -> Result<(), Error> { + ctx.say(format!( + "{:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?} ; {:?}", + title, short_name, group, description, hours, start_date, non_days + )) + .await?; + Ok(()) +} + #[poise::command(prefix_command, slash_command)] pub async fn component_modal(ctx: crate::Context<'_>) -> Result<(), Error> { let reply = { @@ -109,10 +146,9 @@ pub async fn component_modal(ctx: crate::Context<'_>) -> Result<(), Error> { async fn main() { let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"); let intents = serenity::GatewayIntents::non_privileged(); - let framework = poise::Framework::builder() .options(poise::FrameworkOptions { - commands: vec![how_old(), modal(), component_modal()], + commands: vec![vote_command(), vote_modal(), component_modal()], ..Default::default() }) .setup(|ctx, _ready, framework| {