+getChatAdministrators

This commit is contained in:
RustemB 2019-10-20 15:40:28 +05:00
parent 66147232e6
commit 5916460ca1
2 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,60 @@
use crate::{
bot::Bot,
network,
requests::{Request, ResponseResult},
types::{ChatId, ChatMember},
};
use async_trait::async_trait;
/// Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned
#[derive(Debug, Clone, Serialize)]
pub struct GetChatAdministrators<'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,
}
#[async_trait]
impl Request for GetChatAdministrators<'_> {
type Output = Vec<ChatMember>;
async fn send_boxed(self) -> ResponseResult<Self::Output> {
self.send().await
}
}
impl GetChatAdministrators<'_> {
async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
network::request_json(
self.bot.client(),
self.bot.token(),
"getChatAdministrators",
&self,
)
.await
}
}
impl<'a> GetChatAdministrators<'a> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C) -> Self
where
C: Into<ChatId>,
{
Self {
bot,
chat_id: chat_id.into(),
}
}
pub fn chat_id<C>(mut self, value: C) -> Self
where
C: Into<ChatId>,
{
self.chat_id = value.into();
self
}
}

View file

@ -12,6 +12,7 @@ pub use edit_message_live_location::*;
pub use export_chat_invite_link::*;
pub use forward_message::*;
pub use get_chat::*;
pub use get_chat_administrators::*;
pub use get_chat_member::*;
pub use get_chat_members_count::*;
pub use get_file::*;
@ -58,6 +59,7 @@ mod edit_message_live_location;
mod export_chat_invite_link;
mod forward_message;
mod get_chat;
mod get_chat_administrators;
mod get_chat_member;
mod get_chat_members_count;
mod get_file;