From 9d803693fbc20d69626719612f47a34de4dcbfc9 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Tue, 16 Jul 2024 17:12:13 +0400 Subject: [PATCH] Add `GiveawayWinners` struct --- crates/teloxide-core/src/types.rs | 2 + .../src/types/giveaway_winners.rs | 55 +++++++++++++++++++ crates/teloxide-core/src/types/message.rs | 13 ++++- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 crates/teloxide-core/src/types/giveaway_winners.rs diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index a55d9dad..ff89de7e 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -43,6 +43,7 @@ pub use general_forum_topic_hidden::*; pub use general_forum_topic_unhidden::*; pub use giveaway::*; pub use giveaway_created::*; +pub use giveaway_winners::*; pub use inaccessible_message::*; pub use inline_keyboard_button::*; pub use inline_keyboard_markup::*; @@ -178,6 +179,7 @@ mod general_forum_topic_hidden; mod general_forum_topic_unhidden; mod giveaway; mod giveaway_created; +mod giveaway_winners; mod inaccessible_message; mod inline_keyboard_button; mod inline_keyboard_markup; diff --git a/crates/teloxide-core/src/types/giveaway_winners.rs b/crates/teloxide-core/src/types/giveaway_winners.rs new file mode 100644 index 00000000..9ef4dee4 --- /dev/null +++ b/crates/teloxide-core/src/types/giveaway_winners.rs @@ -0,0 +1,55 @@ +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use serde_with::with_prefix; + +use crate::types::{Chat, MessageId, User}; + +with_prefix!(prefix_giveaway "giveaway_"); + +/// This object represents a message about the completion of a giveaway with +/// public winners. +#[serde_with::skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct GiveawayWinners { + /// The chat that created the giveaway + pub chat: Chat, + + /// Identifier of the messsage with the giveaway in the chat + #[serde(flatten, with = "prefix_giveaway")] + pub giveaway_message_id: MessageId, + + /// Point in time (Unix timestamp) when winners of the giveaway were + /// selected + #[serde(with = "crate::types::serde_date_from_unix_timestamp")] + pub winners_selection_date: DateTime, + + /// Total number of winners in the giveaway + pub winner_count: u32, + + /// List of up to 100 winners of the giveaway + pub winners: Vec, + + /// The number of other chats the user had to join in order to be eligible + /// for the giveaway + pub additional_chat_count: Option, + + /// The number of months the Telegram Premium subscription won from the + /// giveaway will be active for + pub premium_subscription_month_count: Option, + + /// Number of undistributed prizes + pub unclaimed_prize_count: Option, + + /// `true`, if only users who had joined the chats after the giveaway + /// started were eligible to win + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub only_new_members: bool, + + /// `true`, if the giveaway was canceled because the payment for it was + /// refunded + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub was_refunded: bool, + + /// Description of additional giveaway prize + pub prize_description: Option, +} diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index ee85e240..24aafe08 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -7,7 +7,7 @@ use url::Url; use crate::types::{ Animation, Audio, BareChatId, Chat, ChatId, ChatShared, Contact, Dice, Document, ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game, - GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, GiveawayCreated, + GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, @@ -79,6 +79,7 @@ pub enum MessageKind { GeneralForumTopicUnhidden(MessageGeneralForumTopicUnhidden), Giveaway(MessageGiveaway), GiveawayCreated(MessageGiveawayCreated), + GiveawayWinners(MessageGiveawayWinners), VideoChatScheduled(MessageVideoChatScheduled), VideoChatStarted(MessageVideoChatStarted), VideoChatEnded(MessageVideoChatEnded), @@ -615,6 +616,16 @@ pub struct MessageGiveawayCreated { pub giveaway_created: GiveawayCreated, } +#[serde_with::skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct MessageGiveawayWinners { + /// Message is giveaway winners, information about the completion of a + /// giveaway with public winners. [More about giveaways »] + /// + /// [More about giveaways »]: https://core.telegram.org/api#giveaways-amp-gifts + pub giveaway_winners: GiveawayWinners, +} + #[serde_with::skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct MessageVideoChatScheduled {