1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct User {
6 pub id: i64,
8
9 pub is_bot: bool,
11
12 pub first_name: String,
14
15 #[serde(skip_serializing_if = "Option::is_none")]
17 pub last_name: Option<String>,
18
19 #[serde(skip_serializing_if = "Option::is_none")]
21 pub username: Option<String>,
22
23 #[serde(skip_serializing_if = "Option::is_none")]
25 pub language_code: Option<String>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub is_premium: Option<bool>,
30
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub added_to_attachment_menu: Option<bool>,
34
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub can_join_groups: Option<bool>,
38
39 #[serde(skip_serializing_if = "Option::is_none")]
41 pub can_read_all_group_messages: Option<bool>,
42
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub supports_inline_queries: Option<bool>,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub can_connect_to_business: Option<bool>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub has_main_web_app: Option<bool>,
54
55 #[serde(skip_serializing_if = "Option::is_none")]
57 pub can_manage_bots: Option<bool>,
58}
59
60impl User {
61 #[must_use]
64 pub fn full_name(&self) -> String {
65 match &self.last_name {
66 Some(last) => format!("{} {}", self.first_name, last),
67 None => self.first_name.clone(),
68 }
69 }
70
71 #[must_use]
73 pub fn mention(&self) -> Option<String> {
74 self.username.as_ref().map(|u| format!("@{u}"))
75 }
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct UserProfilePhotos {
81 pub total_count: u32,
83
84 pub photos: Vec<Vec<crate::file::PhotoSize>>,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct UserProfileAudios {
91 pub total_count: u32,
93
94 pub audios: Vec<crate::file::Audio>,
96}
97
98#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
100#[serde(tag = "type", rename_all = "snake_case")]
101pub enum BotCommandScope {
102 Default,
104 AllPrivateChats,
106 AllGroupChats,
108 AllChatAdministrators,
110 Chat {
112 chat_id: ChatId,
114 },
115 ChatAdministrators {
117 chat_id: ChatId,
119 },
120 ChatMember {
122 chat_id: ChatId,
124 user_id: i64,
126 },
127}
128
129#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
131pub struct BotCommand {
132 pub command: String,
134 pub description: String,
136}
137
138#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum ChatId {
142 Id(i64),
144 Username(String),
146}
147
148impl From<i64> for ChatId {
149 fn from(id: i64) -> Self {
150 Self::Id(id)
151 }
152}
153
154impl From<&str> for ChatId {
155 fn from(username: &str) -> Self {
156 Self::Username(username.to_owned())
157 }
158}
159
160impl From<String> for ChatId {
161 fn from(username: String) -> Self {
162 Self::Username(username)
163 }
164}
165
166impl std::fmt::Display for ChatId {
167 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168 match self {
169 Self::Id(id) => write!(f, "{id}"),
170 Self::Username(u) => write!(f, "{u}"),
171 }
172 }
173}