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