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
use serde::{Deserialize, Serialize};
/// Describes actions that a non-administrator user is allowed to take in a chat.
/// # Documentation
/// <https://core.telegram.org/bots/api#chatpermissions>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ChatPermissions {
/// `true`, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_messages: Option<bool>,
/// `true`, if the user is allowed to send audios
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_audios: Option<bool>,
/// `true`, if the user is allowed to send documents
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_documents: Option<bool>,
/// `true`, if the user is allowed to send photos
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_photos: Option<bool>,
/// `true`, if the user is allowed to send videos
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_videos: Option<bool>,
/// `true`, if the user is allowed to send video notes
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_video_notes: Option<bool>,
/// `true`, if the user is allowed to send voice notes
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_voice_notes: Option<bool>,
/// `true`, if the user is allowed to send polls and checklists
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_polls: Option<bool>,
/// `true`, if the user is allowed to send animations, games, stickers and use inline bots
#[serde(skip_serializing_if = "Option::is_none")]
pub can_send_other_messages: Option<bool>,
/// `true`, if the user is allowed to add web page previews to their messages
#[serde(skip_serializing_if = "Option::is_none")]
pub can_add_web_page_previews: Option<bool>,
/// `true`, if the user is allowed to react to messages. If omitted, defaults to the value of `can_send_messages`.
#[serde(skip_serializing_if = "Option::is_none")]
pub can_react_to_messages: Option<bool>,
/// `true`, if the user is allowed to edit their own tag. If omitted, defaults to the value of `can_pin_messages`.
#[serde(skip_serializing_if = "Option::is_none")]
pub can_edit_tag: Option<bool>,
/// `true`, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups
#[serde(skip_serializing_if = "Option::is_none")]
pub can_change_info: Option<bool>,
/// `true`, if the user is allowed to invite new users to the chat
#[serde(skip_serializing_if = "Option::is_none")]
pub can_invite_users: Option<bool>,
/// `true`, if the user is allowed to pin messages. Ignored in public supergroups
#[serde(skip_serializing_if = "Option::is_none")]
pub can_pin_messages: Option<bool>,
/// `true`, if the user is allowed to create forum topics. If omitted defaults to the value of `can_pin_messages`
#[serde(skip_serializing_if = "Option::is_none")]
pub can_manage_topics: Option<bool>,
}
impl ChatPermissions {
/// Creates a new `ChatPermissions`.
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new() -> Self {
Self {
can_send_messages: None,
can_send_audios: None,
can_send_documents: None,
can_send_photos: None,
can_send_videos: None,
can_send_video_notes: None,
can_send_voice_notes: None,
can_send_polls: None,
can_send_other_messages: None,
can_add_web_page_previews: None,
can_react_to_messages: None,
can_edit_tag: None,
can_change_info: None,
can_invite_users: None,
can_pin_messages: None,
can_manage_topics: None,
}
}
/// `true`, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues
#[must_use]
pub fn can_send_messages<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_messages = Some(val.into());
self
}
/// `true`, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues
#[must_use]
pub fn can_send_messages_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_messages = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send audios
#[must_use]
pub fn can_send_audios<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_audios = Some(val.into());
self
}
/// `true`, if the user is allowed to send audios
#[must_use]
pub fn can_send_audios_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_audios = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send documents
#[must_use]
pub fn can_send_documents<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_documents = Some(val.into());
self
}
/// `true`, if the user is allowed to send documents
#[must_use]
pub fn can_send_documents_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_documents = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send photos
#[must_use]
pub fn can_send_photos<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_photos = Some(val.into());
self
}
/// `true`, if the user is allowed to send photos
#[must_use]
pub fn can_send_photos_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_photos = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send videos
#[must_use]
pub fn can_send_videos<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_videos = Some(val.into());
self
}
/// `true`, if the user is allowed to send videos
#[must_use]
pub fn can_send_videos_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_videos = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send video notes
#[must_use]
pub fn can_send_video_notes<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_video_notes = Some(val.into());
self
}
/// `true`, if the user is allowed to send video notes
#[must_use]
pub fn can_send_video_notes_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_video_notes = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send voice notes
#[must_use]
pub fn can_send_voice_notes<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_voice_notes = Some(val.into());
self
}
/// `true`, if the user is allowed to send voice notes
#[must_use]
pub fn can_send_voice_notes_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_voice_notes = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send polls and checklists
#[must_use]
pub fn can_send_polls<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_polls = Some(val.into());
self
}
/// `true`, if the user is allowed to send polls and checklists
#[must_use]
pub fn can_send_polls_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_polls = val.map(Into::into);
self
}
/// `true`, if the user is allowed to send animations, games, stickers and use inline bots
#[must_use]
pub fn can_send_other_messages<T: Into<bool>>(mut self, val: T) -> Self {
self.can_send_other_messages = Some(val.into());
self
}
/// `true`, if the user is allowed to send animations, games, stickers and use inline bots
#[must_use]
pub fn can_send_other_messages_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_send_other_messages = val.map(Into::into);
self
}
/// `true`, if the user is allowed to add web page previews to their messages
#[must_use]
pub fn can_add_web_page_previews<T: Into<bool>>(mut self, val: T) -> Self {
self.can_add_web_page_previews = Some(val.into());
self
}
/// `true`, if the user is allowed to add web page previews to their messages
#[must_use]
pub fn can_add_web_page_previews_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_add_web_page_previews = val.map(Into::into);
self
}
/// `true`, if the user is allowed to react to messages. If omitted, defaults to the value of `can_send_messages`.
#[must_use]
pub fn can_react_to_messages<T: Into<bool>>(mut self, val: T) -> Self {
self.can_react_to_messages = Some(val.into());
self
}
/// `true`, if the user is allowed to react to messages. If omitted, defaults to the value of `can_send_messages`.
#[must_use]
pub fn can_react_to_messages_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_react_to_messages = val.map(Into::into);
self
}
/// `true`, if the user is allowed to edit their own tag. If omitted, defaults to the value of `can_pin_messages`.
#[must_use]
pub fn can_edit_tag<T: Into<bool>>(mut self, val: T) -> Self {
self.can_edit_tag = Some(val.into());
self
}
/// `true`, if the user is allowed to edit their own tag. If omitted, defaults to the value of `can_pin_messages`.
#[must_use]
pub fn can_edit_tag_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_edit_tag = val.map(Into::into);
self
}
/// `true`, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups
#[must_use]
pub fn can_change_info<T: Into<bool>>(mut self, val: T) -> Self {
self.can_change_info = Some(val.into());
self
}
/// `true`, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups
#[must_use]
pub fn can_change_info_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_change_info = val.map(Into::into);
self
}
/// `true`, if the user is allowed to invite new users to the chat
#[must_use]
pub fn can_invite_users<T: Into<bool>>(mut self, val: T) -> Self {
self.can_invite_users = Some(val.into());
self
}
/// `true`, if the user is allowed to invite new users to the chat
#[must_use]
pub fn can_invite_users_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_invite_users = val.map(Into::into);
self
}
/// `true`, if the user is allowed to pin messages. Ignored in public supergroups
#[must_use]
pub fn can_pin_messages<T: Into<bool>>(mut self, val: T) -> Self {
self.can_pin_messages = Some(val.into());
self
}
/// `true`, if the user is allowed to pin messages. Ignored in public supergroups
#[must_use]
pub fn can_pin_messages_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_pin_messages = val.map(Into::into);
self
}
/// `true`, if the user is allowed to create forum topics. If omitted defaults to the value of `can_pin_messages`
#[must_use]
pub fn can_manage_topics<T: Into<bool>>(mut self, val: T) -> Self {
self.can_manage_topics = Some(val.into());
self
}
/// `true`, if the user is allowed to create forum topics. If omitted defaults to the value of `can_pin_messages`
#[must_use]
pub fn can_manage_topics_option<T: Into<bool>>(mut self, val: Option<T>) -> Self {
self.can_manage_topics = val.map(Into::into);
self
}
}
impl Default for ChatPermissions {
fn default() -> Self {
Self::new()
}
}