telegram_bot_async_raw/requests/
restrict_chat_member.rs1use crate::{requests::*, types::*};
2
3#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
8#[must_use = "requests do nothing unless sent"]
9pub struct RestrictChatMember {
10 chat_id: ChatRef,
11 user_id: UserId,
12 until_date: Option<i32>,
13 can_send_messages: Option<bool>,
14 can_send_media_messages: Option<bool>,
15 can_send_other_messages: Option<bool>,
16 can_add_web_page_previews: Option<bool>,
17}
18
19impl Request for RestrictChatMember {
20 type Type = JsonRequestType<Self>;
21 type Response = JsonTrueToUnitResponse;
22
23 fn serialize(&self) -> Result<HttpRequest, Error> {
24 Self::Type::serialize(RequestUrl::method("restrictChatMember"), self)
25 }
26}
27
28impl RestrictChatMember {
29 pub fn new<C, U>(chat: C, user: U) -> Self
30 where
31 C: ToChatRef,
32 U: ToUserId,
33 {
34 RestrictChatMember {
35 chat_id: chat.to_chat_ref(),
36 user_id: user.to_user_id(),
37 until_date: None,
38 can_send_messages: None,
39 can_send_media_messages: None,
40 can_send_other_messages: None,
41 can_add_web_page_previews: None,
42 }
43 }
44
45 pub fn until_date(mut self, value: i32) -> Self {
46 self.until_date = Some(value);
47 self
48 }
49
50 pub fn can_send_messages(mut self, value: bool) -> Self {
51 self.can_send_messages = Some(value);
52 self
53 }
54
55 pub fn can_send_media_messages(mut self, value: bool) -> Self {
56 self.can_send_media_messages = Some(value);
57 self
58 }
59
60 pub fn can_send_other_messages(mut self, value: bool) -> Self {
61 self.can_send_other_messages = Some(value);
62 self
63 }
64
65 pub fn can_add_web_page_previews(mut self, value: bool) -> Self {
66 self.can_add_web_page_previews = Some(value);
67 self
68 }
69}
70
71pub trait CanRestrictChatMemberForChat {
73 fn restrict<O>(&self, other: O) -> RestrictChatMember
74 where
75 O: ToUserId;
76}
77
78impl<C> CanRestrictChatMemberForChat for C
79where
80 C: ToChatRef,
81{
82 fn restrict<O>(&self, other: O) -> RestrictChatMember
83 where
84 O: ToUserId,
85 {
86 RestrictChatMember::new(self, other)
87 }
88}
89
90pub trait CanRestrictChatMemberForUser {
92 fn restrict_from<O>(&self, other: O) -> RestrictChatMember
93 where
94 O: ToChatRef;
95}
96
97impl<U> CanRestrictChatMemberForUser for U
98where
99 U: ToUserId,
100{
101 fn restrict_from<O>(&self, other: O) -> RestrictChatMember
102 where
103 O: ToChatRef,
104 {
105 RestrictChatMember::new(other, self)
106 }
107}