From a777b3a8055385a67f28e5ce31c6ea46c2743b67 Mon Sep 17 00:00:00 2001 From: nextel Date: Sat, 21 Sep 2019 20:39:58 +0300 Subject: [PATCH] add action template --- src/requests/restrict_chat_member.rs | 87 +++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/src/requests/restrict_chat_member.rs b/src/requests/restrict_chat_member.rs index 781dead6..62bf8f29 100644 --- a/src/requests/restrict_chat_member.rs +++ b/src/requests/restrict_chat_member.rs @@ -1,8 +1,91 @@ -use crate::requests::RequestContext; -//TODO:: need implementation +use crate::network; +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)] pub struct RestrictChatMember<'a> { #[serde(skip_serializing)] 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 + pub until_date: Option, +} + +impl<'a> Request<'a> for RestrictChatMember<'a> { + type ReturnValue = bool; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + 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(mut self, chat_id: T) -> Self + where + T: Into, + { + self.chat_id = chat_id.into(); + self + } + + pub fn user_id(mut self, user_id: T) -> Self + where + T: Into, + { + self.user_id = user_id.into(); + self + } + + pub fn permissions(mut self, permissions: T) -> Self + where + T: Into, + { + self.permissions = permissions.into(); + self + } + + pub fn until_date(mut self, until_date: T) -> Self + where + T: Into, + { + self.until_date = Some(until_date.into()); + self + } }