conogram/entities/
bot_command_scope.rs1use 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#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25#[serde(tag = "type")]
26pub enum BotCommandScope {
27 #[serde(rename = "default")]
31 Default(BotCommandScopeDefault),
32
33 #[serde(rename = "all_private_chats")]
37 AllPrivateChats(BotCommandScopeAllPrivateChats),
38
39 #[serde(rename = "all_group_chats")]
43 AllGroupChats(BotCommandScopeAllGroupChats),
44
45 #[serde(rename = "all_chat_administrators")]
49 AllChatAdministrators(BotCommandScopeAllChatAdministrators),
50
51 #[serde(rename = "chat")]
55 Chat(BotCommandScopeChat),
56
57 #[serde(rename = "chat_administrators")]
61 ChatAdministrators(BotCommandScopeChatAdministrators),
62
63 #[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
118use 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}