telegram_bot_async_raw/requests/
get_chat_member.rs

1use crate::{requests::*, types::*};
2
3/// Use this method to get information about a member of a chat.
4#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
5#[must_use = "requests do nothing unless sent"]
6pub struct GetChatMember {
7    chat_id: ChatRef,
8    user_id: UserId,
9}
10
11impl Request for GetChatMember {
12    type Type = JsonRequestType<Self>;
13    type Response = JsonIdResponse<ChatMember>;
14
15    fn serialize(&self) -> Result<HttpRequest, Error> {
16        Self::Type::serialize(RequestUrl::method("getChatMember"), self)
17    }
18}
19
20impl GetChatMember {
21    pub fn new<C, U>(chat: C, user: U) -> Self
22    where
23        C: ToChatRef,
24        U: ToUserId,
25    {
26        GetChatMember {
27            chat_id: chat.to_chat_ref(),
28            user_id: user.to_user_id(),
29        }
30    }
31}
32
33/// Get information about a member of a chat.
34pub trait CanGetChatMemberForChat {
35    fn get_member<O>(&self, other: O) -> GetChatMember
36    where
37        O: ToUserId;
38}
39
40impl<C> CanGetChatMemberForChat for C
41where
42    C: ToChatRef,
43{
44    fn get_member<O>(&self, other: O) -> GetChatMember
45    where
46        O: ToUserId,
47    {
48        GetChatMember::new(self, other)
49    }
50}
51
52/// Get information about a member of a chat.
53pub trait CanGetChatMemberForUser {
54    fn get_member_from<O>(&self, other: O) -> GetChatMember
55    where
56        O: ToChatRef;
57}
58
59impl<U> CanGetChatMemberForUser for U
60where
61    U: ToUserId,
62{
63    fn get_member_from<O>(&self, other: O) -> GetChatMember
64    where
65        O: ToChatRef,
66    {
67        GetChatMember::new(other, self)
68    }
69}