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
use serde::{Deserialize, Serialize};
use crate::entities::{
bot_command_scope_all_chat_administrators::BotCommandScopeAllChatAdministrators,
bot_command_scope_all_group_chats::BotCommandScopeAllGroupChats,
bot_command_scope_all_private_chats::BotCommandScopeAllPrivateChats,
bot_command_scope_chat::BotCommandScopeChat,
bot_command_scope_chat_administrators::BotCommandScopeChatAdministrators,
bot_command_scope_chat_member::BotCommandScopeChatMember,
bot_command_scope_default::BotCommandScopeDefault,
};
/// This object represents the scope to which bot commands are applied. Currently, the following 7 scopes are supported:
///
/// * [BotCommandScopeDefault](https://core.telegram.org/bots/api/#botcommandscopedefault)
/// * [BotCommandScopeAllPrivateChats](https://core.telegram.org/bots/api/#botcommandscopeallprivatechats)
/// * [BotCommandScopeAllGroupChats](https://core.telegram.org/bots/api/#botcommandscopeallgroupchats)
/// * [BotCommandScopeAllChatAdministrators](https://core.telegram.org/bots/api/#botcommandscopeallchatadministrators)
/// * [BotCommandScopeChat](https://core.telegram.org/bots/api/#botcommandscopechat)
/// * [BotCommandScopeChatAdministrators](https://core.telegram.org/bots/api/#botcommandscopechatadministrators)
/// * [BotCommandScopeChatMember](https://core.telegram.org/bots/api/#botcommandscopechatmember)
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscope)
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum BotCommandScope {
/// 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.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopedefault)
#[serde(rename = "default")]
Default(BotCommandScopeDefault),
/// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all private chats.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopeallprivatechats)
#[serde(rename = "all_private_chats")]
AllPrivateChats(BotCommandScopeAllPrivateChats),
/// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all group and supergroup chats.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopeallgroupchats)
#[serde(rename = "all_group_chats")]
AllGroupChats(BotCommandScopeAllGroupChats),
/// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all group and supergroup chat administrators.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopeallchatadministrators)
#[serde(rename = "all_chat_administrators")]
AllChatAdministrators(BotCommandScopeAllChatAdministrators),
/// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering a specific chat.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopechat)
#[serde(rename = "chat")]
Chat(BotCommandScopeChat),
/// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering all administrators of a specific group or supergroup chat.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopechatadministrators)
#[serde(rename = "chat_administrators")]
ChatAdministrators(BotCommandScopeChatAdministrators),
/// Represents the [scope](https://core.telegram.org/bots/api/#botcommandscope) of bot commands, covering a specific member of a group or supergroup chat.
///
/// API Reference: [link](https://core.telegram.org/bots/api/#botcommandscopechatmember)
#[serde(rename = "chat_member")]
ChatMember(BotCommandScopeChatMember),
}
impl Default for BotCommandScope {
fn default() -> Self {
Self::Default(BotCommandScopeDefault::default())
}
}
impl From<BotCommandScopeDefault> for BotCommandScope {
fn from(value: BotCommandScopeDefault) -> Self {
Self::Default(value)
}
}
impl From<BotCommandScopeAllPrivateChats> for BotCommandScope {
fn from(value: BotCommandScopeAllPrivateChats) -> Self {
Self::AllPrivateChats(value)
}
}
impl From<BotCommandScopeAllGroupChats> for BotCommandScope {
fn from(value: BotCommandScopeAllGroupChats) -> Self {
Self::AllGroupChats(value)
}
}
impl From<BotCommandScopeAllChatAdministrators> for BotCommandScope {
fn from(value: BotCommandScopeAllChatAdministrators) -> Self {
Self::AllChatAdministrators(value)
}
}
impl From<BotCommandScopeChat> for BotCommandScope {
fn from(value: BotCommandScopeChat) -> Self {
Self::Chat(value)
}
}
impl From<BotCommandScopeChatAdministrators> for BotCommandScope {
fn from(value: BotCommandScopeChatAdministrators) -> Self {
Self::ChatAdministrators(value)
}
}
impl From<BotCommandScopeChatMember> for BotCommandScope {
fn from(value: BotCommandScopeChatMember) -> Self {
Self::ChatMember(value)
}
}
// Divider: all content below this line will be preserved after code regen
use std::fmt::Display;
impl Display for BotCommandScope {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Default(_) => "default",
Self::AllPrivateChats(_) => "all_private_chats",
Self::AllGroupChats(_) => "all_group_chats",
Self::AllChatAdministrators(_) => "all_chat_administrators",
Self::Chat(_) => "chat",
Self::ChatAdministrators(_) => "chat_administrators",
Self::ChatMember(_) => "chat_member",
})
}
}
use super::misc::chat_id::ChatId;
impl BotCommandScope {
pub fn chat(chat_id: impl Into<ChatId>) -> Self {
BotCommandScopeChat {
chat_id: chat_id.into(),
}
.into()
}
pub fn chat_member(chat_id: impl Into<ChatId>, user_id: impl Into<i64>) -> Self {
BotCommandScopeChatMember {
chat_id: chat_id.into(),
user_id: user_id.into(),
}
.into()
}
pub fn chat_administrators(chat_id: impl Into<ChatId>) -> Self {
BotCommandScopeChatAdministrators {
chat_id: chat_id.into(),
}
.into()
}
pub fn all_private_chats() -> Self {
BotCommandScopeAllPrivateChats {}.into()
}
pub fn all_group_chats() -> Self {
BotCommandScopeAllGroupChats {}.into()
}
pub fn all_chat_administrators() -> Self {
BotCommandScopeAllChatAdministrators {}.into()
}
}