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
use serde::{Deserialize, Serialize};

/// Describes actions that a non-administrator user is allowed to take in a
/// chat.
///
/// [The official docs](https://core.telegram.org/bots/api#chatpermissions).
#[serde_with_macros::skip_serializing_none]
#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ChatPermissions {
    /// `true`, if the user is allowed to send text messages, contacts,
    /// locations and venues.
    pub can_send_messages: Option<bool>,

    /// `true`, if the user is allowed to send audios, documents,
    /// photos, videos, video notes and voice notes, implies
    /// `can_send_messages`.
    pub can_send_media_messages: Option<bool>,

    /// `true`, if the user is allowed to send polls, implies
    /// `can_send_messages`.
    pub can_send_polls: Option<bool>,

    /// `true`, if the user is allowed to send animations, games, stickers and
    /// use inline bots, implies `can_send_media_messages`.
    pub can_send_other_messages: Option<bool>,

    /// `true`, if the user is allowed to add web page previews to
    /// their messages, implies `can_send_media_messages`.
    pub can_add_web_page_previews: Option<bool>,

    /// `true`, if the user is allowed to change the chat title, photo and
    /// other settings. Ignored in public supergroups.
    pub can_change_info: Option<bool>,

    /// `true`, if the user is allowed to invite new users to the chat.
    pub can_invite_users: Option<bool>,

    /// `true`, if the user is allowed to pin messages. Ignored in public
    /// supergroups.
    pub can_pin_messages: Option<bool>,
}

impl ChatPermissions {
    pub const fn new() -> Self {
        Self {
            can_send_messages: None,
            can_send_media_messages: None,
            can_send_polls: None,
            can_send_other_messages: None,
            can_add_web_page_previews: None,
            can_change_info: None,
            can_invite_users: None,
            can_pin_messages: None,
        }
    }

    pub const fn can_send_messages(mut self, val: bool) -> Self {
        self.can_send_messages = Some(val);
        self
    }

    pub const fn can_send_media_messages(mut self, val: bool) -> Self {
        self.can_send_media_messages = Some(val);
        self
    }

    pub const fn can_send_polls(mut self, val: bool) -> Self {
        self.can_send_polls = Some(val);
        self
    }

    pub const fn can_send_other_messages(mut self, val: bool) -> Self {
        self.can_send_other_messages = Some(val);
        self
    }

    pub const fn can_add_web_page_previews(mut self, val: bool) -> Self {
        self.can_add_web_page_previews = Some(val);
        self
    }

    pub const fn can_change_info(mut self, val: bool) -> Self {
        self.can_change_info = Some(val);
        self
    }

    pub const fn can_invite_users(mut self, val: bool) -> Self {
        self.can_invite_users = Some(val);
        self
    }

    pub const fn can_pin_messages(mut self, val: bool) -> Self {
        self.can_pin_messages = Some(val);
        self
    }
}