1use crate::client::BotClient;
2use crate::error::Result;
3use rustigram_types::chat::{ChatInviteLink, ChatPermissions};
4use rustigram_types::user::ChatId;
5use serde::Serialize;
6use std::future::{Future, IntoFuture};
7use std::pin::Pin;
8
9#[derive(Serialize)]
12struct BanChatMemberParams {
13 chat_id: ChatId,
14 user_id: i64,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 until_date: Option<i64>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 revoke_messages: Option<bool>,
19}
20
21pub struct BanChatMember {
23 client: BotClient,
24 params: BanChatMemberParams,
25}
26
27impl BanChatMember {
28 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
29 Self {
30 client,
31 params: BanChatMemberParams {
32 chat_id: chat_id.into(),
33 user_id,
34 until_date: None,
35 revoke_messages: None,
36 },
37 }
38 }
39 pub fn until_date(mut self, ts: i64) -> Self {
41 self.params.until_date = Some(ts);
42 self
43 }
44 pub fn revoke_messages(mut self, v: bool) -> Self {
46 self.params.revoke_messages = Some(v);
47 self
48 }
49}
50
51impl IntoFuture for BanChatMember {
52 type Output = Result<bool>;
53 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
54 fn into_future(self) -> Self::IntoFuture {
55 Box::pin(async move { self.client.post_json("banChatMember", &self.params).await })
56 }
57}
58
59#[derive(Serialize)]
62struct UnbanChatMemberParams {
63 chat_id: ChatId,
64 user_id: i64,
65 #[serde(skip_serializing_if = "Option::is_none")]
66 only_if_banned: Option<bool>,
67}
68
69pub struct UnbanChatMember {
71 client: BotClient,
72 params: UnbanChatMemberParams,
73}
74
75impl UnbanChatMember {
76 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
77 Self {
78 client,
79 params: UnbanChatMemberParams {
80 chat_id: chat_id.into(),
81 user_id,
82 only_if_banned: None,
83 },
84 }
85 }
86 pub fn only_if_banned(mut self, v: bool) -> Self {
88 self.params.only_if_banned = Some(v);
89 self
90 }
91}
92
93impl IntoFuture for UnbanChatMember {
94 type Output = Result<bool>;
95 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
96 fn into_future(self) -> Self::IntoFuture {
97 Box::pin(async move { self.client.post_json("unbanChatMember", &self.params).await })
98 }
99}
100
101#[derive(Serialize)]
104struct RestrictChatMemberParams {
105 chat_id: ChatId,
106 user_id: i64,
107 permissions: ChatPermissions,
108 #[serde(skip_serializing_if = "Option::is_none")]
109 use_independent_chat_permissions: Option<bool>,
110 #[serde(skip_serializing_if = "Option::is_none")]
111 until_date: Option<i64>,
112}
113
114pub struct RestrictChatMember {
116 client: BotClient,
117 params: RestrictChatMemberParams,
118}
119
120impl RestrictChatMember {
121 pub(crate) fn new(
122 client: BotClient,
123 chat_id: impl Into<ChatId>,
124 user_id: i64,
125 permissions: ChatPermissions,
126 ) -> Self {
127 Self {
128 client,
129 params: RestrictChatMemberParams {
130 chat_id: chat_id.into(),
131 user_id,
132 permissions,
133 use_independent_chat_permissions: None,
134 until_date: None,
135 },
136 }
137 }
138 pub fn until_date(mut self, ts: i64) -> Self {
140 self.params.until_date = Some(ts);
141 self
142 }
143 pub fn use_independent_chat_permissions(mut self, v: bool) -> Self {
145 self.params.use_independent_chat_permissions = Some(v);
146 self
147 }
148}
149
150impl IntoFuture for RestrictChatMember {
151 type Output = Result<bool>;
152 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
153 fn into_future(self) -> Self::IntoFuture {
154 Box::pin(async move {
155 self.client
156 .post_json("restrictChatMember", &self.params)
157 .await
158 })
159 }
160}
161
162#[derive(Serialize)]
165pub struct PromoteChatMemberParams {
167 chat_id: ChatId,
168 user_id: i64,
169 #[serde(skip_serializing_if = "Option::is_none")]
171 pub is_anonymous: Option<bool>,
172 #[serde(skip_serializing_if = "Option::is_none")]
174 pub can_manage_chat: Option<bool>,
175 #[serde(skip_serializing_if = "Option::is_none")]
177 pub can_delete_messages: Option<bool>,
178 #[serde(skip_serializing_if = "Option::is_none")]
180 pub can_manage_video_chats: Option<bool>,
181 #[serde(skip_serializing_if = "Option::is_none")]
183 pub can_restrict_members: Option<bool>,
184 #[serde(skip_serializing_if = "Option::is_none")]
186 pub can_promote_members: Option<bool>,
187 #[serde(skip_serializing_if = "Option::is_none")]
189 pub can_change_info: Option<bool>,
190 #[serde(skip_serializing_if = "Option::is_none")]
192 pub can_invite_users: Option<bool>,
193 #[serde(skip_serializing_if = "Option::is_none")]
195 pub can_post_messages: Option<bool>,
196 #[serde(skip_serializing_if = "Option::is_none")]
198 pub can_edit_messages: Option<bool>,
199 #[serde(skip_serializing_if = "Option::is_none")]
201 pub can_pin_messages: Option<bool>,
202 #[serde(skip_serializing_if = "Option::is_none")]
204 pub can_manage_topics: Option<bool>,
205 #[serde(skip_serializing_if = "Option::is_none")]
207 pub can_post_stories: Option<bool>,
208 #[serde(skip_serializing_if = "Option::is_none")]
210 pub can_edit_stories: Option<bool>,
211 #[serde(skip_serializing_if = "Option::is_none")]
213 pub can_delete_stories: Option<bool>,
214 #[serde(skip_serializing_if = "Option::is_none")]
216 pub can_manage_direct_messages: Option<bool>,
217 #[serde(skip_serializing_if = "Option::is_none")]
219 pub can_manage_tags: Option<bool>,
220}
221
222pub struct PromoteChatMember {
224 client: BotClient,
225 params: PromoteChatMemberParams,
226}
227
228impl PromoteChatMember {
229 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
230 Self {
231 client,
232 params: PromoteChatMemberParams {
233 chat_id: chat_id.into(),
234 user_id,
235 is_anonymous: None,
236 can_manage_chat: None,
237 can_delete_messages: None,
238 can_manage_video_chats: None,
239 can_restrict_members: None,
240 can_promote_members: None,
241 can_change_info: None,
242 can_invite_users: None,
243 can_post_messages: None,
244 can_edit_messages: None,
245 can_pin_messages: None,
246 can_manage_topics: None,
247 can_post_stories: None,
248 can_edit_stories: None,
249 can_delete_stories: None,
250 can_manage_direct_messages: None,
251 can_manage_tags: None,
252 },
253 }
254 }
255 pub fn can_manage_chat(mut self, v: bool) -> Self {
257 self.params.can_manage_chat = Some(v);
258 self
259 }
260 pub fn can_delete_messages(mut self, v: bool) -> Self {
262 self.params.can_delete_messages = Some(v);
263 self
264 }
265 pub fn can_manage_video_chats(mut self, v: bool) -> Self {
267 self.params.can_manage_video_chats = Some(v);
268 self
269 }
270 pub fn can_restrict_members(mut self, v: bool) -> Self {
272 self.params.can_restrict_members = Some(v);
273 self
274 }
275 pub fn can_promote_members(mut self, v: bool) -> Self {
277 self.params.can_promote_members = Some(v);
278 self
279 }
280 pub fn can_change_info(mut self, v: bool) -> Self {
282 self.params.can_change_info = Some(v);
283 self
284 }
285 pub fn can_invite_users(mut self, v: bool) -> Self {
287 self.params.can_invite_users = Some(v);
288 self
289 }
290 pub fn can_pin_messages(mut self, v: bool) -> Self {
292 self.params.can_pin_messages = Some(v);
293 self
294 }
295 pub fn can_manage_topics(mut self, v: bool) -> Self {
297 self.params.can_manage_topics = Some(v);
298 self
299 }
300 pub fn can_post_stories(mut self, v: bool) -> Self {
302 self.params.can_post_stories = Some(v);
303 self
304 }
305 pub fn can_manage_direct_messages(mut self, v: bool) -> Self {
307 self.params.can_manage_direct_messages = Some(v);
308 self
309 }
310 pub fn can_manage_tags(mut self, v: bool) -> Self {
312 self.params.can_manage_tags = Some(v);
313 self
314 }
315}
316
317impl IntoFuture for PromoteChatMember {
318 type Output = Result<bool>;
319 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
320 fn into_future(self) -> Self::IntoFuture {
321 Box::pin(async move {
322 self.client
323 .post_json("promoteChatMember", &self.params)
324 .await
325 })
326 }
327}
328
329#[derive(Serialize)]
332struct CreateChatInviteLinkParams {
333 chat_id: ChatId,
334 #[serde(skip_serializing_if = "Option::is_none")]
335 name: Option<String>,
336 #[serde(skip_serializing_if = "Option::is_none")]
337 expire_date: Option<i64>,
338 #[serde(skip_serializing_if = "Option::is_none")]
339 member_limit: Option<u32>,
340 #[serde(skip_serializing_if = "Option::is_none")]
341 creates_join_request: Option<bool>,
342}
343
344pub struct CreateChatInviteLink {
346 client: BotClient,
347 params: CreateChatInviteLinkParams,
348}
349
350impl CreateChatInviteLink {
351 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
352 Self {
353 client,
354 params: CreateChatInviteLinkParams {
355 chat_id: chat_id.into(),
356 name: None,
357 expire_date: None,
358 member_limit: None,
359 creates_join_request: None,
360 },
361 }
362 }
363 pub fn name(mut self, n: impl Into<String>) -> Self {
365 self.params.name = Some(n.into());
366 self
367 }
368 pub fn expire_date(mut self, ts: i64) -> Self {
370 self.params.expire_date = Some(ts);
371 self
372 }
373 pub fn member_limit(mut self, n: u32) -> Self {
375 self.params.member_limit = Some(n);
376 self
377 }
378 pub fn creates_join_request(mut self, v: bool) -> Self {
380 self.params.creates_join_request = Some(v);
381 self
382 }
383}
384
385impl IntoFuture for CreateChatInviteLink {
386 type Output = Result<ChatInviteLink>;
387 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
388 fn into_future(self) -> Self::IntoFuture {
389 Box::pin(async move {
390 self.client
391 .post_json("createChatInviteLink", &self.params)
392 .await
393 })
394 }
395}
396
397#[derive(Serialize)]
400struct PinChatMessageParams {
401 chat_id: ChatId,
402 message_id: i64,
403 #[serde(skip_serializing_if = "Option::is_none")]
404 disable_notification: Option<bool>,
405}
406
407pub struct PinChatMessage {
409 client: BotClient,
410 params: PinChatMessageParams,
411}
412
413impl PinChatMessage {
414 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, message_id: i64) -> Self {
415 Self {
416 client,
417 params: PinChatMessageParams {
418 chat_id: chat_id.into(),
419 message_id,
420 disable_notification: None,
421 },
422 }
423 }
424 pub fn disable_notification(mut self, v: bool) -> Self {
426 self.params.disable_notification = Some(v);
427 self
428 }
429}
430
431impl IntoFuture for PinChatMessage {
432 type Output = Result<bool>;
433 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
434 fn into_future(self) -> Self::IntoFuture {
435 Box::pin(async move { self.client.post_json("pinChatMessage", &self.params).await })
436 }
437}
438
439#[derive(Serialize)]
442struct UnpinChatMessageParams {
443 chat_id: ChatId,
444 #[serde(skip_serializing_if = "Option::is_none")]
445 message_id: Option<i64>,
446}
447
448pub struct UnpinChatMessage {
450 client: BotClient,
451 params: UnpinChatMessageParams,
452}
453
454impl UnpinChatMessage {
455 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
456 Self {
457 client,
458 params: UnpinChatMessageParams {
459 chat_id: chat_id.into(),
460 message_id: None,
461 },
462 }
463 }
464 pub fn message_id(mut self, id: i64) -> Self {
466 self.params.message_id = Some(id);
467 self
468 }
469}
470
471impl IntoFuture for UnpinChatMessage {
472 type Output = Result<bool>;
473 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
474 fn into_future(self) -> Self::IntoFuture {
475 Box::pin(async move {
476 self.client
477 .post_json("unpinChatMessage", &self.params)
478 .await
479 })
480 }
481}