From 09d7b060798bbe535ee7bc281842690aa355c913 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Mon, 19 Aug 2024 19:29:07 +0400 Subject: [PATCH] Add `ChatBackground` variant to `MessageKind` enum and add `filter_chat_background_set` to `MessageFilterExt` trait --- crates/teloxide-core/src/types.rs | 2 + .../src/types/chat_background.rs | 13 +++++ crates/teloxide-core/src/types/message.rs | 49 +++++++++++++------ crates/teloxide/src/dispatching/filter_ext.rs | 1 + 4 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 crates/teloxide-core/src/types/chat_background.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index d678200b..e3f3a827 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -23,6 +23,7 @@ pub use callback_query::*; pub use chat::*; pub use chat_action::*; pub use chat_administrator_rights::*; +pub use chat_background::*; pub use chat_boost::*; pub use chat_boost_added::*; pub use chat_boost_removed::*; @@ -190,6 +191,7 @@ mod callback_query; mod chat; mod chat_action; mod chat_administrator_rights; +mod chat_background; mod chat_boost; mod chat_boost_removed; mod chat_boost_source; diff --git a/crates/teloxide-core/src/types/chat_background.rs b/crates/teloxide-core/src/types/chat_background.rs new file mode 100644 index 00000000..c4f3fa06 --- /dev/null +++ b/crates/teloxide-core/src/types/chat_background.rs @@ -0,0 +1,13 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::BackgroundType; + +/// This object represents a chat background. +#[serde_with::skip_serializing_none] +#[derive(Clone, Debug)] +#[derive(PartialEq, Eq, Hash)] +#[derive(Serialize, Deserialize)] +pub struct ChatBackground { + /// Type of the background + pub r#type: BackgroundType, +} diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 2c4cc3c9..e942205e 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -5,15 +5,16 @@ use serde::{Deserialize, Serialize}; use url::Url; use crate::types::{ - Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBoostAdded, ChatId, ChatShared, - Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated, - ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, - Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, - LinkPreviewOptions, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, - MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll, - ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, TextQuote, ThreadId, True, User, - UsersShared, Venue, Video, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, - VideoChatStarted, VideoNote, Voice, WebAppData, WriteAccessAllowed, + Animation, Audio, BareChatId, BusinessConnectionId, Chat, ChatBackground, ChatBoostAdded, + ChatId, ChatShared, Contact, Dice, Document, ExternalReplyInfo, ForumTopicClosed, + ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game, GeneralForumTopicHidden, + GeneralForumTopicUnhidden, Giveaway, GiveawayCompleted, GiveawayCreated, GiveawayWinners, + InlineKeyboardMarkup, Invoice, LinkPreviewOptions, Location, MaybeInaccessibleMessage, + MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin, + PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, + TextQuote, ThreadId, True, User, UsersShared, Venue, Video, VideoChatEnded, + VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, Voice, + WebAppData, WriteAccessAllowed, }; /// This object represents a message. @@ -90,6 +91,7 @@ pub enum MessageKind { Dice(MessageDice), ProximityAlertTriggered(MessageProximityAlertTriggered), ChatBoostAdded(MessageChatBoostAdded), + ChatBackground(MessageChatBackground), ForumTopicCreated(MessageForumTopicCreated), ForumTopicEdited(MessageForumTopicEdited), ForumTopicClosed(MessageForumTopicClosed), @@ -584,6 +586,13 @@ pub struct MessageChatBoostAdded { pub boost_added: ChatBoostAdded, } +#[serde_with::skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct MessageChatBackground { + /// Service message. Chat background set. + pub chat_background_set: ChatBackground, +} + #[serde_with::skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct MessageWriteAccessAllowed { @@ -727,12 +736,12 @@ mod getters { }; use super::{ - MessageChatBoostAdded, MessageForumTopicClosed, MessageForumTopicCreated, - MessageForumTopicEdited, MessageForumTopicReopened, MessageGeneralForumTopicHidden, - MessageGeneralForumTopicUnhidden, MessageGiveaway, MessageGiveawayCompleted, - MessageGiveawayCreated, MessageGiveawayWinners, MessageMessageAutoDeleteTimerChanged, - MessageVideoChatEnded, MessageVideoChatScheduled, MessageVideoChatStarted, - MessageWebAppData, MessageWriteAccessAllowed, + MessageChatBackground, MessageChatBoostAdded, MessageForumTopicClosed, + MessageForumTopicCreated, MessageForumTopicEdited, MessageForumTopicReopened, + MessageGeneralForumTopicHidden, MessageGeneralForumTopicUnhidden, MessageGiveaway, + MessageGiveawayCompleted, MessageGiveawayCreated, MessageGiveawayWinners, + MessageMessageAutoDeleteTimerChanged, MessageVideoChatEnded, MessageVideoChatScheduled, + MessageVideoChatStarted, MessageWebAppData, MessageWriteAccessAllowed, }; /// Getters for [Message] fields from [telegram docs]. @@ -1414,6 +1423,16 @@ mod getters { } } + #[must_use] + pub fn chat_background_set(&self) -> Option<&types::ChatBackground> { + match &self.kind { + ChatBackground(MessageChatBackground { chat_background_set }) => { + Some(chat_background_set) + } + _ => None, + } + } + #[must_use] pub fn forum_topic_created(&self) -> Option<&types::ForumTopicCreated> { match &self.kind { diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index 09b16eb6..ea3c4f14 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -116,6 +116,7 @@ define_message_ext! { (filter_dice, Message::dice), (filter_proximity_alert_triggered, Message::proximity_alert_triggered), (filter_boost_added, Message::boost_added), + (filter_chat_background_set, Message::chat_background_set), (filter_forum_topic_created, Message::forum_topic_created), (filter_forum_topic_edited, Message::forum_topic_edited), (filter_forum_topic_closed, Message::forum_topic_closed),