Merge branch 'dev' into requests_gymmasssorla

This commit is contained in:
Temirkhan Myrzamadi 2019-10-17 15:41:34 +00:00 committed by GitHub
commit e8b402ea21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 1 deletions

View file

@ -10,7 +10,7 @@ use crate::{
PinChatMessage, PromoteChatMember, RestrictChatMember, SendAudio,
SendChatAction, SendContact, SendLocation, SendMediaGroup, SendMessage,
SendPhoto, SendPoll, SendVenue, SendVideoNote, SendVoice,
StopMessageLiveLocation, UnbanChatMember, UnpinChatMessage,
SetChatDescription, StopMessageLiveLocation, UnbanChatMember, UnpinChatMessage,
},
types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
};
@ -260,6 +260,13 @@ impl Bot {
SendVoice::new(self, chat_id, voice)
}
pub fn send_chat_description<C>(&self, chat_id: C) -> SetChatDescription
where
C: Into<ChatId>,
{
SetChatDescription::new(self, chat_id)
}
pub fn unban_chat_member<C, U>(
&self,
chat_id: C,

View file

@ -35,6 +35,7 @@ pub use send_video::*;
pub use send_video_note::*;
pub use send_voice::*;
pub use set_chat_sticker_set::*;
pub use set_chat_description::*;
pub use stop_message_live_location::*;
pub use unban_chat_member::*;
pub use unpin_chat_message::*;
@ -74,6 +75,7 @@ mod send_video;
mod send_video_note;
mod send_voice;
mod set_chat_sticker_set;
mod set_chat_description;
mod stop_message_live_location;
mod unban_chat_member;
mod unpin_chat_message;

View file

@ -0,0 +1,96 @@
use async_trait::async_trait;
use crate::{
network,
requests::{Request, ResponseResult},
types::{True, ChatId},
bot::Bot,
};
#[derive(Debug, Clone, Serialize)]
pub struct SetChatDescription<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
}
#[async_trait]
impl Request for SetChatDescription<'_> {
type Output = True;
async fn send_boxed(self) -> ResponseResult<Self::Output> {
self.send().await
}
}
impl SetChatDescription<'_> {
pub async fn send(self) -> ResponseResult<True> {
network::request_json(
&self.bot.client(),
&self.bot.token(),
"setChatDescription",
&self
).await
}
}
impl<'a> SetChatDescription<'a> {
pub(crate) fn new<C>(
bot: &'a Bot,
chat_id: C,
) -> Self
where C: Into<ChatId>
{
Self {
bot,
chat_id: chat_id.into(),
description: 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 description<T>(mut self, description: T) -> Self
where T: Into<String>
{
self.description = Some(description.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serialize_new() {
let bot = Bot::new("token");
let chat_id = 123;
let method = SetChatDescription::new(&bot, chat_id);
let expected = r#"{"chat_id":123}"#;
let actual = serde_json::to_string::<SetChatDescription>(&method).unwrap();
assert_eq!(actual, expected);
}
#[test]
fn serialize_description() {
let bot = Bot::new("token");
let chat_id = 123;
let description = "description";
let method = SetChatDescription::new(&bot, chat_id)
.description(description);
let expected = r#"{"chat_id":123,"description":"description"}"#;
let actual = serde_json::to_string::<SetChatDescription>(&method).unwrap();
assert_eq!(actual, expected);
}
}