titanium_model/builder/
poll.rs

1use crate::TitanString;
2
3/// Builder for creating a Poll.
4#[derive(Debug, Clone)]
5pub struct PollBuilder<'a> {
6    poll: crate::message::Poll<'a>,
7}
8
9impl<'a> PollBuilder<'a> {
10    /// Create a new `PollBuilder`.
11    pub fn new(question: impl Into<TitanString<'a>>) -> Self {
12        Self {
13            poll: crate::message::Poll {
14                question: crate::message::PollMedia {
15                    text: Some(question.into()),
16                    emoji: None,
17                },
18                answers: Vec::new(),
19                expiry: None,
20                allow_multiselect: false,
21                layout_type: None,
22                results: None,
23            },
24        }
25    }
26
27    /// Add an answer.
28    pub fn answer(mut self, answer: impl Into<crate::message::PollAnswer<'a>>) -> Self {
29        self.poll.answers.push(answer.into());
30        self
31    }
32
33    /// Set expiry.
34    pub fn expiry(mut self, expiry: impl Into<TitanString<'a>>) -> Self {
35        self.poll.expiry = Some(expiry.into());
36        self
37    }
38
39    /// Allow multiselect.
40    #[must_use]
41    pub fn allow_multiselect(mut self, allow: bool) -> Self {
42        self.poll.allow_multiselect = allow;
43        self
44    }
45
46    /// Build the Poll.
47    #[must_use]
48    pub fn build(self) -> crate::message::Poll<'a> {
49        self.poll
50    }
51}