1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API, entities::misc::chat_id::ChatId, errors::ConogramError, impl_into_future,
request::RequestT, utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct BanChatMemberParams {
pub chat_id: ChatId,
pub user_id: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub until_date: Option<i64>,
#[serde(default, skip_serializing_if = "is_false")]
pub revoke_messages: bool,
}
impl_into_future!(BanChatMemberRequest<'a>);
///Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless [unbanned](https://core.telegram.org/bots/api/#unbanchatmember) first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns *True* on success.
#[derive(Clone)]
pub struct BanChatMemberRequest<'a> {
api: &'a API,
params: BanChatMemberParams,
}
impl<'a> RequestT for BanChatMemberRequest<'a> {
type ParamsType = BanChatMemberParams;
type ReturnType = bool;
fn get_name() -> &'static str {
"banChatMember"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
false
}
}
impl<'a> BanChatMemberRequest<'a> {
pub fn new(api: &'a API, chat_id: impl Into<ChatId>, user_id: impl Into<i64>) -> Self {
Self {
api,
params: BanChatMemberParams {
chat_id: chat_id.into(),
user_id: user_id.into(),
until_date: Option::default(),
revoke_messages: bool::default(),
},
}
}
///Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
#[must_use]
pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
self.params.chat_id = chat_id.into();
self
}
///Unique identifier of the target user
#[must_use]
pub fn user_id(mut self, user_id: impl Into<i64>) -> Self {
self.params.user_id = user_id.into();
self
}
///Date when the user will be unbanned; Unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.
#[must_use]
pub fn until_date(mut self, until_date: impl Into<i64>) -> Self {
self.params.until_date = Some(until_date.into());
self
}
///Pass *True* to delete all messages from the chat for the user that is being removed. If *False*, the user will be able to see messages in the group that were sent before the user was removed. Always *True* for supergroups and channels.
#[must_use]
pub fn revoke_messages(mut self, revoke_messages: impl Into<bool>) -> Self {
self.params.revoke_messages = revoke_messages.into();
self
}
}
impl API {
///Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless [unbanned](https://core.telegram.org/bots/api/#unbanchatmember) first. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns *True* on success.
pub fn ban_chat_member(
&self,
chat_id: impl Into<ChatId>,
user_id: impl Into<i64>,
) -> BanChatMemberRequest {
BanChatMemberRequest::new(self, chat_id, user_id)
}
}
// Divider: all content below this line will be preserved after code regen