Added VoteContainer and some placeholder functions
This commit is contained in:
parent
1b6563464d
commit
f053fa222d
106
src/io.rs
106
src/io.rs
|
|
@ -19,7 +19,7 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
use poise::serenity_prelude as serenity;
|
||||
use poise::serenity_prelude::{self as serenity};
|
||||
|
||||
/// User data, which is stored and accessible in all command invocations
|
||||
pub struct Data {}
|
||||
|
|
@ -28,13 +28,66 @@ 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>;
|
||||
|
||||
/// Generic object that is used to transfer vote data to other parts of the code.
|
||||
pub struct VoteContainer {
|
||||
title: String,
|
||||
description: String,
|
||||
group: Option<String>,
|
||||
hours: Option<String>,
|
||||
short_name: Option<String>,
|
||||
start_date: Option<String>,
|
||||
non_days: Option<String>,
|
||||
days: Option<String>,
|
||||
date_begin: Option<String>,
|
||||
date_end: Option<String>,
|
||||
identifier: VoteTypeIdentifier,
|
||||
}
|
||||
|
||||
/// Only title, description and identifier are mandatory
|
||||
impl VoteContainer {
|
||||
pub fn new(title: String, description: String, identifier: VoteTypeIdentifier) -> Self {
|
||||
Self {
|
||||
title,
|
||||
description,
|
||||
identifier,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Default is None
|
||||
impl Default for VoteContainer {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
title: "".to_string(),
|
||||
description: "".to_string(),
|
||||
group: None,
|
||||
hours: None,
|
||||
short_name: None,
|
||||
start_date: None,
|
||||
non_days: None,
|
||||
days: None,
|
||||
date_begin: None,
|
||||
date_end: None,
|
||||
identifier: VoteTypeIdentifier::Uninitialised,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum VoteTypeIdentifier {
|
||||
WeeklyVote,
|
||||
ShortVote,
|
||||
LongVote,
|
||||
Uninitialised,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[derive(Debug, poise::Modal)]
|
||||
#[allow(dead_code)] // fields only used for Debug print
|
||||
#[name = "Créer un nouveau Vote"]
|
||||
pub(crate) struct VoteCreation {
|
||||
pub(crate) struct WeeklyVoteModal {
|
||||
/// The description of the event
|
||||
#[paragraph]
|
||||
#[name = "Description"]
|
||||
|
|
@ -66,9 +119,9 @@ pub(crate) struct VoteCreation {
|
|||
}
|
||||
|
||||
#[cfg(test)] // This default implementation only exists during testing
|
||||
impl Default for VoteCreation {
|
||||
impl Default for WeeklyVoteModal {
|
||||
fn default() -> Self {
|
||||
VoteCreation {
|
||||
WeeklyVoteModal {
|
||||
description: "Dummy vote".into(),
|
||||
group: Some("Base group".into()),
|
||||
hours: Some("21h - 23".into()),
|
||||
|
|
@ -90,21 +143,40 @@ pub async fn vote_modal(
|
|||
) -> Result<(), GenericError> {
|
||||
use poise::Modal as _;
|
||||
|
||||
let data = VoteCreation::execute(ctx).await?;
|
||||
// TODO: Change with logging
|
||||
println!("Got data: {:?}", data);
|
||||
let data = WeeklyVoteModal::execute(ctx).await?;
|
||||
if let Some(unwrapped_data) = data {
|
||||
let group = unwrapped_data.group.unwrap_or("".into());
|
||||
let title = unwrapped_data.title;
|
||||
let description = unwrapped_data.description;
|
||||
let short_name = unwrapped_data.short_name.unwrap_or("".into());
|
||||
let hours = unwrapped_data.hours.unwrap_or("".into());
|
||||
log::info!(
|
||||
"@{:?} **{:?}**\n{:?}\n{:?}, {:?}",
|
||||
unwrapped_data.group,
|
||||
unwrapped_data.title,
|
||||
unwrapped_data.description,
|
||||
unwrapped_data.short_name,
|
||||
unwrapped_data.hours
|
||||
);
|
||||
|
||||
let reply = poise::CreateReply::default().content(format!(
|
||||
"@{} **{}**\n{}\n{}, {}",
|
||||
group, title, description, short_name, hours
|
||||
));
|
||||
ctx.send(reply).await?;
|
||||
log::info!("{:?}", ctx);
|
||||
|
||||
// let group = unwrapped_data.group.unwrap_or("".into());
|
||||
// let title = unwrapped_data.title;
|
||||
// let description = unwrapped_data.description;
|
||||
// let short_name = unwrapped_data.short_name.unwrap_or("".into());
|
||||
// let hours = unwrapped_data.hours.unwrap_or("".into());
|
||||
|
||||
let serotoninenjoyer = VoteContainer {
|
||||
title: unwrapped_data.title,
|
||||
description: unwrapped_data.description,
|
||||
group: unwrapped_data.group,
|
||||
hours: unwrapped_data.hours,
|
||||
short_name: unwrapped_data.short_name,
|
||||
identifier: VoteTypeIdentifier::WeeklyVote,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// let reply = poise::CreateReply::default().content(format!(
|
||||
// "@{} **{}**\n{}\n{}, {}",
|
||||
// group, title, description, short_name, hours
|
||||
// ));
|
||||
// ctx.send(reply).await?;
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -5,53 +5,17 @@
|
|||
//! Many handler functions
|
||||
//! Every module encompassing a feature
|
||||
|
||||
use crate::io::VoteCreation;
|
||||
struct LongVote {
|
||||
// todo
|
||||
}
|
||||
struct ShortVote {
|
||||
// todo
|
||||
}
|
||||
struct WeeklyVote {
|
||||
// todo
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// use super::*;
|
||||
}
|
||||
|
||||
fn treatment_vote_modal(
|
||||
ctx: poise::ApplicationContext<'_, Data, GenericError>,
|
||||
data: VoteCreation,
|
||||
) {
|
||||
// parse data
|
||||
// -> group needs to be matched with existing group or return an error
|
||||
// -> check which of short_name and hours exist and decide on formatting
|
||||
// create the final product and send to scheduler for next voting window
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn treatment_vote_command(
|
||||
ctx: poise::ApplicationContext<'_, Data, GenericError>,
|
||||
data: VoteCreation,
|
||||
) {
|
||||
// parse data
|
||||
// -> check which of short_name and hours exist and decide on formatting
|
||||
// create the final product and send to scheduler with the start_date and non_days if specified
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn treatment_short_vote(
|
||||
ctx: poise::ApplicationContext<'_, Data, GenericError>,
|
||||
data: VoteCreation,
|
||||
) {
|
||||
// parse data
|
||||
// -> check whether hours exist and decide on formatting
|
||||
// create the final product and send to scheduler with the start_date if specified and days
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn treatment_long_vote(ctx: poise::ApplicationContext<'_, Data, GenericError>, data: VoteCreation) {
|
||||
// parse data
|
||||
// create the final product and pass it along with the start_date if it's here and the begining and end dates
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// 1: user types command (vote_modal)
|
||||
// 2: modal pops
|
||||
// 3: data from the modal gets parsed
|
||||
// 3.1 : group has to be matched with groups else error
|
||||
// 3.2 : check whether or not there are hours and short names, and decide on the formatting depending on it
|
||||
// 4: send final output to scheduler, with (if possible) context so it can reply instead of sending a new post
|
||||
|
|
|
|||
Loading…
Reference in New Issue