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
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct GetUpdates {
#[serde(skip_serializing_if = "Option::is_none")]
pub offset: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_updates: Option<Vec<UpdateType>>,
}
impl GetUpdates {
pub fn new() -> Self {
Self {
offset: None,
limit: None,
timeout: None,
allowed_updates: None,
}
}
pub fn set_offset(&mut self, offset: i64) -> &mut Self {
self.offset = Some(offset);
self
}
pub fn set_limit(&mut self, mut limit: usize) -> &mut Self {
if limit > 100 {
limit = 100;
}
self.limit = Some(limit);
self
}
pub fn set_timeout(&mut self, timeout: usize) -> &mut Self {
self.timeout = Some(timeout);
self
}
pub fn set_allowed_updates(&mut self, allowed_updates: Vec<UpdateType>) -> &mut Self {
self.allowed_updates = Some(allowed_updates);
self
}
pub fn add_allowed_updates(&mut self, allowed_update: UpdateType) -> &mut Self {
if let Some(ref mut a) = self.allowed_updates {
a.push(allowed_update)
} else {
self.allowed_updates = Some(vec![allowed_update])
}
self
}
}
impl std::default::Default for GetUpdates {
fn default() -> Self {
Self::new()
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum UpdateType {
#[serde(rename = "message")]
Message,
#[serde(rename = "edited_message")]
EditedMessage,
#[serde(rename = "channel_post")]
ChannelPost,
#[serde(rename = "edited_channel_post")]
EditedChannelPost,
#[serde(rename = "inline_query")]
InlineQuery,
#[serde(rename = "chosen_inline_result")]
ChosenInlineResult,
#[serde(rename = "callback_query")]
CallbackQuery,
#[serde(rename = "shipping_query")]
ShippingQuery,
#[serde(rename = "pre_checkout_query")]
PreCheckoutQuery,
#[serde(rename = "poll")]
Poll,
#[serde(rename = "poll_answer")]
PollAnswer,
}