discord_webhook2/message/poll/
create.rs

1use crate::message::poll::answer::PollAnswer;
2use crate::message::poll::layout_type::PollLayoutType;
3use crate::message::poll::media::PollMedia;
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize, Deserialize, Debug, Clone)]
7pub struct PollCreate {
8    /// The question of the poll. Only text is supported.
9    question: PollMedia,
10    /// Each of the answers available in the poll, up to 10
11    answers: Vec<PollAnswer>,
12    /// Number of hours the poll should be open for, up to 32 days. Defaults to 24
13    duration: Option<u32>,
14    /// Whether a user can select multiple answers. Defaults to false
15    allow_multiselect: Option<bool>,
16    /// The layout type of the poll. Defaults to... DEFAULT!
17    layout_type: Option<PollLayoutType>,
18}
19
20impl PollCreate {
21    pub fn new(question: PollMedia) -> PollCreate {
22        Self {
23            question,
24            answers: vec![],
25            duration: None,
26            allow_multiselect: None,
27            layout_type: None,
28        }
29    }
30
31    pub fn answer<Func>(mut self, function: Func) -> Self
32    where
33        Func: FnOnce(PollMedia) -> PollMedia,
34    {
35        self.answers
36            .push(PollAnswer::new(function(PollMedia::new())));
37        self
38    }
39}