mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 06:51:01 +01:00
Merge pull request #34 from async-telegram-bot/feature/RestrictChatMember
add action RestrictChatMember
This commit is contained in:
commit
f8754cfc9d
1 changed files with 86 additions and 2 deletions
|
@ -1,8 +1,92 @@
|
||||||
use crate::requests::RequestContext;
|
use crate::network;
|
||||||
//TODO:: need implementation
|
use crate::requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
};
|
||||||
|
use crate::types::ChatPermissions;
|
||||||
|
|
||||||
|
/// Use this method to restrict a user in a supergroup. The bot must be an
|
||||||
|
/// administrator in the supergroup for this to work and must have the
|
||||||
|
/// appropriate admin rights. Pass True for all permissions to lift restrictions
|
||||||
|
/// from a user. Returns True on success.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct RestrictChatMember<'a> {
|
pub struct RestrictChatMember<'a> {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
ctx: RequestContext<'a>,
|
ctx: RequestContext<'a>,
|
||||||
|
///Unique identifier for the target chat or username of the target
|
||||||
|
/// supergroup (in the format @supergroupusername)
|
||||||
|
pub chat_id: ChatId,
|
||||||
|
///Unique identifier of the target user
|
||||||
|
pub user_id: i32,
|
||||||
|
///New user permissions
|
||||||
|
pub permissions: ChatPermissions,
|
||||||
|
///Date when restrictions will be lifted for the user, unix time. If user
|
||||||
|
/// is restricted for more than 366 days or less than 30 seconds from the
|
||||||
|
/// current time, they are considered to be restricted forever
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub until_date: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Request<'a> for RestrictChatMember<'a> {
|
||||||
|
type ReturnValue = bool;
|
||||||
|
|
||||||
|
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
network::request_json(
|
||||||
|
&self.ctx.client,
|
||||||
|
&self.ctx.token,
|
||||||
|
"restrictChatMember",
|
||||||
|
&self,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> RestrictChatMember<'a> {
|
||||||
|
pub(crate) fn new(
|
||||||
|
ctx: RequestContext<'a>,
|
||||||
|
chat_id: ChatId,
|
||||||
|
user_id: i32,
|
||||||
|
permissions: ChatPermissions,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
ctx,
|
||||||
|
chat_id,
|
||||||
|
user_id,
|
||||||
|
permissions,
|
||||||
|
until_date: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ChatId>,
|
||||||
|
{
|
||||||
|
self.chat_id = chat_id.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn user_id<T>(mut self, user_id: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<i32>,
|
||||||
|
{
|
||||||
|
self.user_id = user_id.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn permissions<T>(mut self, permissions: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<ChatPermissions>,
|
||||||
|
{
|
||||||
|
self.permissions = permissions.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn until_date<T>(mut self, until_date: T) -> Self
|
||||||
|
where
|
||||||
|
T: Into<u64>,
|
||||||
|
{
|
||||||
|
self.until_date = Some(until_date.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue