conogram/entities/
bot_command_scope.rs

1use serde::{Deserialize, Serialize};
2
3use crate::entities::{
4    bot_command_scope_all_chat_administrators::BotCommandScopeAllChatAdministrators,
5    bot_command_scope_all_group_chats::BotCommandScopeAllGroupChats,
6    bot_command_scope_all_private_chats::BotCommandScopeAllPrivateChats,
7    bot_command_scope_chat::BotCommandScopeChat,
8    bot_command_scope_chat_administrators::BotCommandScopeChatAdministrators,
9    bot_command_scope_chat_member::BotCommandScopeChatMember,
10    bot_command_scope_default::BotCommandScopeDefault,
11};
12
13/// This object represents the scope to which bot commands are applied. Currently, the following 7 scopes are supported:
14///
15/// * [BotCommandScopeDefault](https://core.telegram.org/bots/api/#botcommandscopedefault)
16/// * [BotCommandScopeAllPrivateChats](https://core.telegram.org/bots/api/#botcommandscopeallprivatechats)
17/// * [BotCommandScopeAllGroupChats](https://core.telegram.org/bots/api/#botcommandscopeallgroupchats)
18/// * [BotCommandScopeAllChatAdministrators](https://core.telegram.org/bots/api/#botcommandscopeallchatadministrators)
19/// * [BotCommandScopeChat](https://core.telegram.org/bots/api/#botcommandscopechat)
20/// * [BotCommandScopeChatAdministrators](https://core.telegram.org/bots/api/#botcommandscopechatadministrators)
21/// * [BotCommandScopeChatMember](https://core.telegram.org/bots/api/#botcommandscopechatmember)
22///
23/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscope)
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25#[serde(tag = "type")]
26pub enum BotCommandScope {
27    /// Represents the default [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands. Default commands are used if no commands with a [narrower scope](https://core.telegram.org/bots/api/#determining-list-of-commands) are specified for the user.
28    ///
29    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopedefault)
30    #[serde(rename = "default")]
31    Default(BotCommandScopeDefault),
32
33    /// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all private chats.
34    ///
35    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopeallprivatechats)
36    #[serde(rename = "all_private_chats")]
37    AllPrivateChats(BotCommandScopeAllPrivateChats),
38
39    /// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all group and supergroup chats.
40    ///
41    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopeallgroupchats)
42    #[serde(rename = "all_group_chats")]
43    AllGroupChats(BotCommandScopeAllGroupChats),
44
45    /// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all group and supergroup chat administrators.
46    ///
47    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopeallchatadministrators)
48    #[serde(rename = "all_chat_administrators")]
49    AllChatAdministrators(BotCommandScopeAllChatAdministrators),
50
51    /// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering a specific chat.
52    ///
53    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopechat)
54    #[serde(rename = "chat")]
55    Chat(BotCommandScopeChat),
56
57    /// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all administrators of a specific group or supergroup chat.
58    ///
59    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopechatadministrators)
60    #[serde(rename = "chat_administrators")]
61    ChatAdministrators(BotCommandScopeChatAdministrators),
62
63    /// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering a specific member of a group or supergroup chat.
64    ///
65    /// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopechatmember)
66    #[serde(rename = "chat_member")]
67    ChatMember(BotCommandScopeChatMember),
68}
69
70impl Default for BotCommandScope {
71    fn default() -> Self {
72        Self::Default(BotCommandScopeDefault::default())
73    }
74}
75
76impl From<BotCommandScopeDefault> for BotCommandScope {
77    fn from(value: BotCommandScopeDefault) -> Self {
78        Self::Default(value)
79    }
80}
81
82impl From<BotCommandScopeAllPrivateChats> for BotCommandScope {
83    fn from(value: BotCommandScopeAllPrivateChats) -> Self {
84        Self::AllPrivateChats(value)
85    }
86}
87
88impl From<BotCommandScopeAllGroupChats> for BotCommandScope {
89    fn from(value: BotCommandScopeAllGroupChats) -> Self {
90        Self::AllGroupChats(value)
91    }
92}
93
94impl From<BotCommandScopeAllChatAdministrators> for BotCommandScope {
95    fn from(value: BotCommandScopeAllChatAdministrators) -> Self {
96        Self::AllChatAdministrators(value)
97    }
98}
99
100impl From<BotCommandScopeChat> for BotCommandScope {
101    fn from(value: BotCommandScopeChat) -> Self {
102        Self::Chat(value)
103    }
104}
105
106impl From<BotCommandScopeChatAdministrators> for BotCommandScope {
107    fn from(value: BotCommandScopeChatAdministrators) -> Self {
108        Self::ChatAdministrators(value)
109    }
110}
111
112impl From<BotCommandScopeChatMember> for BotCommandScope {
113    fn from(value: BotCommandScopeChatMember) -> Self {
114        Self::ChatMember(value)
115    }
116}
117
118// Divider: all content below this line will be preserved after code regen
119use std::fmt::Display;
120
121impl Display for BotCommandScope {
122    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
123        f.write_str(match self {
124            Self::Default(_) => "default",
125            Self::AllPrivateChats(_) => "all_private_chats",
126            Self::AllGroupChats(_) => "all_group_chats",
127            Self::AllChatAdministrators(_) => "all_chat_administrators",
128            Self::Chat(_) => "chat",
129            Self::ChatAdministrators(_) => "chat_administrators",
130            Self::ChatMember(_) => "chat_member",
131        })
132    }
133}
134
135use super::misc::chat_id::ChatId;
136impl BotCommandScope {
137    pub fn chat(chat_id: impl Into<ChatId>) -> Self {
138        BotCommandScopeChat {
139            chat_id: chat_id.into(),
140        }
141        .into()
142    }
143
144    pub fn chat_member(chat_id: impl Into<ChatId>, user_id: impl Into<i64>) -> Self {
145        BotCommandScopeChatMember {
146            chat_id: chat_id.into(),
147            user_id: user_id.into(),
148        }
149        .into()
150    }
151
152    pub fn chat_administrators(chat_id: impl Into<ChatId>) -> Self {
153        BotCommandScopeChatAdministrators {
154            chat_id: chat_id.into(),
155        }
156        .into()
157    }
158
159    pub fn all_private_chats() -> Self {
160        BotCommandScopeAllPrivateChats {}.into()
161    }
162
163    pub fn all_group_chats() -> Self {
164        BotCommandScopeAllGroupChats {}.into()
165    }
166
167    pub fn all_chat_administrators() -> Self {
168        BotCommandScopeAllChatAdministrators {}.into()
169    }
170}