telegram_bot_async_raw/requests/
kick_chat_member.rs

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