Add GetChatMember

This commit is contained in:
Temirkhan Myrzamadi 2019-10-17 21:09:46 +06:00
parent 82db9b18b2
commit b3572072ad
3 changed files with 82 additions and 1 deletions

View file

@ -1,6 +1,6 @@
use crate::bot::Bot;
use crate::requests::{
AnswerCallbackQuery, DeleteChatStickerSet, SetChatStickerSet,
AnswerCallbackQuery, DeleteChatStickerSet, GetChatMember, SetChatStickerSet,
};
use crate::{
requests::{
@ -306,4 +306,12 @@ impl Bot {
{
SetChatStickerSet::new(self, chat_id, sticker_set_name)
}
pub fn get_chat_member<C, I>(&self, chat_id: C, user_id: I) -> GetChatMember
where
C: Into<ChatId>,
I: Into<i32>,
{
GetChatMember::new(self, chat_id, user_id)
}
}

View file

@ -0,0 +1,71 @@
use crate::bot::Bot;
use crate::network;
use crate::requests::{Request, ResponseResult};
use crate::types::{ChatId, ChatMember};
use async_trait::async_trait;
/// Use this method to get information about a member of a chat. Returns a
/// ChatMember object on success.
#[derive(Debug, Clone, Serialize)]
pub struct GetChatMember<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target
/// supergroup or channel (in the format @channelusername)
chat_id: ChatId,
/// Unique identifier of the target user
user_id: i32,
}
#[async_trait]
impl Request for GetChatMember<'_> {
type Output = ChatMember;
async fn send_boxed(self) -> ResponseResult<Self::Output> {
self.send().await
}
}
impl GetChatMember<'_> {
async fn send(&self) -> ResponseResult<ChatMember> {
network::request_json(
self.bot.client(),
self.bot.token(),
"getChatMember",
&self,
)
.await
}
}
impl<'a> GetChatMember<'a> {
pub(crate) fn new<C, I>(bot: &'a Bot, chat_id: C, user_id: I) -> Self
where
C: Into<ChatId>,
I: Into<i32>,
{
Self {
bot,
chat_id: chat_id.into(),
user_id: user_id.into(),
}
}
pub fn chat_id<C>(mut self, value: C) -> Self
where
C: Into<ChatId>,
{
self.chat_id = value.into();
self
}
pub fn user_id<I>(mut self, value: I) -> Self
where
I: Into<i32>,
{
self.user_id = value.into();
self
}
}

View file

@ -10,6 +10,7 @@ pub use delete_chat_sticker_set::*;
pub use edit_message_live_location::*;
pub use forward_message::*;
pub use get_chat::*;
pub use get_chat_member::*;
pub use get_file::*;
pub use get_me::*;
pub use get_updates::*;
@ -47,6 +48,7 @@ mod delete_chat_sticker_set;
mod edit_message_live_location;
mod forward_message;
mod get_chat;
mod get_chat_member;
mod get_file;
mod get_me;
mod get_updates;