Adds a config file and implements a base votes structs
This commit is contained in:
parent
43990f43a0
commit
7c6fee6914
|
|
@ -19,3 +19,7 @@ Cargo.lock
|
|||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
||||
# The discord token
|
||||
|
||||
.token
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ edition = "2021"
|
|||
poise = "0.6.1"
|
||||
poise_macros = "0.6.1"
|
||||
tokio = { version = "1.41.0", features = ["rt-multi-thread"] }
|
||||
serde = { version = "1.0.214", features = ["alloc", "derive"] }
|
||||
uuid = { version = "1.11.0", features = ["v4", "v7", "serde", "fast-rng"] }
|
||||
|
||||
[profile.dev]
|
||||
debug = 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
//! Handles all config related functions
|
||||
//!
|
||||
//! Tries to load a config from .idlefox.toml
|
||||
//! and creates a default version if it fails to do so
|
||||
//!
|
||||
//! Features:
|
||||
//! Create, loads and saves config
|
||||
//! Default config
|
||||
//! Import old data from outdated configs
|
||||
//! Recover from importing faulty data
|
||||
//!
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The global config
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct GlobalConfig {}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
// This line is here to force the use of extensive documentation
|
||||
#![warn(clippy::missing_docs_in_private_items)]
|
||||
|
||||
mod config;
|
||||
mod io;
|
||||
mod modules;
|
||||
mod persistence;
|
||||
|
|
@ -142,6 +143,7 @@ pub async fn component_modal(ctx: crate::Context<'_>) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let token = std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
|
||||
|
|
|
|||
109
src/votes.rs
109
src/votes.rs
|
|
@ -8,6 +8,115 @@
|
|||
//! ListFutureEvents (struct)
|
||||
//!
|
||||
|
||||
use std::{collections::HashMap, sync::LazyLock};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Placeholder datatype
|
||||
///
|
||||
/// Links to an event, active or planned
|
||||
type EventDataType = Uuid;
|
||||
|
||||
/// Placeholder user data type
|
||||
///
|
||||
/// Links back to an user
|
||||
#[deprecated(note = "This is an incorrect type to define an user")]
|
||||
type UserDataType = String;
|
||||
|
||||
/// What an user voted for
|
||||
#[deprecated(note = "This is an incorrect type to define a vote")]
|
||||
type VoteValueType = String;
|
||||
|
||||
/// A vote, represents a user interraction towards an event
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct Vote {
|
||||
/// The event the vote refers to
|
||||
linked_event: EventDataType,
|
||||
/// The user casting the vote
|
||||
user_handle: UserDataType,
|
||||
/// What the user voted for
|
||||
vote_value: VoteValueType,
|
||||
}
|
||||
|
||||
/// Data type representing a date
|
||||
type DateDataType = String;
|
||||
|
||||
/// The global status of the event
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) enum EventStatus {
|
||||
/// The event exists but wasn't started yet
|
||||
Pending,
|
||||
/// The event was started but the finish date wasn't reached yet
|
||||
Started,
|
||||
/// The event was started and the date finish date was reached without being closed
|
||||
Finished,
|
||||
/// The event was closed and the outcome was made public
|
||||
Closed,
|
||||
/// The event was cancelled
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
/// An event, wether ongoing or planned
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct Event {
|
||||
/// The title of the even
|
||||
title: String,
|
||||
/// Description of the event
|
||||
description: String,
|
||||
/// The global status of the vote
|
||||
status: EventStatus,
|
||||
/// Date at which to autostart the vote process
|
||||
launch_date: Option<DateDataType>,
|
||||
/// Date at which to autoclose the vote process
|
||||
close_date: Option<DateDataType>,
|
||||
/// The inner list of votes cast
|
||||
votes: Vec<Vote>,
|
||||
/// The list of values to vote for, this list all the valid dates to vote for
|
||||
vote_values: Vec<DateDataType>,
|
||||
}
|
||||
|
||||
// This split in two differents structs conceptually represents
|
||||
// the fact that very differents actions will be performed for each struct
|
||||
type EventListType = HashMap<Uuid, Event>;
|
||||
|
||||
/// The list of pending events, not yet started
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct PendingEvents {
|
||||
/// The list of pending events
|
||||
pending_events: EventListType,
|
||||
}
|
||||
impl PendingEvents {
|
||||
/// Create a new empty list of events, called in case of a first initialization
|
||||
///
|
||||
/// However a deserialization will always be performed if possible
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
pending_events: EventListType::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The list of ongoing events, not yet closed
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub(crate) struct OngoingEvents {
|
||||
/// The list of ongoing events
|
||||
ongoing_events: EventListType,
|
||||
}
|
||||
|
||||
impl OngoingEvents {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
ongoing_events: EventListType::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The thread safe list of pending events
|
||||
static CURRENT_EVENTS: LazyLock<PendingEvents> = LazyLock::new(PendingEvents::new);
|
||||
/// The thread safe list of ongoing events
|
||||
static PENDING_EVENTS: LazyLock<OngoingEvents> = LazyLock::new(OngoingEvents::new);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
// use super::*;
|
||||
|
|
|
|||
Loading…
Reference in New Issue