tgbot/types/definitions/chat/
member.rs

1use serde::{Deserialize, Deserializer, Serialize, Serializer};
2
3use crate::{
4    api::{Method, Payload},
5    types::{Chat, ChatId, ChatInviteLink, ChatPermissions, Integer, User},
6};
7
8/// Represents a member of a chat.
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
11#[serde(rename_all = "snake_case")]
12#[serde(tag = "status")]
13pub enum ChatMember {
14    /// Represents a chat administrator.
15    Administrator(ChatMemberAdministrator),
16    /// Represents a chat creator.
17    Creator(ChatMemberCreator),
18    /// Represents a kicked user.
19    Kicked(ChatMemberKicked),
20    /// Represents a user who left the chat.
21    #[serde(deserialize_with = "ChatMemberUser::deserialize_value")]
22    #[serde(serialize_with = "ChatMemberUser::serialize_value")]
23    Left(User),
24    /// Represents a regular chat member.
25    Member {
26        /// Information about the user
27        user: User,
28        /// Date when the user's subscription will expire; Unix time
29        until_date: Option<Integer>,
30    },
31    /// Represents a restricted user.
32    Restricted(ChatMemberRestricted),
33}
34
35impl ChatMember {
36    /// Returns the user object associated with the chat member.
37    pub fn get_user(&self) -> &User {
38        use self::ChatMember::*;
39        match self {
40            Administrator(admin) => &admin.user,
41            Creator(creator) => &creator.user,
42            Kicked(kicked) => &kicked.user,
43            Left(user) => user,
44            Member { user, .. } => user,
45            Restricted(restricted) => &restricted.user,
46        }
47    }
48
49    /// Checks if a user is a member of the chat.
50    pub fn is_member(&self) -> bool {
51        use self::ChatMember::*;
52        match self {
53            Administrator(_) | Creator(_) | Member { .. } => true,
54            Kicked(_) | Left(_) => false,
55            Restricted(restricted) => restricted.is_member,
56        }
57    }
58}
59
60#[derive(Deserialize, Serialize)]
61struct ChatMemberUser {
62    user: User,
63}
64
65impl ChatMemberUser {
66    fn deserialize_value<'de, T>(deserializer: T) -> Result<User, T::Error>
67    where
68        T: Deserializer<'de>,
69    {
70        ChatMemberUser::deserialize(deserializer).map(|x| x.user)
71    }
72
73    fn serialize_value<T>(value: &User, serializer: T) -> Result<T::Ok, T::Error>
74    where
75        T: Serializer,
76    {
77        let value = ChatMemberUser { user: value.clone() };
78        value.serialize(serializer)
79    }
80}
81
82/// Represents a chat administrator.
83#[serde_with::skip_serializing_none]
84#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
85pub struct ChatMemberAdministrator {
86    /// Information about the user.
87    pub user: User,
88    /// Indicates whether a bot is allowed to edit administrator privileges of that user.
89    pub can_be_edited: bool,
90    /// Indicates whether the administrator can change the chat title, photo and other settings.
91    pub can_change_info: bool,
92    /// Indicates whether the administrator can delete messages of other users.
93    pub can_delete_messages: bool,
94    /// Indicates whether the administrator can delete stories posted by other users;
95    /// channels only.
96    pub can_delete_stories: Option<bool>,
97    /// Indicates whether the administrator can edit messages
98    /// of other users and can pin messages; channels only.
99    pub can_edit_messages: Option<bool>,
100    /// Indicates whether the administrator can edit stories posted by other users; channels only.
101    pub can_edit_stories: Option<bool>,
102    /// Indicates whether the administrator can invite new users to the chat.
103    pub can_invite_users: bool,
104    /// Indicates whether the administrator can access the chat event log,
105    /// chat statistics, message statistics in channels, see channel members,
106    /// see anonymous administrators in supergroups and ignore slow mode;
107    /// implied by any other administrator privilege.
108    pub can_manage_chat: bool,
109    /// Whether the administrator can manage direct messages
110    /// of the channel and decline suggested posts; for channels only.
111    pub can_manage_direct_messages: Option<bool>,
112    /// Indicates whether the administrator is allowed to
113    /// create, rename, close, and reopen forum topics; supergroups only.
114    pub can_manage_topics: Option<bool>,
115    /// Indicates whether the administrator can manage video chats.
116    pub can_manage_video_chats: bool,
117    /// Indicates whether the administrator can pin messages; groups and supergroups only.
118    pub can_pin_messages: Option<bool>,
119    /// Indicates whether the administrator can post in the channel; channels only.
120    pub can_post_messages: Option<bool>,
121    /// Indicates whether the administrator can post stories in the channel; channels only.
122    pub can_post_stories: Option<bool>,
123    /// Indicates whether the administrator can add new administrators with a subset
124    /// of his own privileges or demote administrators that he has promoted,
125    /// directly or indirectly (promoted by administrators that were appointed by the user).
126    pub can_promote_members: bool,
127    /// Indicates whether the administrator can restrict, ban or unban chat members.
128    pub can_restrict_members: bool,
129    /// Custom title for the administrator.
130    pub custom_title: Option<String>,
131    /// Indicates whether the administrator's presence in the chat is hidden.
132    pub is_anonymous: bool,
133}
134
135impl ChatMemberAdministrator {
136    /// Creates a new `ChatMemberAdministrator`
137    ///
138    /// # Arguments
139    ///
140    /// * `user` - Information about the user.
141    pub fn new(user: User) -> Self {
142        Self {
143            user,
144            can_be_edited: false,
145            can_change_info: false,
146            can_delete_messages: false,
147            can_delete_stories: None,
148            can_edit_messages: None,
149            can_edit_stories: None,
150            can_invite_users: false,
151            can_manage_chat: false,
152            can_manage_direct_messages: None,
153            can_manage_topics: None,
154            can_manage_video_chats: false,
155            can_pin_messages: None,
156            can_post_messages: None,
157            can_post_stories: None,
158            can_promote_members: false,
159            can_restrict_members: false,
160            is_anonymous: false,
161            custom_title: None,
162        }
163    }
164
165    /// Sets a new value for the `can_be_edited` flag.
166    ///
167    /// # Arguments
168    ///
169    /// * `value` - Indicates whether a bot is allowed to edit privileges of that administrator.
170    pub fn with_can_be_edited(mut self, value: bool) -> Self {
171        self.can_be_edited = value;
172        self
173    }
174
175    /// Sets a new value for the `can_change_info` flag.
176    ///
177    /// # Arguments
178    ///
179    /// * `value` - Indicates whether the administrator can change the chat title,
180    ///   photo and other settings.
181    pub fn with_can_change_info(mut self, value: bool) -> Self {
182        self.can_change_info = value;
183        self
184    }
185
186    /// Sets a new value for the `can_delete_messages` flag.
187    ///
188    /// # Arguments
189    ///
190    /// * `value` - Indicates whether the administrator can delete messages of other users.
191    pub fn with_can_delete_messages(mut self, value: bool) -> Self {
192        self.can_delete_messages = value;
193        self
194    }
195
196    /// Sets a new value for the `can_delete_stories` flag.
197    ///
198    /// # Arguments
199    ///
200    /// * `value` - Indicates whether the administrator
201    ///   can delete stories posted by other users; channels only.
202    pub fn with_can_delete_stories(mut self, value: bool) -> Self {
203        self.can_delete_stories = Some(value);
204        self
205    }
206
207    /// Sets a new value for the `can_edit_messages` flag.
208    ///
209    /// # Arguments
210    ///
211    /// * `value` - Indicates whether the administrator can edit messages
212    ///   of other users and can pin messages; channels only.
213    pub fn with_can_edit_messages(mut self, value: bool) -> Self {
214        self.can_edit_messages = Some(value);
215        self
216    }
217
218    /// Sets a new value for the `can_edit_stories` flag.
219    ///
220    /// # Arguments
221    ///
222    /// * `value` - Indicates whether the administrator can
223    ///   edit stories posted by other users; channels only.
224    pub fn with_can_edit_stories(mut self, value: bool) -> Self {
225        self.can_edit_stories = Some(value);
226        self
227    }
228
229    /// Sets a new value for the `can_invite_users` flag.
230    ///
231    /// # Arguments
232    ///
233    /// * `value` - Indicates whether the administrator can invite new users to the chat.
234    pub fn with_can_invite_users(mut self, value: bool) -> Self {
235        self.can_invite_users = value;
236        self
237    }
238
239    /// Sets a new value for the `can_manage_chat` flag.
240    ///
241    /// # Arguments
242    ///
243    /// * `value` - Indicates whether the administrator can access the chat event log,
244    ///   chat statistics, message statistics in channels, see channel members,
245    ///   see anonymous administrators in supergroups and ignore slow mode;
246    ///   implied by any other administrator privilege.
247    pub fn with_can_manage_chat(mut self, value: bool) -> Self {
248        self.can_manage_chat = value;
249        self
250    }
251
252    /// Sets a new value for the `can_manage_direct_messages` flag.
253    ///
254    /// # Arguments
255    ///
256    /// * `value` - Whether the administrator can manage direct messages
257    ///   of the channel and decline suggested posts; for channels only
258    pub fn with_can_manage_direct_messages(mut self, value: bool) -> Self {
259        self.can_manage_direct_messages = Some(value);
260        self
261    }
262
263    /// Sets a new value for the `can_manage_topics` flag.
264    ///
265    /// # Arguments
266    ///
267    /// * `value` -  Indicates whether the administrator is allowed to
268    ///   create, rename, close, and reopen forum topics; supergroups only.
269    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
270        self.can_manage_topics = Some(value);
271        self
272    }
273
274    /// Sets a new value for the `can_manage_video_chats` flag.
275    ///
276    /// # Arguments
277    ///
278    /// * `value` - Indicates whether the administrator can manage video chats.
279    pub fn with_can_manage_video_chats(mut self, value: bool) -> Self {
280        self.can_manage_video_chats = value;
281        self
282    }
283
284    /// Sets a new value for the `can_pin_messages` flag.
285    ///
286    /// # Arguments
287    ///
288    /// * `value` - Indicates whether the administrator can pin messages;
289    ///   groups and supergroups only.
290    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
291        self.can_pin_messages = Some(value);
292        self
293    }
294
295    /// Sets a new value for the `can_post_messages` flag.
296    ///
297    /// # Arguments
298    ///
299    /// * `value` - Indicates whether the administrator can post in the channel; channels only.
300    pub fn with_can_post_messages(mut self, value: bool) -> Self {
301        self.can_post_messages = Some(value);
302        self
303    }
304
305    /// Sets a new value for the `can_post_stories` flag.
306    ///
307    /// # Arguments
308    ///
309    /// * `value` - Indicates whether the administrator can
310    ///   post stories in the channel; channels only.
311    pub fn with_can_post_stories(mut self, value: bool) -> Self {
312        self.can_post_stories = Some(value);
313        self
314    }
315
316    /// Sets a new value for the `can_promote_members` flag.
317    ///
318    /// # Arguments
319    ///
320    /// * `value` - Indicates whether the administrator can add new administrators with a subset
321    ///   of his own privileges or demote administrators that he has promoted,
322    ///   directly or indirectly (promoted by administrators
323    ///   that were appointed by the user).
324    pub fn with_can_promote_members(mut self, value: bool) -> Self {
325        self.can_promote_members = value;
326        self
327    }
328
329    /// Sets a new value for the `can_restrict_members` flag.
330    ///
331    /// # Arguments
332    ///
333    /// * `value` - Indicates whether the administrator can restrict, ban or unban chat members.
334    pub fn with_can_restrict_members(mut self, value: bool) -> Self {
335        self.can_restrict_members = value;
336        self
337    }
338
339    /// Sets a new custom title.
340    ///
341    /// # Arguments
342    ///
343    /// * `value` - Custom title for the administrator.
344    pub fn with_custom_title<T>(mut self, value: T) -> Self
345    where
346        T: Into<String>,
347    {
348        self.custom_title = Some(value.into());
349        self
350    }
351
352    /// Sets a new value for the `is_anonymous` flag.
353    ///
354    /// # Arguments
355    ///
356    /// * `value` - Indicates whether the administrator's presence in the chat is hidden.
357    pub fn with_is_anonymous(mut self, value: bool) -> Self {
358        self.is_anonymous = value;
359        self
360    }
361}
362
363/// Represents a chat member that owns the chat and has all administrator privileges.
364#[serde_with::skip_serializing_none]
365#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
366pub struct ChatMemberCreator {
367    /// Indicates whether the creator's presence in the chat is hidden.
368    pub is_anonymous: bool,
369    /// Information about the user.
370    pub user: User,
371    /// Custom title for the creator.
372    pub custom_title: Option<String>,
373}
374
375impl ChatMemberCreator {
376    /// Creates a new `ChatMemberCreator`.
377    ///
378    /// # Arguments
379    ///
380    /// * `user` - Information about the user.
381    pub fn new(user: User) -> Self {
382        Self {
383            is_anonymous: false,
384            user,
385            custom_title: None,
386        }
387    }
388
389    /// Sets a new custom title.
390    ///
391    /// # Arguments
392    ///
393    /// * `value` - Custom title for the creator.
394    pub fn with_custom_title<T>(mut self, value: T) -> Self
395    where
396        T: Into<String>,
397    {
398        self.custom_title = Some(value.into());
399        self
400    }
401
402    /// Sets a new value of an `is_anonymous` flag.
403    ///
404    /// # Arguments
405    ///
406    /// * `value` - Indicates whether the creator's presence in the chat is hidden.
407    pub fn with_is_anonymous(mut self, value: bool) -> Self {
408        self.is_anonymous = value;
409        self
410    }
411}
412
413/// Represents a kicked chat member.
414#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
415pub struct ChatMemberKicked {
416    /// Date when restrictions will be lifted for this user; unix time.
417    pub until_date: Integer,
418    /// Information about the user.
419    pub user: User,
420}
421
422impl ChatMemberKicked {
423    /// Creates a new `ChatMemberKicked`.
424    ///
425    /// # Arguments
426    ///
427    /// * `until_date` - Date when restrictions will be lifted for this user; unix time.
428    /// * `user` - Information about the user.
429    pub fn new(until_date: Integer, user: User) -> Self {
430        Self { user, until_date }
431    }
432}
433
434/// Represents a restricted user.
435#[serde_with::skip_serializing_none]
436#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
437pub struct ChatMemberRestricted {
438    /// Information about the user.
439    pub user: User,
440    /// Indicates whether the user may add web page previews to his messages.
441    pub can_add_web_page_previews: bool,
442    /// Indicates whether the user allowed to change the chat title, photo and other settings.
443    pub can_change_info: bool,
444    /// Indicates whether the user allowed to invite new users to the chat.
445    pub can_invite_users: bool,
446    /// Indicates whether the user is allowed to create forum topics.
447    pub can_manage_topics: bool,
448    /// Indicates whether the user allowed to pin messages; groups and supergroups only.
449    pub can_pin_messages: Option<bool>,
450    /// Indicates whether the user is allowed to send audios.
451    pub can_send_audios: Option<bool>,
452    /// Indicates whether the user is allowed to send documents.
453    pub can_send_documents: Option<bool>,
454    /// Indicates whether the user can send text messages, contacts, locations and venues.
455    pub can_send_messages: bool,
456    /// Indicates whether the user can send animations, games, stickers and use inline bots.
457    pub can_send_other_messages: bool,
458    /// Indicates whether the user is allowed to send photos.
459    pub can_send_photos: Option<bool>,
460    /// Indicates whether the user is allowed to send polls.
461    pub can_send_polls: bool,
462    /// Indicates whether the user is allowed to send video notes.
463    pub can_send_video_notes: Option<bool>,
464    /// Indicates whether the user is allowed to send videos.
465    pub can_send_videos: Option<bool>,
466    /// Indicates whether the user is allowed to send voice notes.
467    pub can_send_voice_notes: Option<bool>,
468    /// Indicates whether the user is a member of the chat at the moment of the request.
469    pub is_member: bool,
470    /// Date when restrictions will be lifted for this user; unix time.
471    pub until_date: Integer,
472}
473
474impl ChatMemberRestricted {
475    /// Creates a new `ChatMemberRestricted`
476    ///
477    /// # Arguments
478    ///
479    /// * `user` - Information about the user.
480    /// * `until_date` - Date when restrictions will be lifted for this user; unix time.
481    pub fn new(user: User, until_date: Integer) -> Self {
482        Self {
483            user,
484            can_add_web_page_previews: false,
485            can_change_info: false,
486            can_invite_users: false,
487            can_manage_topics: false,
488            can_pin_messages: None,
489            can_send_audios: None,
490            can_send_documents: None,
491            can_send_messages: false,
492            can_send_other_messages: false,
493            can_send_photos: None,
494            can_send_polls: false,
495            can_send_video_notes: None,
496            can_send_videos: None,
497            can_send_voice_notes: None,
498            is_member: false,
499            until_date,
500        }
501    }
502
503    /// Sets a new value for the `can_add_web_page_previews` flag.
504    ///
505    /// # Arguments
506    ///
507    /// * `value` - Indicates whether the user may add web page previews to his messages.
508    pub fn with_can_add_web_page_previews(mut self, value: bool) -> Self {
509        self.can_add_web_page_previews = value;
510        self
511    }
512
513    /// Sets a new value for the `can_change_info` flag.
514    ///
515    /// # Arguments
516    ///
517    /// * `value` - Indicates whether the user allowed to change the chat title,
518    ///   photo and other settings.
519    pub fn with_can_change_info(mut self, value: bool) -> Self {
520        self.can_change_info = value;
521        self
522    }
523
524    /// Sets a new value for the `can_invite_users` flag.
525    ///
526    /// # Arguments
527    ///
528    /// * `value` - Indicates whether the user allowed to invite new users to the chat.
529    pub fn with_can_invite_users(mut self, value: bool) -> Self {
530        self.can_invite_users = value;
531        self
532    }
533
534    /// Sets a new value for the `can_manage_topics` flag.
535    ///
536    /// # Arguments
537    ///
538    /// * `value` - Indicates whether the user is allowed to create forum topics.
539    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
540        self.can_manage_topics = value;
541        self
542    }
543
544    /// Sets a new value for the `can_pin_messages` flag.
545    ///
546    /// # Arguments
547    ///
548    /// * `value` - Indicates whether the user allowed to pin messages;
549    ///   groups and supergroups only.
550    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
551        self.can_pin_messages = Some(value);
552        self
553    }
554
555    /// Sets a new value for the `can_send_audios` flag.
556    ///
557    /// # Arguments
558    ///
559    /// * `value` - Indicates whether the user is allowed to send audios.
560    pub fn with_can_send_audios(mut self, value: bool) -> Self {
561        self.can_send_audios = Some(value);
562        self
563    }
564
565    /// Sets a new value for the `can_send_documents` flag.
566    ///
567    /// # Arguments
568    ///
569    /// * `value` - Indicates whether the user is allowed to send documents.
570    pub fn with_can_send_documents(mut self, value: bool) -> Self {
571        self.can_send_documents = Some(value);
572        self
573    }
574
575    /// Sets a new value for the `can_send_messages` flag.
576    ///
577    /// # Arguments
578    ///
579    /// * `value` - Indicates whether the user can send text messages,
580    ///   contacts, locations and venues.
581    pub fn with_can_send_messages(mut self, value: bool) -> Self {
582        self.can_send_messages = value;
583        self
584    }
585
586    /// Sets a new value for the `can_send_other_messages` flag.
587    ///
588    /// # Arguments
589    ///
590    /// * `value` - Indicates whether the user can send animations,
591    ///   games, stickers and use inline bots.
592    pub fn with_can_send_other_messages(mut self, value: bool) -> Self {
593        self.can_send_other_messages = value;
594        self
595    }
596
597    /// Sets a new value for the `can_send_photos` flag.
598    ///
599    /// # Arguments
600    ///
601    /// * `value` - Indicates whether the user is allowed to send photos.
602    pub fn with_can_send_photos(mut self, value: bool) -> Self {
603        self.can_send_photos = Some(value);
604        self
605    }
606
607    /// Sets a new value for the `can_send_polls` flag.
608    ///
609    /// # Arguments
610    ///
611    /// * `value` - Indicates whether the user is allowed to send polls.
612    pub fn with_can_send_polls(mut self, value: bool) -> Self {
613        self.can_send_polls = value;
614        self
615    }
616
617    /// Sets a new value for the `can_send_video_notes` flag.
618    ///
619    /// # Arguments
620    ///
621    /// * `value` - Indicates whether the user is allowed to send video notes.
622    pub fn with_can_send_video_notes(mut self, value: bool) -> Self {
623        self.can_send_video_notes = Some(value);
624        self
625    }
626
627    /// Sets a new value for the `can_send_videos` flag.
628    ///
629    /// # Arguments
630    ///
631    /// * `value` - Indicates whether the user is allowed to send videos.
632    pub fn with_can_send_videos(mut self, value: bool) -> Self {
633        self.can_send_videos = Some(value);
634        self
635    }
636
637    /// Sets a new value for the `can_send_voice_notes` flag.
638    ///
639    /// # Arguments
640    ///
641    /// * `value` - Indicates whether the user is allowed to send voice notes.
642    pub fn with_can_send_voice_notes(mut self, value: bool) -> Self {
643        self.can_send_voice_notes = Some(value);
644        self
645    }
646
647    /// Sets a new value for the `is_member` flag.
648    ///
649    /// # Arguments
650    ///
651    /// * `value` - Indicates whether the user is a member of the chat at the moment of the request.
652    pub fn with_is_member(mut self, value: bool) -> Self {
653        self.is_member = value;
654        self
655    }
656}
657
658/// Represents changes in a status of a chat member.
659#[serde_with::skip_serializing_none]
660#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
661pub struct ChatMemberUpdated {
662    /// Chat the user belongs to.
663    pub chat: Chat,
664    /// Date the change was done in Unix time.
665    pub date: Integer,
666    /// Performer of the action, which resulted in the change.
667    pub from: User,
668    /// New information about the chat member.
669    pub new_chat_member: ChatMember,
670    /// Previous information about the chat member.
671    pub old_chat_member: ChatMember,
672    /// Chat invite link, which was used by the user to join the chat;
673    /// for joining by invite link events only.
674    pub invite_link: Option<ChatInviteLink>,
675    /// Indicates whether the user joined the chat via a chat folder invite link.
676    pub via_chat_folder_invite_link: Option<bool>,
677    /// Indicates whether the user joined the chat after sending a direct join request
678    /// and being approved by an administrator.
679    pub via_join_request: Option<bool>,
680}
681
682impl ChatMemberUpdated {
683    /// Creates a new `ChatMemberUpdated`.
684    ///
685    /// # Arguments
686    ///
687    /// * `chat` - Chat the user belongs to.
688    /// * `date` - Date the change was done in Unix time.
689    /// * `from` - Performer of the action, which resulted in the change.
690    /// * `new_chat_member` - New information about the chat member.
691    /// * `old_chat_member` - Previous information about the chat member.
692    pub fn new(
693        chat: Chat,
694        date: Integer,
695        from: User,
696        new_chat_member: ChatMember,
697        old_chat_member: ChatMember,
698    ) -> Self {
699        Self {
700            chat,
701            date,
702            from,
703            new_chat_member,
704            old_chat_member,
705            invite_link: None,
706            via_chat_folder_invite_link: None,
707            via_join_request: None,
708        }
709    }
710
711    /// Sets a new invite link
712    ///
713    /// # Arguments
714    ///
715    /// * `value` - The invite link, which was used by the user to join the chat.
716    pub fn with_invite_link(mut self, value: ChatInviteLink) -> Self {
717        self.invite_link = Some(value);
718        self
719    }
720
721    /// Sets a new value for the `via_chat_folder_invite_link` flag.
722    ///
723    /// # Arguments
724    ///
725    /// * `value` - Indicates whether the user joined the chat via a chat folder invite link.
726    pub fn with_via_chat_folder_invite_link(mut self, value: bool) -> Self {
727        self.via_chat_folder_invite_link = Some(value);
728        self
729    }
730
731    /// Sets a new value for the `via_join_request` flag.
732    ///
733    /// # Arguments
734    ///
735    /// * `value` - Indicates whether the user joined the chat after sending a direct join request
736    ///   and being approved by an administrator.
737    pub fn with_via_join_request(mut self, value: bool) -> Self {
738        self.via_join_request = Some(value);
739        self
740    }
741}
742
743/// Bans a user in a chat.
744///
745/// In the case of supergroups and channels,
746/// the user will not be able to return to the chat on their own using invite links,
747/// etc., unless unbanned first.
748///
749/// The bot must be an administrator in the chat
750/// for this to work and must have the appropriate admin rights.
751#[serde_with::skip_serializing_none]
752#[derive(Clone, Debug, Serialize)]
753pub struct BanChatMember {
754    chat_id: ChatId,
755    user_id: Integer,
756    revoke_messages: Option<bool>,
757    until_date: Option<Integer>,
758}
759
760impl BanChatMember {
761    /// Creates a new `BanChatMember`.
762    ///
763    /// # Arguments
764    ///
765    /// * `chat_id` - Unique identifier of the target chat.
766    /// * `user_id` - Unique identifier of the target user.
767    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
768    where
769        T: Into<ChatId>,
770    {
771        Self {
772            chat_id: chat_id.into(),
773            user_id,
774            until_date: None,
775            revoke_messages: None,
776        }
777    }
778
779    /// Sets a new value for the `revoke_messages` flag.
780    ///
781    /// # Arguments
782    ///
783    /// * `value` - Delete all messages from the chat for the user that is being removed;
784    ///   if `false`, the user will be able to see messages in the group that were
785    ///   sent before the user was removed;
786    ///   always `true` for supergroups and channels.
787    pub fn with_revoke_messages(mut self, value: bool) -> Self {
788        self.revoke_messages = Some(value);
789        self
790    }
791
792    /// Sets a new until date.
793    ///
794    /// # Arguments
795    ///
796    /// * `value` - The date when the user will be unbanned, unix time.
797    ///
798    /// If user is banned for more than 366 days or less than 30 seconds
799    /// from the current time they are considered to be banned forever.
800    pub fn with_until_date(mut self, value: Integer) -> Self {
801        self.until_date = Some(value);
802        self
803    }
804}
805
806impl Method for BanChatMember {
807    type Response = bool;
808
809    fn into_payload(self) -> Payload {
810        Payload::json("banChatMember", self)
811    }
812}
813
814/// Returns a list of administrators in a chat.
815///
816/// On success, returns an array of [`ChatMember`] objects that contains
817/// information about all chat administrators except other bots.
818///
819/// If the chat is a group or a supergroup and no administrators
820/// were appointed, only the creator will be returned.
821#[derive(Clone, Debug, Serialize)]
822pub struct GetChatAdministrators {
823    chat_id: ChatId,
824}
825
826impl GetChatAdministrators {
827    /// Creates a new `GetChatAdministrators`.
828    ///
829    /// # Arguments
830    ///
831    /// * `chat_id` - Unique identifier of the target chat.
832    pub fn new<T>(chat_id: T) -> Self
833    where
834        T: Into<ChatId>,
835    {
836        Self {
837            chat_id: chat_id.into(),
838        }
839    }
840}
841
842impl Method for GetChatAdministrators {
843    type Response = Vec<ChatMember>;
844
845    fn into_payload(self) -> Payload {
846        Payload::json("getChatAdministrators", self)
847    }
848}
849
850/// Returns a member of a chat.
851#[derive(Clone, Debug, Serialize)]
852pub struct GetChatMember {
853    chat_id: ChatId,
854    user_id: Integer,
855}
856
857impl GetChatMember {
858    /// Creates a new `GetChatMember`
859    ///
860    /// # Arguments
861    ///
862    /// * `chat_id` - Unique identifier of the target chat.
863    /// * `user_id` - Unique identifier of the target user.
864    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
865    where
866        T: Into<ChatId>,
867    {
868        Self {
869            chat_id: chat_id.into(),
870            user_id,
871        }
872    }
873}
874
875impl Method for GetChatMember {
876    type Response = ChatMember;
877
878    fn into_payload(self) -> Payload {
879        Payload::json("getChatMember", self)
880    }
881}
882
883/// Returns a number of members in a chat.
884#[derive(Clone, Debug, Serialize)]
885pub struct GetChatMemberCount {
886    chat_id: ChatId,
887}
888
889impl GetChatMemberCount {
890    /// Creates a new `GetChatMemberCount`.
891    ///
892    /// # Arguments
893    ///
894    /// * `chat_id` - Unique identifier of the target chat.
895    pub fn new<T>(chat_id: T) -> Self
896    where
897        T: Into<ChatId>,
898    {
899        Self {
900            chat_id: chat_id.into(),
901        }
902    }
903}
904
905impl Method for GetChatMemberCount {
906    type Response = Integer;
907
908    fn into_payload(self) -> Payload {
909        Payload::json("getChatMemberCount", self)
910    }
911}
912
913/// Promotes or demotes a user in a chat.
914///
915/// The bot must be an administrator in the chat
916/// for this to work and must have the appropriate admin rights.
917#[serde_with::skip_serializing_none]
918#[derive(Clone, Debug, Serialize)]
919pub struct PromoteChatMember {
920    chat_id: ChatId,
921    user_id: Integer,
922    can_change_info: Option<bool>,
923    can_delete_messages: Option<bool>,
924    can_delete_stories: Option<bool>,
925    can_edit_messages: Option<bool>,
926    can_edit_stories: Option<bool>,
927    can_invite_users: Option<bool>,
928    can_manage_chat: Option<bool>,
929    can_manage_direct_messages: Option<bool>,
930    can_manage_topics: Option<bool>,
931    can_manage_video_chats: Option<bool>,
932    can_pin_messages: Option<bool>,
933    can_post_messages: Option<bool>,
934    can_post_stories: Option<bool>,
935    can_promote_members: Option<bool>,
936    can_restrict_members: Option<bool>,
937    is_anonymous: Option<bool>,
938}
939
940impl PromoteChatMember {
941    /// Creates a new `PromoteChatMember`
942    ///
943    /// # Arguments
944    ///
945    /// * `chat_id` - Unique identifier of the target chat.
946    /// * `user_id` - Unique identifier of the target user.
947    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
948    where
949        T: Into<ChatId>,
950    {
951        Self {
952            chat_id: chat_id.into(),
953            user_id,
954            can_change_info: None,
955            can_delete_messages: None,
956            can_delete_stories: None,
957            can_edit_messages: None,
958            can_edit_stories: None,
959            can_invite_users: None,
960            can_manage_chat: None,
961            can_manage_direct_messages: None,
962            can_manage_topics: None,
963            can_manage_video_chats: None,
964            can_pin_messages: None,
965            can_post_messages: None,
966            can_post_stories: None,
967            can_promote_members: None,
968            can_restrict_members: None,
969            is_anonymous: None,
970        }
971    }
972
973    /// Promotes all privileges.
974    pub fn promote_all(mut self) -> Self {
975        self.is_anonymous = Some(true);
976        self.can_change_info = Some(true);
977        self.can_delete_messages = Some(true);
978        self.can_delete_stories = Some(true);
979        self.can_edit_messages = Some(true);
980        self.can_edit_stories = Some(true);
981        self.can_invite_users = Some(true);
982        self.can_manage_chat = Some(true);
983        self.can_manage_direct_messages = Some(true);
984        self.can_manage_topics = Some(true);
985        self.can_manage_video_chats = Some(true);
986        self.can_pin_messages = Some(true);
987        self.can_post_messages = Some(true);
988        self.can_post_stories = Some(true);
989        self.can_promote_members = Some(true);
990        self.can_restrict_members = Some(true);
991        self
992    }
993
994    /// Demotes all privileges.
995    pub fn demote_all(mut self) -> Self {
996        self.is_anonymous = Some(false);
997        self.can_change_info = Some(false);
998        self.can_delete_messages = Some(false);
999        self.can_delete_stories = Some(false);
1000        self.can_edit_messages = Some(false);
1001        self.can_edit_stories = Some(false);
1002        self.can_invite_users = Some(false);
1003        self.can_manage_chat = Some(false);
1004        self.can_manage_direct_messages = Some(false);
1005        self.can_manage_topics = Some(false);
1006        self.can_manage_video_chats = Some(false);
1007        self.can_pin_messages = Some(false);
1008        self.can_post_messages = Some(false);
1009        self.can_post_stories = Some(false);
1010        self.can_promote_members = Some(false);
1011        self.can_restrict_members = Some(false);
1012        self
1013    }
1014
1015    /// Sets a new value for the `can_change_info` flag.
1016    ///
1017    /// # Arguments
1018    ///
1019    /// * `value` - Indicates whether the administrator can change chat title,
1020    ///   photo and other settings.
1021    pub fn with_can_change_info(mut self, value: bool) -> Self {
1022        self.can_change_info = Some(value);
1023        self
1024    }
1025
1026    /// Sets a new value for the `can_delete_messages` flag.
1027    ///
1028    /// # Arguments
1029    ///
1030    /// * `value` - Indicates whether the administrator can delete messages of other users.
1031    pub fn with_can_delete_messages(mut self, value: bool) -> Self {
1032        self.can_delete_messages = Some(value);
1033        self
1034    }
1035
1036    /// Sets a new value for the `can_delete_stories` flag.
1037    ///
1038    /// # Arguments
1039    ///
1040    /// * `value` - Indicates whether the administrator can delete stories posted by other users; channels only.
1041    pub fn with_can_delete_stories(mut self, value: bool) -> Self {
1042        self.can_delete_stories = Some(value);
1043        self
1044    }
1045
1046    /// Sets a new value for the `can_edit_messages` flag.
1047    ///
1048    /// # Arguments
1049    ///
1050    /// * `value` - Indicates whether the administrator can edit messages
1051    ///   of other users and can pin messages; channels only.
1052    pub fn with_can_edit_messages(mut self, value: bool) -> Self {
1053        self.can_edit_messages = Some(value);
1054        self
1055    }
1056
1057    /// Sets a new value for the `can_edit_stories` flag.
1058    ///
1059    /// # Arguments
1060    ///
1061    /// * `value` - Indicates whether the administrator can
1062    ///   edit stories posted by other users; channels only.
1063    pub fn with_can_edit_stories(mut self, value: bool) -> Self {
1064        self.can_edit_stories = Some(value);
1065        self
1066    }
1067
1068    /// Sets a new value for the `can_invite_users` flag.
1069    ///
1070    /// # Arguments
1071    ///
1072    /// * `value` - Indicates whether the administrator can invite new users to the chat.
1073    pub fn with_can_invite_users(mut self, value: bool) -> Self {
1074        self.can_invite_users = Some(value);
1075        self
1076    }
1077
1078    /// Sets a new value for the `can_manage_chat` flag.
1079    ///
1080    /// # Arguments
1081    ///
1082    /// * `value` - Indicates whether the administrator can access the chat event log,
1083    ///   chat statistics, message statistics in channels, see channel members,
1084    ///   see anonymous administrators in supergroups and ignore slow mode;
1085    ///   implied by any other administrator privilege.
1086    pub fn with_can_manage_chat(mut self, value: bool) -> Self {
1087        self.can_manage_chat = Some(value);
1088        self
1089    }
1090
1091    /// Sets a new value for the `can_manage_direct_messages` flag.
1092    ///
1093    /// # Arguments
1094    ///
1095    /// * `value` - Whether the administrator can manage direct messages
1096    ///   within the channel and decline suggested posts; for channels only.
1097    pub fn with_can_manage_direct_messages(mut self, value: bool) -> Self {
1098        self.can_manage_direct_messages = Some(value);
1099        self
1100    }
1101
1102    /// Sets a new value for the `can_manage_topics` flag.
1103    ///
1104    /// # Arguments
1105    ///
1106    /// * `value` - User is allowed to create, rename, close, and reopen forum topics; supergroups only.
1107    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
1108        self.can_manage_topics = Some(value);
1109        self
1110    }
1111
1112    /// Sets a new value for the `can_manage_video_chats` flag.
1113    ///
1114    /// # Arguments
1115    ///
1116    /// * `value` - Indicates whether the administrator can manage video chats; supergroups only.
1117    pub fn with_can_manage_video_chats(mut self, value: bool) -> Self {
1118        self.can_manage_video_chats = Some(value);
1119        self
1120    }
1121
1122    /// Sets a new value for the `can_pin_messages` flag.
1123    ///
1124    /// # Arguments
1125    ///
1126    /// * `value` - Indicates whether the administrator can pin messages; supergroups only.
1127    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
1128        self.can_pin_messages = Some(value);
1129        self
1130    }
1131
1132    /// Sets a new value for the `can_post_messages` flag.
1133    ///
1134    /// # Arguments
1135    ///
1136    /// * `value` - Indicates whether the administrator can create channel posts; channels only.
1137    pub fn with_can_post_messages(mut self, value: bool) -> Self {
1138        self.can_post_messages = Some(value);
1139        self
1140    }
1141
1142    /// Sets a new value for the `can_post_stories` flag.
1143    ///
1144    /// # Arguments
1145    ///
1146    /// * `value` - Indicates whether the administrator can post stories in the channel; channels only.
1147    pub fn with_can_post_stories(mut self, value: bool) -> Self {
1148        self.can_post_stories = Some(value);
1149        self
1150    }
1151
1152    /// Sets a new value for the `can_promote_members` flag.
1153    ///
1154    /// # Arguments
1155    ///
1156    /// * `value` - Indicates whether the administrator can add new administrators with a subset
1157    ///   of his own privileges or demote administrators that he has promoted,
1158    ///   directly or indirectly (promoted by administrators that were appointed by him).
1159    pub fn with_can_promote_members(mut self, value: bool) -> Self {
1160        self.can_promote_members = Some(value);
1161        self
1162    }
1163
1164    /// Sets a new value for the `can_restrict_members` flag.
1165    ///
1166    /// # Arguments
1167    ///
1168    /// * `value` - Indicates whether the administrator can restrict, ban or unban chat members.
1169    pub fn with_can_restrict_members(mut self, value: bool) -> Self {
1170        self.can_restrict_members = Some(value);
1171        self
1172    }
1173
1174    /// Sets a new value for the `is_anonymous` flag.
1175    ///
1176    /// # Arguments
1177    ///
1178    /// * `value` - Indicates whether the administrator's presence in the chat is hidden.
1179    pub fn with_is_anonymous(mut self, value: bool) -> Self {
1180        self.is_anonymous = Some(value);
1181        self
1182    }
1183}
1184
1185impl Method for PromoteChatMember {
1186    type Response = bool;
1187
1188    fn into_payload(self) -> Payload {
1189        Payload::json("promoteChatMember", self)
1190    }
1191}
1192
1193/// Restricts a user in a supergroup.
1194///
1195/// The bot must be an administrator in the supergroup
1196/// for this to work and must have the appropriate admin rights.
1197#[serde_with::skip_serializing_none]
1198#[derive(Clone, Debug, Serialize)]
1199pub struct RestrictChatMember {
1200    chat_id: ChatId,
1201    permissions: ChatPermissions,
1202    user_id: Integer,
1203    until_date: Option<Integer>,
1204    use_independent_chat_permissions: Option<bool>,
1205}
1206
1207impl RestrictChatMember {
1208    /// Creates a new `RestrictChatMember`.
1209    ///
1210    /// # Arguments
1211    ///
1212    /// * `chat_id` - Unique identifier for the target chat.
1213    /// * `user_id` - Unique identifier of the target user.
1214    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
1215    where
1216        T: Into<ChatId>,
1217    {
1218        RestrictChatMember {
1219            chat_id: chat_id.into(),
1220            permissions: ChatPermissions::default(),
1221            user_id,
1222            until_date: None,
1223            use_independent_chat_permissions: None,
1224        }
1225    }
1226
1227    /// Allows everything.
1228    pub fn allow_all(mut self) -> Self {
1229        self.permissions = ChatPermissions::allowed();
1230        self
1231    }
1232
1233    /// Restricts everything.
1234    pub fn restrict_all(mut self) -> Self {
1235        self.permissions = ChatPermissions::restricted();
1236        self
1237    }
1238
1239    /// Replaces current permissions with the new one.
1240    ///
1241    /// # Arguments
1242    ///
1243    /// * `value` - The new permissions.
1244    pub fn with_permissions(mut self, value: ChatPermissions) -> Self {
1245        self.permissions = value;
1246        self
1247    }
1248
1249    /// Sets a new until date.
1250    ///
1251    /// # Arguments
1252    ///
1253    /// * `value` - The date when restrictions will be lifted for the user, unix time.
1254    ///
1255    /// If user is restricted for more than 366 days or less than 30 seconds
1256    /// from the current time, they are considered to be restricted forever.
1257    pub fn with_until_date(mut self, value: Integer) -> Self {
1258        self.until_date = Some(value);
1259        self
1260    }
1261
1262    /// Sets a new value for the `use_independent_chat_permissions` flag.
1263    ///
1264    /// # Arguments
1265    ///
1266    /// * `value` - Indicates whether the chat permissions are set independently.
1267    ///
1268    /// If `false`, the `can_send_other_messages` and `can_add_web_page_previews` permissions
1269    /// will imply the `can_send_messages`, `can_send_audios`, `can_send_documents`,
1270    /// `can_send_photos`, `can_send_videos`, `can_send_video_notes`,
1271    /// and `can_send_voice_notes` permissions; the `can_send_polls` permission
1272    /// will imply the `can_send_messages` permission.
1273    pub fn with_use_independent_chat_permissions(mut self, value: bool) -> Self {
1274        self.use_independent_chat_permissions = Some(value);
1275        self
1276    }
1277}
1278
1279impl Method for RestrictChatMember {
1280    type Response = bool;
1281
1282    fn into_payload(self) -> Payload {
1283        Payload::json("restrictChatMember", self)
1284    }
1285}
1286
1287/// Sets a custom title for an administrator in a supergroup promoted by the bot.
1288#[derive(Clone, Debug, Serialize)]
1289pub struct SetChatAdministratorCustomTitle {
1290    chat_id: ChatId,
1291    user_id: Integer,
1292    custom_title: String,
1293}
1294
1295impl SetChatAdministratorCustomTitle {
1296    /// Creates a new `SetChatAdministratorCustomTitle`.
1297    ///
1298    /// # Arguments
1299    ///
1300    /// * `chat_id` - Unique identifier of the target chat.
1301    /// * `custom_title` - New custom title for the administrator; 0-16 characters; emoji are not allowed.
1302    /// * `user_id` - Unique identifier of the target user.
1303    pub fn new<A, B>(chat_id: A, custom_title: B, user_id: Integer) -> Self
1304    where
1305        A: Into<ChatId>,
1306        B: Into<String>,
1307    {
1308        Self {
1309            chat_id: chat_id.into(),
1310            custom_title: custom_title.into(),
1311            user_id,
1312        }
1313    }
1314}
1315
1316impl Method for SetChatAdministratorCustomTitle {
1317    type Response = bool;
1318
1319    fn into_payload(self) -> Payload {
1320        Payload::json("setChatAdministratorCustomTitle", self)
1321    }
1322}
1323
1324/// Unbans a previously kicked user in a supergroup or channel.
1325///
1326/// The user will not return to the group or channel
1327/// automatically, but will be able to join via link, etc.
1328///
1329/// The bot must be an administrator for this to work
1330#[serde_with::skip_serializing_none]
1331#[derive(Clone, Debug, Serialize)]
1332pub struct UnbanChatMember {
1333    chat_id: ChatId,
1334    user_id: Integer,
1335    only_if_banned: Option<bool>,
1336}
1337
1338impl UnbanChatMember {
1339    /// Creates a new `UnbanChatMember`.
1340    ///
1341    /// # Arguments
1342    ///
1343    /// * `chat_id` - Unique identifier of the target chat.
1344    /// * `user_id` - Unique identifier of the target user.
1345    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
1346    where
1347        T: Into<ChatId>,
1348    {
1349        UnbanChatMember {
1350            chat_id: chat_id.into(),
1351            user_id,
1352            only_if_banned: None,
1353        }
1354    }
1355
1356    /// Sets a new value for the `only_if_banned` flag.
1357    ///
1358    /// # Arguments
1359    ///
1360    /// * `value` - If `true` - do nothing if the user is not banned.
1361    pub fn with_only_if_banned(mut self, only_if_banned: bool) -> Self {
1362        self.only_if_banned = Some(only_if_banned);
1363        self
1364    }
1365}
1366
1367impl Method for UnbanChatMember {
1368    type Response = bool;
1369
1370    fn into_payload(self) -> Payload {
1371        Payload::json("unbanChatMember", self)
1372    }
1373}