Merge branch 'dev' of github.com:async-telegram-bot/async-telegram-bot into dev

This commit is contained in:
Mr-Andersen 2019-09-25 17:51:51 +03:00
commit fea357e6f0
3 changed files with 207 additions and 10 deletions

View file

@ -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<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub offset: Option<i64>,
///Limits the number of photos to be retrieved. Values between 1—100 are
/// accepted. Defaults to 100.
limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
}
impl<'a> Request<'a> for GetUserProfilePhotos<'a> {
type ReturnValue = UserProfilePhotos;
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
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<T>(mut self, user_id: T) -> Self
where
T: Into<i32>,
{
self.user_id = user_id.into();
self
}
pub fn offset<T>(mut self, offset: T) -> Self
where
T: Into<i64>,
{
self.offset = Some(offset.into());
self
}
pub fn limit<T>(mut self, limit: T) -> Self
where
T: Into<i64>,
{
self.limit = Some(limit.into());
self
}
}

View file

@ -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<u64>,
}
impl<'a> Request<'a> for KickChatMember<'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,
"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<T: Into<ChatId>>(mut self, chat_id: T) -> Self {
self.chat_id = chat_id.into();
self
}
pub fn user_id<T: Into<i32>>(mut self, user_id: T) -> Self {
self.user_id = user_id.into();
self
}
pub fn until_date<T: Into<u64>>(mut self, until_date: T) -> Self {
self.until_date = Some(until_date.into());
self
}
}

View file

@ -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<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
}
}