telegram_bot_fork_raw/requests/
kick_chat_member.rs

1use requests::*;
2use types::*;
3
4/// Use this method to kick a user from a group or a supergroup.
5/// In the case of supergroups, the user will not be able to return to the group on
6/// their own using invite links, etc., unless unbanned first.
7/// The bot must be an administrator in the group for this to work.
8#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
9#[must_use = "requests do nothing unless sent"]
10pub struct KickChatMember {
11    chat_id: ChatRef,
12    user_id: UserId,
13}
14
15impl Request for KickChatMember {
16    type Type = JsonRequestType<Self>;
17    type Response = JsonTrueToUnitResponse;
18
19    fn serialize(&self) -> Result<HttpRequest, Error> {
20        Self::Type::serialize(RequestUrl::method("kickChatMember"), self)
21    }
22}
23
24impl KickChatMember {
25    pub fn new<C, U>(chat: C, user: U) -> Self
26    where
27        C: ToChatRef,
28        U: ToUserId,
29    {
30        KickChatMember {
31            chat_id: chat.to_chat_ref(),
32            user_id: user.to_user_id(),
33        }
34    }
35}
36
37/// Kick a user from a group or a supergroup.
38pub trait CanKickChatMemberForChat {
39    fn kick<O>(&self, other: O) -> KickChatMember
40    where
41        O: ToUserId;
42}
43
44impl<C> CanKickChatMemberForChat for C
45where
46    C: ToChatRef,
47{
48    fn kick<O>(&self, other: O) -> KickChatMember
49    where
50        O: ToUserId,
51    {
52        KickChatMember::new(self, other)
53    }
54}
55
56/// Kick a user from a group or a supergroup.
57pub trait CanKickChatMemberForUser {
58    fn kick_from<O>(&self, other: O) -> KickChatMember
59    where
60        O: ToChatRef;
61}
62
63impl<U> CanKickChatMemberForUser for U
64where
65    U: ToUserId,
66{
67    fn kick_from<O>(&self, other: O) -> KickChatMember
68    where
69        O: ToChatRef,
70    {
71        KickChatMember::new(other, self)
72    }
73}