levaeChat

This commit is contained in:
RustemB 2019-10-20 12:30:07 +05:00
parent e0a278701d
commit 66147232e6
2 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,50 @@
use async_trait::async_trait;
use crate::{
bot::Bot,
network,
requests::{Request, ResponseResult},
types::ChatId,
};
/// Use this method for your bot to leave a group, supergroup or channel.
/// Returns True on success.
#[derive(Debug, Clone, Serialize)]
pub struct LeaveChat<'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 LeaveChat<'_> {
type Output = bool;
async fn send_boxed(self) -> ResponseResult<Self::Output> {
self.send().await
}
}
impl LeaveChat<'_> {
pub async fn send(self) -> ResponseResult<bool> {
network::request_json(
self.bot.client(),
self.bot.token(),
"leaveChat",
&self,
)
.await
}
}
impl<'a> LeaveChat<'a> {
pub fn chat_id<C>(mut self, value: C) -> Self
where
C: Into<ChatId>,
{
self.chat_id = value.into();
self
}
}

View file

@ -19,6 +19,7 @@ pub use get_me::*;
pub use get_updates::*;
pub use get_user_profile_photos::*;
pub use kick_chat_member::*;
pub use leave_chat::*;
pub use pin_chat_message::*;
pub use promote_chat_member::*;
pub use restrict_chat_member::*;
@ -64,6 +65,7 @@ mod get_me;
mod get_updates;
mod get_user_profile_photos;
mod kick_chat_member;
mod leave_chat;
mod pin_chat_message;
mod promote_chat_member;
mod restrict_chat_member;