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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
use serde::{Deserialize, Serialize};
/// This object contains information about one member of a chat. Currently, the following 6 types of chat members are supported:
/// - [`crate::types::ChatMemberOwner`]
/// - [`crate::types::ChatMemberAdministrator`]
/// - [`crate::types::ChatMemberMember`]
/// - [`crate::types::ChatMemberRestricted`]
/// - [`crate::types::ChatMemberLeft`]
/// - [`crate::types::ChatMemberBanned`]
/// # Documentation
/// <https://core.telegram.org/bots/api#chatmember>
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum ChatMember {
Creator(crate::types::ChatMemberOwner),
Administrator(crate::types::ChatMemberAdministrator),
Member(crate::types::ChatMemberMember),
Restricted(crate::types::ChatMemberRestricted),
Left(crate::types::ChatMemberLeft),
Kicked(crate::types::ChatMemberBanned),
}
impl ChatMember {
/// Helper method for field `can_add_web_page_previews`.
///
/// `true`, if the user is allowed to add web page previews to their messages
#[must_use]
pub fn can_add_web_page_previews(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_add_web_page_previews),
_ => None,
}
}
/// Helper method for field `can_be_edited`.
///
/// `true`, if the bot is allowed to edit administrator privileges of that user
#[must_use]
pub fn can_be_edited(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_be_edited),
_ => None,
}
}
/// Helper method for field `can_change_info`.
///
/// `true`, if the user is allowed to change the chat title, photo and other settings
#[must_use]
pub fn can_change_info(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_change_info),
Self::Restricted(val) => Some(val.can_change_info),
_ => None,
}
}
/// Helper method for field `can_delete_messages`.
///
/// `true`, if the administrator can delete messages of other users
#[must_use]
pub fn can_delete_messages(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_delete_messages),
_ => None,
}
}
/// Helper method for field `can_delete_stories`.
///
/// `true`, if the administrator can delete stories posted by other users
#[must_use]
pub fn can_delete_stories(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_delete_stories),
_ => None,
}
}
/// Helper method for field `can_edit_messages`.
///
/// `true`, if the administrator can edit messages of other users and can pin messages; for channels only
#[must_use]
pub fn can_edit_messages(&self) -> Option<bool> {
match self {
Self::Administrator(val) => val.can_edit_messages,
_ => None,
}
}
/// Helper method for field `can_edit_stories`.
///
/// `true`, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat's story archive
#[must_use]
pub fn can_edit_stories(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_edit_stories),
_ => None,
}
}
/// Helper method for field `can_edit_tag`.
///
/// `true`, if the user is allowed to edit their own tag
#[must_use]
pub fn can_edit_tag(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_edit_tag),
_ => None,
}
}
/// Helper method for field `can_invite_users`.
///
/// `true`, if the user is allowed to invite new users to the chat
#[must_use]
pub fn can_invite_users(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_invite_users),
Self::Restricted(val) => Some(val.can_invite_users),
_ => None,
}
}
/// Helper method for field `can_manage_chat`.
///
/// `true`, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages, ignore slow mode, and send messages to the chat without paying Telegram Stars. Implied by any other administrator privilege.
#[must_use]
pub fn can_manage_chat(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_manage_chat),
_ => None,
}
}
/// Helper method for field `can_manage_direct_messages`.
///
/// `true`, if the administrator can manage direct messages of the channel and decline suggested posts; for channels only
#[must_use]
pub fn can_manage_direct_messages(&self) -> Option<bool> {
match self {
Self::Administrator(val) => val.can_manage_direct_messages,
_ => None,
}
}
/// Helper method for field `can_manage_tags`.
///
/// `true`, if the administrator can edit the tags of regular members; for groups and supergroups only. If omitted defaults to the value of `can_pin_messages`.
#[must_use]
pub fn can_manage_tags(&self) -> Option<bool> {
match self {
Self::Administrator(val) => val.can_manage_tags,
_ => None,
}
}
/// Helper method for field `can_manage_topics`.
///
/// # Variants
/// - `ChatMemberAdministrator`. `true`, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only
/// - `ChatMemberRestricted`. `true`, if the user is allowed to create forum topics
#[must_use]
pub fn can_manage_topics(&self) -> Option<bool> {
match self {
Self::Administrator(val) => val.can_manage_topics,
Self::Restricted(val) => Some(val.can_manage_topics),
_ => None,
}
}
/// Helper method for field `can_manage_video_chats`.
///
/// `true`, if the administrator can manage video chats
#[must_use]
pub fn can_manage_video_chats(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_manage_video_chats),
_ => None,
}
}
/// Helper method for field `can_pin_messages`.
///
/// # Variants
/// - `ChatMemberAdministrator`. `true`, if the user is allowed to pin messages; for groups and supergroups only
/// - `ChatMemberRestricted`. `true`, if the user is allowed to pin messages
#[must_use]
pub fn can_pin_messages(&self) -> Option<bool> {
match self {
Self::Administrator(val) => val.can_pin_messages,
Self::Restricted(val) => Some(val.can_pin_messages),
_ => None,
}
}
/// Helper method for field `can_post_messages`.
///
/// `true`, if the administrator can post messages in the channel, approve suggested posts, or access channel statistics; for channels only
#[must_use]
pub fn can_post_messages(&self) -> Option<bool> {
match self {
Self::Administrator(val) => val.can_post_messages,
_ => None,
}
}
/// Helper method for field `can_post_stories`.
///
/// `true`, if the administrator can post stories to the chat
#[must_use]
pub fn can_post_stories(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_post_stories),
_ => None,
}
}
/// Helper method for field `can_promote_members`.
///
/// `true`, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user)
#[must_use]
pub fn can_promote_members(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_promote_members),
_ => None,
}
}
/// Helper method for field `can_restrict_members`.
///
/// `true`, if the administrator can restrict, ban or unban chat members, or access supergroup statistics
#[must_use]
pub fn can_restrict_members(&self) -> Option<bool> {
match self {
Self::Administrator(val) => Some(val.can_restrict_members),
_ => None,
}
}
/// Helper method for field `can_send_audios`.
///
/// `true`, if the user is allowed to send audios
#[must_use]
pub fn can_send_audios(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_audios),
_ => None,
}
}
/// Helper method for field `can_send_documents`.
///
/// `true`, if the user is allowed to send documents
#[must_use]
pub fn can_send_documents(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_documents),
_ => None,
}
}
/// Helper method for field `can_send_messages`.
///
/// `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(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_messages),
_ => None,
}
}
/// Helper method for field `can_send_other_messages`.
///
/// `true`, if the user is allowed to send animations, games, stickers and use inline bots
#[must_use]
pub fn can_send_other_messages(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_other_messages),
_ => None,
}
}
/// Helper method for field `can_send_photos`.
///
/// `true`, if the user is allowed to send photos
#[must_use]
pub fn can_send_photos(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_photos),
_ => None,
}
}
/// Helper method for field `can_send_polls`.
///
/// `true`, if the user is allowed to send polls and checklists
#[must_use]
pub fn can_send_polls(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_polls),
_ => None,
}
}
/// Helper method for field `can_send_video_notes`.
///
/// `true`, if the user is allowed to send video notes
#[must_use]
pub fn can_send_video_notes(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_video_notes),
_ => None,
}
}
/// Helper method for field `can_send_videos`.
///
/// `true`, if the user is allowed to send videos
#[must_use]
pub fn can_send_videos(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_videos),
_ => None,
}
}
/// Helper method for field `can_send_voice_notes`.
///
/// `true`, if the user is allowed to send voice notes
#[must_use]
pub fn can_send_voice_notes(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.can_send_voice_notes),
_ => None,
}
}
/// Helper method for field `custom_title`.
///
/// Custom title for this user
#[must_use]
pub fn custom_title(&self) -> Option<&str> {
match self {
Self::Creator(val) => val.custom_title.as_deref(),
Self::Administrator(val) => val.custom_title.as_deref(),
_ => None,
}
}
/// Helper method for field `is_anonymous`.
///
/// `true`, if the user's presence in the chat is hidden
#[must_use]
pub fn is_anonymous(&self) -> Option<bool> {
match self {
Self::Creator(val) => Some(val.is_anonymous),
Self::Administrator(val) => Some(val.is_anonymous),
_ => None,
}
}
/// Helper method for field `is_member`.
///
/// `true`, if the user is a member of the chat at the moment of the request
#[must_use]
pub fn is_member(&self) -> Option<bool> {
match self {
Self::Restricted(val) => Some(val.is_member),
_ => None,
}
}
/// Helper method for field `tag`.
///
/// Tag of the member
#[must_use]
pub fn tag(&self) -> Option<&str> {
match self {
Self::Member(val) => val.tag.as_deref(),
Self::Restricted(val) => val.tag.as_deref(),
_ => None,
}
}
/// Helper method for field `until_date`.
///
/// # Variants
/// - `ChatMemberMember`. Date when the user's subscription will expire; Unix time
/// - `ChatMemberRestricted`. Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted forever
/// - `ChatMemberBanned`. Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever
#[must_use]
pub fn until_date(&self) -> Option<i64> {
match self {
Self::Member(val) => val.until_date,
Self::Restricted(val) => Some(val.until_date),
Self::Kicked(val) => Some(val.until_date),
_ => None,
}
}
/// Helper method for field `user`.
///
/// Information about the user
#[must_use]
pub fn user(&self) -> &crate::types::User {
match self {
Self::Creator(val) => val.user.as_ref(),
Self::Administrator(val) => val.user.as_ref(),
Self::Member(val) => val.user.as_ref(),
Self::Restricted(val) => val.user.as_ref(),
Self::Left(val) => val.user.as_ref(),
Self::Kicked(val) => val.user.as_ref(),
}
}
/// Helper method for nested field `added_to_attachment_menu`.
#[must_use]
pub fn added_to_attachment_menu(&self) -> Option<bool> {
{
let inner = self.user();
inner.added_to_attachment_menu
}
}
/// Helper method for nested field `allows_users_to_create_topics`.
#[must_use]
pub fn allows_users_to_create_topics(&self) -> Option<bool> {
{
let inner = self.user();
inner.allows_users_to_create_topics
}
}
/// Helper method for nested field `can_connect_to_business`.
#[must_use]
pub fn can_connect_to_business(&self) -> Option<bool> {
{
let inner = self.user();
inner.can_connect_to_business
}
}
/// Helper method for nested field `can_join_groups`.
#[must_use]
pub fn can_join_groups(&self) -> Option<bool> {
{
let inner = self.user();
inner.can_join_groups
}
}
/// Helper method for nested field `can_manage_bots`.
#[must_use]
pub fn can_manage_bots(&self) -> Option<bool> {
{
let inner = self.user();
inner.can_manage_bots
}
}
/// Helper method for nested field `can_read_all_group_messages`.
#[must_use]
pub fn can_read_all_group_messages(&self) -> Option<bool> {
{
let inner = self.user();
inner.can_read_all_group_messages
}
}
/// Helper method for nested field `first_name`.
#[must_use]
pub fn first_name(&self) -> &str {
{
let inner = self.user();
inner.first_name.as_ref()
}
}
/// Helper method for nested field `has_main_web_app`.
#[must_use]
pub fn has_main_web_app(&self) -> Option<bool> {
{
let inner = self.user();
inner.has_main_web_app
}
}
/// Helper method for nested field `has_topics_enabled`.
#[must_use]
pub fn has_topics_enabled(&self) -> Option<bool> {
{
let inner = self.user();
inner.has_topics_enabled
}
}
/// Helper method for nested field `id`.
#[must_use]
pub fn id(&self) -> i64 {
{
let inner = self.user();
inner.id
}
}
/// Helper method for nested field `is_bot`.
#[must_use]
pub fn is_bot(&self) -> bool {
{
let inner = self.user();
inner.is_bot
}
}
/// Helper method for nested field `is_premium`.
#[must_use]
pub fn is_premium(&self) -> Option<bool> {
{
let inner = self.user();
inner.is_premium
}
}
/// Helper method for nested field `language_code`.
#[must_use]
pub fn language_code(&self) -> Option<&str> {
{
let inner = self.user();
inner.language_code.as_deref()
}
}
/// Helper method for nested field `last_name`.
#[must_use]
pub fn last_name(&self) -> Option<&str> {
{
let inner = self.user();
inner.last_name.as_deref()
}
}
/// Helper method for nested field `supports_inline_queries`.
#[must_use]
pub fn supports_inline_queries(&self) -> Option<bool> {
{
let inner = self.user();
inner.supports_inline_queries
}
}
/// Helper method for nested field `username`.
#[must_use]
pub fn username(&self) -> Option<&str> {
{
let inner = self.user();
inner.username.as_deref()
}
}
}
impl From<crate::types::ChatMemberOwner> for ChatMember {
fn from(val: crate::types::ChatMemberOwner) -> Self {
Self::Creator(val)
}
}
impl TryFrom<ChatMember> for crate::types::ChatMemberOwner {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: ChatMember) -> Result<Self, Self::Error> {
if let ChatMember::Creator(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(ChatMember),
stringify!(ChatMemberOwner),
))
}
}
}
impl From<crate::types::ChatMemberAdministrator> for ChatMember {
fn from(val: crate::types::ChatMemberAdministrator) -> Self {
Self::Administrator(val)
}
}
impl TryFrom<ChatMember> for crate::types::ChatMemberAdministrator {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: ChatMember) -> Result<Self, Self::Error> {
if let ChatMember::Administrator(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(ChatMember),
stringify!(ChatMemberAdministrator),
))
}
}
}
impl From<crate::types::ChatMemberMember> for ChatMember {
fn from(val: crate::types::ChatMemberMember) -> Self {
Self::Member(val)
}
}
impl TryFrom<ChatMember> for crate::types::ChatMemberMember {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: ChatMember) -> Result<Self, Self::Error> {
if let ChatMember::Member(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(ChatMember),
stringify!(ChatMemberMember),
))
}
}
}
impl From<crate::types::ChatMemberRestricted> for ChatMember {
fn from(val: crate::types::ChatMemberRestricted) -> Self {
Self::Restricted(val)
}
}
impl TryFrom<ChatMember> for crate::types::ChatMemberRestricted {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: ChatMember) -> Result<Self, Self::Error> {
if let ChatMember::Restricted(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(ChatMember),
stringify!(ChatMemberRestricted),
))
}
}
}
impl From<crate::types::ChatMemberLeft> for ChatMember {
fn from(val: crate::types::ChatMemberLeft) -> Self {
Self::Left(val)
}
}
impl TryFrom<ChatMember> for crate::types::ChatMemberLeft {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: ChatMember) -> Result<Self, Self::Error> {
if let ChatMember::Left(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(ChatMember),
stringify!(ChatMemberLeft),
))
}
}
}
impl From<crate::types::ChatMemberBanned> for ChatMember {
fn from(val: crate::types::ChatMemberBanned) -> Self {
Self::Kicked(val)
}
}
impl TryFrom<ChatMember> for crate::types::ChatMemberBanned {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: ChatMember) -> Result<Self, Self::Error> {
if let ChatMember::Kicked(inner) = val {
Ok(inner)
} else {
Err(Self::Error::new(
stringify!(ChatMember),
stringify!(ChatMemberBanned),
))
}
}
}