Skip to main content

telegram_bot_raw/types/
chat_member.rs

1use std::fmt;
2
3use serde::de;
4use serde::de::{Deserialize, Deserializer, Visitor};
5
6use crate::types::*;
7
8/// The member's status in the chat
9#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10pub enum ChatMemberStatus {
11    Creator,
12    Administrator,
13    Member,
14    Left,
15    Kicked,
16    #[doc(hidden)]
17    Unknown(String),
18}
19
20impl<'de> Deserialize<'de> for ChatMemberStatus {
21    fn deserialize<D>(deserializer: D) -> Result<ChatMemberStatus, D::Error>
22    where
23        D: Deserializer<'de>,
24    {
25        struct ChatMemberStatusVisitor;
26        use self::ChatMemberStatus::*;
27
28        impl<'de> Visitor<'de> for ChatMemberStatusVisitor {
29            type Value = ChatMemberStatus;
30
31            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
32                formatter.write_str("creator | administrator | member | left | kicked")
33            }
34
35            fn visit_str<E>(self, value: &str) -> Result<ChatMemberStatus, E>
36            where
37                E: de::Error,
38            {
39                Ok(match value {
40                    "creator" => Creator,
41                    "administrator" => Administrator,
42                    "member" => Member,
43                    "left" => Left,
44                    "kicked" => Kicked,
45                    _unknown => Unknown(value.to_string()),
46                })
47            }
48        }
49
50        deserializer.deserialize_str(ChatMemberStatusVisitor)
51    }
52}
53
54/// This object contains information about one member of the chat.
55#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Deserialize)]
56pub struct ChatMember {
57    /// Information about the user.
58    pub user: User,
59    /// The member's status in the chat.
60    pub status: ChatMemberStatus,
61    ///Optional. Restricted and kicked only. Date when restrictions will be lifted for this user, unix time
62    pub until_date: Option<Integer>,
63    ///Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user
64    pub can_be_edited: Option<bool>,
65    ///Optional. Administrators only. True, if the administrator can change the chat title, photo and other settings
66    pub can_change_info: Option<bool>,
67    ///Optional. Administrators only. True, if the administrator can post in the channel, channels only
68    pub can_post_messages: Option<bool>,
69    ///Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages, channels only
70    pub can_edit_messages: Option<bool>,
71    ///Optional. Administrators only. True, if the administrator can delete messages of other users
72    pub can_delete_messages: Option<bool>,
73    ///Optional. Administrators only. True, if the administrator can invite new users to the chat
74    pub can_invite_users: Option<bool>,
75    ///Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members
76    pub can_restrict_members: Option<bool>,
77    ///Optional. Administrators only. True, if the administrator can pin messages, supergroups only
78    pub can_pin_messages: Option<bool>,
79    ///Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
80    pub can_promote_members: Option<bool>,
81    ///Optional. Restricted only. True, if the user can send text messages, contacts, locations and venues
82    pub can_send_messages: Option<bool>,
83    ///Optional. Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
84    pub can_send_media_messages: Option<bool>,
85    ///Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
86    pub can_send_other_messages: Option<bool>,
87    ///Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages
88    pub can_add_web_page_previews: Option<bool>,
89}