diff --git a/src/requests/get_chat_administrators.rs b/src/requests/get_chat_administrators.rs new file mode 100644 index 00000000..693a2c70 --- /dev/null +++ b/src/requests/get_chat_administrators.rs @@ -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 + } + +} diff --git a/src/requests/mod.rs b/src/requests/mod.rs index e356bb2f..5349630b 100644 --- a/src/requests/mod.rs +++ b/src/requests/mod.rs @@ -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;