diff --git a/src/requests/get_user_profile_photos.rs b/src/requests/get_user_profile_photos.rs index 5feca84e..722b919a 100644 --- a/src/requests/get_user_profile_photos.rs +++ b/src/requests/get_user_profile_photos.rs @@ -1,7 +1,7 @@ -use crate::requests::RequestContext; +use crate::network; +use crate::requests::{Request, RequestContext, RequestFuture, ResponseResult}; +use crate::types::UserProfilePhotos; -//TODO: complete implementation after user_profile_fotos will be added to -// types/mod.rs ///Use this method to get a list of profile pictures for a user. Returns a /// UserProfilePhotos object. #[derive(Debug, Clone, Serialize)] @@ -9,11 +9,65 @@ pub struct GetUserProfilePhotos<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// Unique identifier of the target user - user_id: i32, + pub user_id: i32, /// Sequential number of the first photo to be returned. By default, all /// photos are returned. - offset: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub offset: Option, ///Limits the number of photos to be retrieved. Values between 1—100 are /// accepted. Defaults to 100. - limit: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, +} + +impl<'a> Request<'a> for GetUserProfilePhotos<'a> { + type ReturnValue = UserProfilePhotos; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "getUserProfilePhotos", + &self, + ) + .await + }) + } +} + +impl<'a> GetUserProfilePhotos<'a> { + pub fn new(ctx: RequestContext<'a>, user_id: i32) -> Self { + Self { + ctx, + user_id, + offset: None, + limit: None, + } + } + + pub fn user_id(mut self, user_id: T) -> Self + where + T: Into, + { + self.user_id = user_id.into(); + self + } + + pub fn offset(mut self, offset: T) -> Self + where + T: Into, + { + self.offset = Some(offset.into()); + self + } + + pub fn limit(mut self, limit: T) -> Self + where + T: Into, + { + self.limit = Some(limit.into()); + self + } + } diff --git a/src/requests/kick_chat_member.rs b/src/requests/kick_chat_member.rs index baabe494..2ed54f0a 100644 --- a/src/requests/kick_chat_member.rs +++ b/src/requests/kick_chat_member.rs @@ -1,5 +1,8 @@ -use crate::requests::RequestContext; -//TODO:: need implementation +use crate::network; +use crate::requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, +}; + /// Use this method to kick a user from a group, a supergroup or a channel. In /// the case of supergroups and channels, the user will not be able to return to /// the group on their own using invite links, etc., unless unbanned first. The @@ -9,4 +12,60 @@ use crate::requests::RequestContext; pub struct KickChatMember<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, + ///Unique identifier for the target group or username of the target + /// supergroup or channel (in the format @channelusername) + pub chat_id: ChatId, + /// Unique identifier of the target user + pub user_id: i32, + ///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 + #[serde(skip_serializing_if = "Option::is_none")] + pub until_date: Option, +} + +impl<'a> Request<'a> for KickChatMember<'a> { + type ReturnValue = bool; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + self.ctx.client, + self.ctx.token, + "kickChatMember", + &self, + ) + .await + }) + } +} + +impl<'a> KickChatMember<'a> { + pub(crate) fn new( + ctx: RequestContext<'a>, + chat_id: ChatId, + user_id: i32, + ) -> Self { + Self { + ctx, + chat_id, + user_id, + until_date: None, + } + } + + pub fn chat_id>(mut self, chat_id: T) -> Self { + self.chat_id = chat_id.into(); + self + } + + pub fn user_id>(mut self, user_id: T) -> Self { + self.user_id = user_id.into(); + self + } + + pub fn until_date>(mut self, until_date: T) -> Self { + self.until_date = Some(until_date.into()); + self + } } diff --git a/src/requests/restrict_chat_member.rs b/src/requests/restrict_chat_member.rs index 781dead6..dabfb9c1 100644 --- a/src/requests/restrict_chat_member.rs +++ b/src/requests/restrict_chat_member.rs @@ -1,8 +1,92 @@ -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 + #[serde(skip_serializing_if = "Option::is_none")] + 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 + } }