rust_tdlib/types/
bot_command_scope.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Represents the scope to which bot commands are relevant
8pub trait TDBotCommandScope: Debug + RObject {}
9
10/// Represents the scope to which bot commands are relevant
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum BotCommandScope {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// A scope covering all group and supergroup chat administrators
18    #[serde(rename = "botCommandScopeAllChatAdministrators")]
19    AllChatAdministrators(BotCommandScopeAllChatAdministrators),
20    /// A scope covering all group and supergroup chats
21    #[serde(rename = "botCommandScopeAllGroupChats")]
22    AllGroupChats(BotCommandScopeAllGroupChats),
23    /// A scope covering all private chats
24    #[serde(rename = "botCommandScopeAllPrivateChats")]
25    AllPrivateChats(BotCommandScopeAllPrivateChats),
26    /// A scope covering all members of a chat
27    #[serde(rename = "botCommandScopeChat")]
28    Chat(BotCommandScopeChat),
29    /// A scope covering all administrators of a chat
30    #[serde(rename = "botCommandScopeChatAdministrators")]
31    ChatAdministrators(BotCommandScopeChatAdministrators),
32    /// A scope covering a member of a chat
33    #[serde(rename = "botCommandScopeChatMember")]
34    ChatMember(BotCommandScopeChatMember),
35    /// A scope covering all users
36    #[serde(rename = "botCommandScopeDefault")]
37    Default(BotCommandScopeDefault),
38}
39
40impl RObject for BotCommandScope {
41    #[doc(hidden)]
42    fn extra(&self) -> Option<&str> {
43        match self {
44            BotCommandScope::AllChatAdministrators(t) => t.extra(),
45            BotCommandScope::AllGroupChats(t) => t.extra(),
46            BotCommandScope::AllPrivateChats(t) => t.extra(),
47            BotCommandScope::Chat(t) => t.extra(),
48            BotCommandScope::ChatAdministrators(t) => t.extra(),
49            BotCommandScope::ChatMember(t) => t.extra(),
50            BotCommandScope::Default(t) => t.extra(),
51
52            _ => None,
53        }
54    }
55    #[doc(hidden)]
56    fn client_id(&self) -> Option<i32> {
57        match self {
58            BotCommandScope::AllChatAdministrators(t) => t.client_id(),
59            BotCommandScope::AllGroupChats(t) => t.client_id(),
60            BotCommandScope::AllPrivateChats(t) => t.client_id(),
61            BotCommandScope::Chat(t) => t.client_id(),
62            BotCommandScope::ChatAdministrators(t) => t.client_id(),
63            BotCommandScope::ChatMember(t) => t.client_id(),
64            BotCommandScope::Default(t) => t.client_id(),
65
66            _ => None,
67        }
68    }
69}
70
71impl BotCommandScope {
72    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
73        Ok(serde_json::from_str(json.as_ref())?)
74    }
75    #[doc(hidden)]
76    pub fn _is_default(&self) -> bool {
77        matches!(self, BotCommandScope::_Default)
78    }
79}
80
81impl AsRef<BotCommandScope> for BotCommandScope {
82    fn as_ref(&self) -> &BotCommandScope {
83        self
84    }
85}
86
87/// A scope covering all group and supergroup chat administrators
88#[derive(Debug, Clone, Default, Serialize, Deserialize)]
89pub struct BotCommandScopeAllChatAdministrators {
90    #[doc(hidden)]
91    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
92    extra: Option<String>,
93    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
94    client_id: Option<i32>,
95}
96
97impl RObject for BotCommandScopeAllChatAdministrators {
98    #[doc(hidden)]
99    fn extra(&self) -> Option<&str> {
100        self.extra.as_deref()
101    }
102    #[doc(hidden)]
103    fn client_id(&self) -> Option<i32> {
104        self.client_id
105    }
106}
107
108impl TDBotCommandScope for BotCommandScopeAllChatAdministrators {}
109
110impl BotCommandScopeAllChatAdministrators {
111    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
112        Ok(serde_json::from_str(json.as_ref())?)
113    }
114    pub fn builder() -> BotCommandScopeAllChatAdministratorsBuilder {
115        let mut inner = BotCommandScopeAllChatAdministrators::default();
116        inner.extra = Some(Uuid::new_v4().to_string());
117
118        BotCommandScopeAllChatAdministratorsBuilder { inner }
119    }
120}
121
122#[doc(hidden)]
123pub struct BotCommandScopeAllChatAdministratorsBuilder {
124    inner: BotCommandScopeAllChatAdministrators,
125}
126
127#[deprecated]
128pub type RTDBotCommandScopeAllChatAdministratorsBuilder =
129    BotCommandScopeAllChatAdministratorsBuilder;
130
131impl BotCommandScopeAllChatAdministratorsBuilder {
132    pub fn build(&self) -> BotCommandScopeAllChatAdministrators {
133        self.inner.clone()
134    }
135}
136
137impl AsRef<BotCommandScopeAllChatAdministrators> for BotCommandScopeAllChatAdministrators {
138    fn as_ref(&self) -> &BotCommandScopeAllChatAdministrators {
139        self
140    }
141}
142
143impl AsRef<BotCommandScopeAllChatAdministrators> for BotCommandScopeAllChatAdministratorsBuilder {
144    fn as_ref(&self) -> &BotCommandScopeAllChatAdministrators {
145        &self.inner
146    }
147}
148
149/// A scope covering all group and supergroup chats
150#[derive(Debug, Clone, Default, Serialize, Deserialize)]
151pub struct BotCommandScopeAllGroupChats {
152    #[doc(hidden)]
153    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
154    extra: Option<String>,
155    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
156    client_id: Option<i32>,
157}
158
159impl RObject for BotCommandScopeAllGroupChats {
160    #[doc(hidden)]
161    fn extra(&self) -> Option<&str> {
162        self.extra.as_deref()
163    }
164    #[doc(hidden)]
165    fn client_id(&self) -> Option<i32> {
166        self.client_id
167    }
168}
169
170impl TDBotCommandScope for BotCommandScopeAllGroupChats {}
171
172impl BotCommandScopeAllGroupChats {
173    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
174        Ok(serde_json::from_str(json.as_ref())?)
175    }
176    pub fn builder() -> BotCommandScopeAllGroupChatsBuilder {
177        let mut inner = BotCommandScopeAllGroupChats::default();
178        inner.extra = Some(Uuid::new_v4().to_string());
179
180        BotCommandScopeAllGroupChatsBuilder { inner }
181    }
182}
183
184#[doc(hidden)]
185pub struct BotCommandScopeAllGroupChatsBuilder {
186    inner: BotCommandScopeAllGroupChats,
187}
188
189#[deprecated]
190pub type RTDBotCommandScopeAllGroupChatsBuilder = BotCommandScopeAllGroupChatsBuilder;
191
192impl BotCommandScopeAllGroupChatsBuilder {
193    pub fn build(&self) -> BotCommandScopeAllGroupChats {
194        self.inner.clone()
195    }
196}
197
198impl AsRef<BotCommandScopeAllGroupChats> for BotCommandScopeAllGroupChats {
199    fn as_ref(&self) -> &BotCommandScopeAllGroupChats {
200        self
201    }
202}
203
204impl AsRef<BotCommandScopeAllGroupChats> for BotCommandScopeAllGroupChatsBuilder {
205    fn as_ref(&self) -> &BotCommandScopeAllGroupChats {
206        &self.inner
207    }
208}
209
210/// A scope covering all private chats
211#[derive(Debug, Clone, Default, Serialize, Deserialize)]
212pub struct BotCommandScopeAllPrivateChats {
213    #[doc(hidden)]
214    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
215    extra: Option<String>,
216    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
217    client_id: Option<i32>,
218}
219
220impl RObject for BotCommandScopeAllPrivateChats {
221    #[doc(hidden)]
222    fn extra(&self) -> Option<&str> {
223        self.extra.as_deref()
224    }
225    #[doc(hidden)]
226    fn client_id(&self) -> Option<i32> {
227        self.client_id
228    }
229}
230
231impl TDBotCommandScope for BotCommandScopeAllPrivateChats {}
232
233impl BotCommandScopeAllPrivateChats {
234    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
235        Ok(serde_json::from_str(json.as_ref())?)
236    }
237    pub fn builder() -> BotCommandScopeAllPrivateChatsBuilder {
238        let mut inner = BotCommandScopeAllPrivateChats::default();
239        inner.extra = Some(Uuid::new_v4().to_string());
240
241        BotCommandScopeAllPrivateChatsBuilder { inner }
242    }
243}
244
245#[doc(hidden)]
246pub struct BotCommandScopeAllPrivateChatsBuilder {
247    inner: BotCommandScopeAllPrivateChats,
248}
249
250#[deprecated]
251pub type RTDBotCommandScopeAllPrivateChatsBuilder = BotCommandScopeAllPrivateChatsBuilder;
252
253impl BotCommandScopeAllPrivateChatsBuilder {
254    pub fn build(&self) -> BotCommandScopeAllPrivateChats {
255        self.inner.clone()
256    }
257}
258
259impl AsRef<BotCommandScopeAllPrivateChats> for BotCommandScopeAllPrivateChats {
260    fn as_ref(&self) -> &BotCommandScopeAllPrivateChats {
261        self
262    }
263}
264
265impl AsRef<BotCommandScopeAllPrivateChats> for BotCommandScopeAllPrivateChatsBuilder {
266    fn as_ref(&self) -> &BotCommandScopeAllPrivateChats {
267        &self.inner
268    }
269}
270
271/// A scope covering all members of a chat
272#[derive(Debug, Clone, Default, Serialize, Deserialize)]
273pub struct BotCommandScopeChat {
274    #[doc(hidden)]
275    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
276    extra: Option<String>,
277    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
278    client_id: Option<i32>,
279    /// Chat identifier
280
281    #[serde(default)]
282    chat_id: i64,
283}
284
285impl RObject for BotCommandScopeChat {
286    #[doc(hidden)]
287    fn extra(&self) -> Option<&str> {
288        self.extra.as_deref()
289    }
290    #[doc(hidden)]
291    fn client_id(&self) -> Option<i32> {
292        self.client_id
293    }
294}
295
296impl TDBotCommandScope for BotCommandScopeChat {}
297
298impl BotCommandScopeChat {
299    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
300        Ok(serde_json::from_str(json.as_ref())?)
301    }
302    pub fn builder() -> BotCommandScopeChatBuilder {
303        let mut inner = BotCommandScopeChat::default();
304        inner.extra = Some(Uuid::new_v4().to_string());
305
306        BotCommandScopeChatBuilder { inner }
307    }
308
309    pub fn chat_id(&self) -> i64 {
310        self.chat_id
311    }
312}
313
314#[doc(hidden)]
315pub struct BotCommandScopeChatBuilder {
316    inner: BotCommandScopeChat,
317}
318
319#[deprecated]
320pub type RTDBotCommandScopeChatBuilder = BotCommandScopeChatBuilder;
321
322impl BotCommandScopeChatBuilder {
323    pub fn build(&self) -> BotCommandScopeChat {
324        self.inner.clone()
325    }
326
327    pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
328        self.inner.chat_id = chat_id;
329        self
330    }
331}
332
333impl AsRef<BotCommandScopeChat> for BotCommandScopeChat {
334    fn as_ref(&self) -> &BotCommandScopeChat {
335        self
336    }
337}
338
339impl AsRef<BotCommandScopeChat> for BotCommandScopeChatBuilder {
340    fn as_ref(&self) -> &BotCommandScopeChat {
341        &self.inner
342    }
343}
344
345/// A scope covering all administrators of a chat
346#[derive(Debug, Clone, Default, Serialize, Deserialize)]
347pub struct BotCommandScopeChatAdministrators {
348    #[doc(hidden)]
349    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
350    extra: Option<String>,
351    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
352    client_id: Option<i32>,
353    /// Chat identifier
354
355    #[serde(default)]
356    chat_id: i64,
357}
358
359impl RObject for BotCommandScopeChatAdministrators {
360    #[doc(hidden)]
361    fn extra(&self) -> Option<&str> {
362        self.extra.as_deref()
363    }
364    #[doc(hidden)]
365    fn client_id(&self) -> Option<i32> {
366        self.client_id
367    }
368}
369
370impl TDBotCommandScope for BotCommandScopeChatAdministrators {}
371
372impl BotCommandScopeChatAdministrators {
373    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
374        Ok(serde_json::from_str(json.as_ref())?)
375    }
376    pub fn builder() -> BotCommandScopeChatAdministratorsBuilder {
377        let mut inner = BotCommandScopeChatAdministrators::default();
378        inner.extra = Some(Uuid::new_v4().to_string());
379
380        BotCommandScopeChatAdministratorsBuilder { inner }
381    }
382
383    pub fn chat_id(&self) -> i64 {
384        self.chat_id
385    }
386}
387
388#[doc(hidden)]
389pub struct BotCommandScopeChatAdministratorsBuilder {
390    inner: BotCommandScopeChatAdministrators,
391}
392
393#[deprecated]
394pub type RTDBotCommandScopeChatAdministratorsBuilder = BotCommandScopeChatAdministratorsBuilder;
395
396impl BotCommandScopeChatAdministratorsBuilder {
397    pub fn build(&self) -> BotCommandScopeChatAdministrators {
398        self.inner.clone()
399    }
400
401    pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
402        self.inner.chat_id = chat_id;
403        self
404    }
405}
406
407impl AsRef<BotCommandScopeChatAdministrators> for BotCommandScopeChatAdministrators {
408    fn as_ref(&self) -> &BotCommandScopeChatAdministrators {
409        self
410    }
411}
412
413impl AsRef<BotCommandScopeChatAdministrators> for BotCommandScopeChatAdministratorsBuilder {
414    fn as_ref(&self) -> &BotCommandScopeChatAdministrators {
415        &self.inner
416    }
417}
418
419/// A scope covering a member of a chat
420#[derive(Debug, Clone, Default, Serialize, Deserialize)]
421pub struct BotCommandScopeChatMember {
422    #[doc(hidden)]
423    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
424    extra: Option<String>,
425    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
426    client_id: Option<i32>,
427    /// Chat identifier
428
429    #[serde(default)]
430    chat_id: i64,
431    /// User identifier
432
433    #[serde(default)]
434    user_id: i64,
435}
436
437impl RObject for BotCommandScopeChatMember {
438    #[doc(hidden)]
439    fn extra(&self) -> Option<&str> {
440        self.extra.as_deref()
441    }
442    #[doc(hidden)]
443    fn client_id(&self) -> Option<i32> {
444        self.client_id
445    }
446}
447
448impl TDBotCommandScope for BotCommandScopeChatMember {}
449
450impl BotCommandScopeChatMember {
451    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
452        Ok(serde_json::from_str(json.as_ref())?)
453    }
454    pub fn builder() -> BotCommandScopeChatMemberBuilder {
455        let mut inner = BotCommandScopeChatMember::default();
456        inner.extra = Some(Uuid::new_v4().to_string());
457
458        BotCommandScopeChatMemberBuilder { inner }
459    }
460
461    pub fn chat_id(&self) -> i64 {
462        self.chat_id
463    }
464
465    pub fn user_id(&self) -> i64 {
466        self.user_id
467    }
468}
469
470#[doc(hidden)]
471pub struct BotCommandScopeChatMemberBuilder {
472    inner: BotCommandScopeChatMember,
473}
474
475#[deprecated]
476pub type RTDBotCommandScopeChatMemberBuilder = BotCommandScopeChatMemberBuilder;
477
478impl BotCommandScopeChatMemberBuilder {
479    pub fn build(&self) -> BotCommandScopeChatMember {
480        self.inner.clone()
481    }
482
483    pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
484        self.inner.chat_id = chat_id;
485        self
486    }
487
488    pub fn user_id(&mut self, user_id: i64) -> &mut Self {
489        self.inner.user_id = user_id;
490        self
491    }
492}
493
494impl AsRef<BotCommandScopeChatMember> for BotCommandScopeChatMember {
495    fn as_ref(&self) -> &BotCommandScopeChatMember {
496        self
497    }
498}
499
500impl AsRef<BotCommandScopeChatMember> for BotCommandScopeChatMemberBuilder {
501    fn as_ref(&self) -> &BotCommandScopeChatMember {
502        &self.inner
503    }
504}
505
506/// A scope covering all users
507#[derive(Debug, Clone, Default, Serialize, Deserialize)]
508pub struct BotCommandScopeDefault {
509    #[doc(hidden)]
510    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
511    extra: Option<String>,
512    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
513    client_id: Option<i32>,
514}
515
516impl RObject for BotCommandScopeDefault {
517    #[doc(hidden)]
518    fn extra(&self) -> Option<&str> {
519        self.extra.as_deref()
520    }
521    #[doc(hidden)]
522    fn client_id(&self) -> Option<i32> {
523        self.client_id
524    }
525}
526
527impl TDBotCommandScope for BotCommandScopeDefault {}
528
529impl BotCommandScopeDefault {
530    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
531        Ok(serde_json::from_str(json.as_ref())?)
532    }
533    pub fn builder() -> BotCommandScopeDefaultBuilder {
534        let mut inner = BotCommandScopeDefault::default();
535        inner.extra = Some(Uuid::new_v4().to_string());
536
537        BotCommandScopeDefaultBuilder { inner }
538    }
539}
540
541#[doc(hidden)]
542pub struct BotCommandScopeDefaultBuilder {
543    inner: BotCommandScopeDefault,
544}
545
546#[deprecated]
547pub type RTDBotCommandScopeDefaultBuilder = BotCommandScopeDefaultBuilder;
548
549impl BotCommandScopeDefaultBuilder {
550    pub fn build(&self) -> BotCommandScopeDefault {
551        self.inner.clone()
552    }
553}
554
555impl AsRef<BotCommandScopeDefault> for BotCommandScopeDefault {
556    fn as_ref(&self) -> &BotCommandScopeDefault {
557        self
558    }
559}
560
561impl AsRef<BotCommandScopeDefault> for BotCommandScopeDefaultBuilder {
562    fn as_ref(&self) -> &BotCommandScopeDefault {
563        &self.inner
564    }
565}