1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
use serde::{Deserialize, Serialize};
/// This object represents a regular poll.
/// # Notes
/// This object represents a poll from original poll type `regular`.
/// # Documentation
/// <https://core.telegram.org/bots/api#poll>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PollRegular {
/// Unique poll identifier
pub id: Box<str>,
/// Poll question, 1-300 characters
pub question: Box<str>,
/// Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions
#[serde(skip_serializing_if = "Option::is_none")]
pub question_entities: Option<Box<[crate::types::MessageEntity]>>,
/// List of poll options
pub options: Box<[crate::types::PollOption]>,
/// Total number of users that voted in the poll
pub total_voter_count: i64,
/// `true`, if the poll is closed
pub is_closed: bool,
/// `true`, if the poll is anonymous
pub is_anonymous: bool,
/// `true`, if the poll allows multiple answers
pub allows_multiple_answers: bool,
/// `true`, if the poll allows to change the chosen answer options
pub allows_revoting: bool,
/// Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
#[serde(skip_serializing_if = "Option::is_none")]
pub explanation_entities: Option<Box<[crate::types::MessageEntity]>>,
/// Amount of time in seconds the poll will be active after creation
#[serde(skip_serializing_if = "Option::is_none")]
pub open_period: Option<i64>,
/// Point in time (Unix timestamp) when the poll will be automatically closed
#[serde(skip_serializing_if = "Option::is_none")]
pub close_date: Option<i64>,
/// Description of the poll; for polls inside the Message object only
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<Box<str>>,
/// Special entities like usernames, URLs, bot commands, etc. that appear in the description
#[serde(skip_serializing_if = "Option::is_none")]
pub description_entities: Option<Box<[crate::types::MessageEntity]>>,
}
impl PollRegular {
/// Creates a new `PollRegular`.
///
/// # Arguments
/// * `id` - Unique poll identifier
/// * `question` - Poll question, 1-300 characters
/// * `options` - List of poll options
/// * `total_voter_count` - Total number of users that voted in the poll
/// * `is_closed` - `true`, if the poll is closed
/// * `is_anonymous` - `true`, if the poll is anonymous
/// * `allows_multiple_answers` - `true`, if the poll allows multiple answers
/// * `allows_revoting` - `true`, if the poll allows to change the chosen answer options
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<
T0: Into<Box<str>>,
T1: Into<Box<str>>,
T2Item: Into<crate::types::PollOption>,
T2: IntoIterator<Item = T2Item>,
T3: Into<i64>,
T4: Into<bool>,
T5: Into<bool>,
T6: Into<bool>,
T7: Into<bool>,
>(
id: T0,
question: T1,
options: T2,
total_voter_count: T3,
is_closed: T4,
is_anonymous: T5,
allows_multiple_answers: T6,
allows_revoting: T7,
) -> Self {
Self {
id: id.into(),
question: question.into(),
question_entities: None,
options: options.into_iter().map(Into::into).collect(),
total_voter_count: total_voter_count.into(),
is_closed: is_closed.into(),
is_anonymous: is_anonymous.into(),
allows_multiple_answers: allows_multiple_answers.into(),
allows_revoting: allows_revoting.into(),
explanation_entities: None,
open_period: None,
close_date: None,
description: None,
description_entities: None,
}
}
/// Unique poll identifier
#[must_use]
pub fn id<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.id = val.into();
this
}
/// Poll question, 1-300 characters
#[must_use]
pub fn question<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.question = val.into();
this
}
/// Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn question_entities<T: Into<Box<[crate::types::MessageEntity]>>>(self, val: T) -> Self {
let mut this = self;
this.question_entities = Some(
this.question_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into())
.collect(),
);
this
}
/// Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn question_entity<T: Into<crate::types::MessageEntity>>(self, val: T) -> Self {
let mut this = self;
this.question_entities = Some(
this.question_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
this
}
/// Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn question_entities_option<T: Into<Box<[crate::types::MessageEntity]>>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.question_entities = val.map(Into::into);
this
}
/// List of poll options
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn options<T: Into<Box<[crate::types::PollOption]>>>(self, val: T) -> Self {
let mut this = self;
this.options = this
.options
.into_vec()
.into_iter()
.chain(val.into())
.collect();
this
}
/// List of poll options
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn option<T: Into<crate::types::PollOption>>(self, val: T) -> Self {
let mut this = self;
this.options = this
.options
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect();
this
}
/// Total number of users that voted in the poll
#[must_use]
pub fn total_voter_count<T: Into<i64>>(self, val: T) -> Self {
let mut this = self;
this.total_voter_count = val.into();
this
}
/// `true`, if the poll is closed
#[must_use]
pub fn is_closed<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.is_closed = val.into();
this
}
/// `true`, if the poll is anonymous
#[must_use]
pub fn is_anonymous<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.is_anonymous = val.into();
this
}
/// `true`, if the poll allows multiple answers
#[must_use]
pub fn allows_multiple_answers<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.allows_multiple_answers = val.into();
this
}
/// `true`, if the poll allows to change the chosen answer options
#[must_use]
pub fn allows_revoting<T: Into<bool>>(self, val: T) -> Self {
let mut this = self;
this.allows_revoting = val.into();
this
}
/// Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn explanation_entities<T: Into<Box<[crate::types::MessageEntity]>>>(self, val: T) -> Self {
let mut this = self;
this.explanation_entities = Some(
this.explanation_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into())
.collect(),
);
this
}
/// Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn explanation_entity<T: Into<crate::types::MessageEntity>>(self, val: T) -> Self {
let mut this = self;
this.explanation_entities = Some(
this.explanation_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
this
}
/// Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn explanation_entities_option<T: Into<Box<[crate::types::MessageEntity]>>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.explanation_entities = val.map(Into::into);
this
}
/// Amount of time in seconds the poll will be active after creation
#[must_use]
pub fn open_period<T: Into<i64>>(self, val: T) -> Self {
let mut this = self;
this.open_period = Some(val.into());
this
}
/// Amount of time in seconds the poll will be active after creation
#[must_use]
pub fn open_period_option<T: Into<i64>>(self, val: Option<T>) -> Self {
let mut this = self;
this.open_period = val.map(Into::into);
this
}
/// Point in time (Unix timestamp) when the poll will be automatically closed
#[must_use]
pub fn close_date<T: Into<i64>>(self, val: T) -> Self {
let mut this = self;
this.close_date = Some(val.into());
this
}
/// Point in time (Unix timestamp) when the poll will be automatically closed
#[must_use]
pub fn close_date_option<T: Into<i64>>(self, val: Option<T>) -> Self {
let mut this = self;
this.close_date = val.map(Into::into);
this
}
/// Description of the poll; for polls inside the Message object only
#[must_use]
pub fn description<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.description = Some(val.into());
this
}
/// Description of the poll; for polls inside the Message object only
#[must_use]
pub fn description_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
let mut this = self;
this.description = val.map(Into::into);
this
}
/// Special entities like usernames, URLs, bot commands, etc. that appear in the description
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn description_entities<T: Into<Box<[crate::types::MessageEntity]>>>(self, val: T) -> Self {
let mut this = self;
this.description_entities = Some(
this.description_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into())
.collect(),
);
this
}
/// Special entities like usernames, URLs, bot commands, etc. that appear in the description
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn description_entity<T: Into<crate::types::MessageEntity>>(self, val: T) -> Self {
let mut this = self;
this.description_entities = Some(
this.description_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
this
}
/// Special entities like usernames, URLs, bot commands, etc. that appear in the description
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn description_entities_option<T: Into<Box<[crate::types::MessageEntity]>>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.description_entities = val.map(Into::into);
this
}
}