Added text commands /vote_long et /vote_short, added some doc #9

Merged
vky merged 1 commits from shorter_vote into dev 2024-11-02 20:20:28 +01:00
1 changed files with 41 additions and 39 deletions

View File

@ -28,19 +28,6 @@ type GenericError = Box<dyn std::error::Error + Send + Sync>;
/// The context (in a discord sence) of a message
type Context<'a> = poise::Context<'a, Data, GenericError>;
// // 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(())
// }
/// The result of a vote creation.
///
/// This struct is used to store and display the results of creating a new vote via a discord modal form.
@ -144,33 +131,48 @@ pub async fn vote_command(
Ok(())
}
/// TODO: Fill doc
/// Text command for the creation of exeptional votes ; outside normal voting windows.
///
/// This text command is composed of optional group, hours and start_date ; and compulsory title, description and days. days will indicate which days of the week after the start_date will be available for voting.
// Since this is a discord command and not a real rust command, this many arguments is "normal"
#[allow(clippy::too_many_arguments)]
#[poise::command(prefix_command, slash_command)]
pub async fn component_modal(ctx: Context<'_>) -> Result<(), GenericError> {
let reply = {
let components = vec![serenity::CreateActionRow::Buttons(vec![
serenity::CreateButton::new("open_modal")
.label("Open modal")
.style(poise::serenity_prelude::ButtonStyle::Success),
])];
pub async fn short_vote(
ctx: Context<'_>,
#[description = "Titre"] title: String,
#[description = "Groupe"] group: ListOfRoles,
#[description = "Description"] description: String,
#[description = "Horaires"] hours: Option<String>,
#[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?;
Ok(())
}
poise::CreateReply::default()
.content("Click the button below to open the modal")
.components(components)
};
ctx.send(reply).await?;
while let Some(mci) = serenity::ComponentInteractionCollector::new(ctx.serenity_context())
.timeout(std::time::Duration::from_secs(120))
.filter(move |mci| mci.data.custom_id == "open_modal")
.await
{
let data =
poise::execute_modal_on_component_interaction::<VoteCreation>(ctx, mci, None, None)
.await?;
println!("Got data: {:?}", data);
}
/// Text command for the creation of long votes
///
/// Text command for the creation of votes that span on a very long period to decide on dates for larger-scale events.
/// Takes mandatory title, description, beginning and end date and optional starting date for the vote.
#[allow(clippy::too_many_arguments)]
#[poise::command(prefix_command, slash_command)] // i have no idea what causes this warning
pub async fn long_vote(
ctx: Context<'_>,
#[description = "Titre"] title: String,
#[description = "Description"] description: String,
#[description = "Date de début du vote"] start_date: Option<String>,
#[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?;
Ok(())
}
@ -182,7 +184,7 @@ pub async fn discord_main_loop() {
let intents = serenity::GatewayIntents::non_privileged();
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![vote_command(), vote_modal(), component_modal()],
commands: vec![vote_command(), vote_modal(), short_vote(), long_vote()],
..Default::default()
})
.setup(|ctx, _ready, framework| {