Renames the modal command to vote_modal and creates vote_command
This commit is contained in:
parent
ee29c47387
commit
43990f43a0
|
|
@ -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<String>): Optional short name for the event;
|
||||
* group (Option<String>): 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<String>): 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<String>): Optional short name for the event;
|
||||
* group (Option<String>): 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<String>): Time window for the event;
|
||||
* start_date(Option<String>): Date after which the bot will publish the vote in the first open-voting window (if it exists);
|
||||
* non_days(Option<String>): 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
|
||||
|
|
@ -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
|
||||
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.
|
||||
|
|
|
|||
64
src/main.rs
64
src/main.rs
|
|
@ -19,17 +19,18 @@ struct Data {} // User data, which is stored and accessible in all command invoc
|
|||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
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<serenity::User>,
|
||||
) -> 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<serenity::User>,
|
||||
// ) -> 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<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"]
|
||||
// start_date: Option<String>,
|
||||
// #[name = "Jours non dispos"]
|
||||
// #[placeholder = "'lun', '30', '2 dec'"]
|
||||
// non_days: Option<String>,
|
||||
}
|
||||
|
||||
// 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<String>,
|
||||
#[description = "Groupe"] group: ListOfRoles,
|
||||
#[description = "Description"] description: String,
|
||||
#[description = "Horaires"] hours: Option<String>,
|
||||
#[description = "Date de début du vote"] start_date: Option<String>,
|
||||
#[description = "Jours non dispos"] non_days: Option<String>,
|
||||
) -> 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| {
|
||||
|
|
|
|||
Loading…
Reference in New Issue