diff --git a/raw/src/requests/mod.rs b/raw/src/requests/mod.rs index 4d744a2d1a..6604f1429c 100644 --- a/raw/src/requests/mod.rs +++ b/raw/src/requests/mod.rs @@ -30,6 +30,7 @@ pub mod send_photo; pub mod send_poll; pub mod send_venue; pub mod send_video; +pub mod set_chat_description; pub mod stop_message_live_location; pub mod stop_poll; pub mod unban_chat_member; @@ -66,6 +67,7 @@ pub use self::send_photo::*; pub use self::send_poll::*; pub use self::send_venue::*; pub use self::send_video::*; +pub use self::set_chat_description::*; pub use self::stop_message_live_location::*; pub use self::stop_poll::*; pub use self::unban_chat_member::*; diff --git a/raw/src/requests/send_message.rs b/raw/src/requests/send_message.rs index 5aca4663cd..95dc9aa471 100644 --- a/raw/src/requests/send_message.rs +++ b/raw/src/requests/send_message.rs @@ -114,7 +114,7 @@ where where T: Into>, { - let mut rq = self.to_source_chat().text(text); + let mut rq = send_message::CanSendMessage::text(&self.to_source_chat(), text); rq.reply_to(self.to_message_id()); rq } diff --git a/raw/src/requests/set_chat_description.rs b/raw/src/requests/set_chat_description.rs new file mode 100644 index 0000000000..aad9288d39 --- /dev/null +++ b/raw/src/requests/set_chat_description.rs @@ -0,0 +1,53 @@ +use std::borrow::Cow; + +use crate::requests::*; +use crate::types::*; + +/// Use this method to set group descriptions. +#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)] +#[must_use = "requests do nothing unless sent"] +pub struct SetChatDescription<'s> { + chat_id: ChatRef, + description: Cow<'s, str>, +} + +impl<'c, 's> Request for SetChatDescription<'s> { + type Type = JsonRequestType; + type Response = JsonIdResponse; + + fn serialize(&self) -> Result { + Self::Type::serialize(RequestUrl::method("setChatDescription"), self) + } +} + +impl<'s> SetChatDescription<'s> { + pub fn new(chat: C, description: D) -> Self + where + C: ToChatRef, + D: Into>, + { + SetChatDescription { + chat_id: chat.to_chat_ref(), + description: description.into(), + } + } +} + +/// Set chat description. +pub trait CanSetChatDescription { + fn text<'s, T>(&self, text: T) -> SetChatDescription<'s> + where + T: Into>; +} + +impl CanSetChatDescription for C +where + C: ToChatRef, +{ + fn text<'s, D>(&self, text: D) -> SetChatDescription<'s> + where + D: Into>, + { + SetChatDescription::new(self, text) + } +} diff --git a/raw/src/types/chat.rs b/raw/src/types/chat.rs index 2aa016411f..9553a6aa03 100644 --- a/raw/src/types/chat.rs +++ b/raw/src/types/chat.rs @@ -32,6 +32,8 @@ pub struct Group { /// You can generate a new invite link by using the /// export_invite_link method. pub invite_link: Option, + /// The group's description. + pub description: Option, } /// This object represents a supergroup. @@ -47,6 +49,8 @@ pub struct Supergroup { /// You can generate a new invite link by using the /// export_invite_link method. pub invite_link: Option, + /// The group's description. + pub description: Option, } /// This object represents a channel. @@ -62,6 +66,8 @@ pub struct Channel { /// You can generate a new invite link by using the /// export_invite_link method. pub invite_link: Option, + /// Channel description + pub description: Option, } /// This object represents a private, group or supergroup. @@ -138,18 +144,21 @@ impl<'de> Deserialize<'de> for Chat { title: required_field!(title), all_members_are_administrators: required_field!(all_members_are_administrators), invite_link: raw.invite_link, + description: raw.description, }), "supergroup" => Chat::Supergroup(Supergroup { id: raw.id.into(), title: required_field!(title), username: raw.username, invite_link: raw.invite_link, + description: raw.description, }), "channel" => Chat::Channel(Channel { id: raw.id.into(), title: required_field!(title), username: raw.username, invite_link: raw.invite_link, + description: raw.description, }), _ => Chat::Unknown(raw), }) @@ -179,4 +188,6 @@ pub struct RawChat { pub language_code: Option, /// True if a group has ‘All Members Are Admins’ enabled. pub all_members_are_administrators: Option, + /// The group's description + pub description: Option, }