Add GiveawayWinners struct

This commit is contained in:
Andrey Brusnik 2024-07-16 17:12:13 +04:00
parent fa1b793c7f
commit 9d803693fb
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
3 changed files with 69 additions and 1 deletions

View file

@ -43,6 +43,7 @@ pub use general_forum_topic_hidden::*;
pub use general_forum_topic_unhidden::*; pub use general_forum_topic_unhidden::*;
pub use giveaway::*; pub use giveaway::*;
pub use giveaway_created::*; pub use giveaway_created::*;
pub use giveaway_winners::*;
pub use inaccessible_message::*; pub use inaccessible_message::*;
pub use inline_keyboard_button::*; pub use inline_keyboard_button::*;
pub use inline_keyboard_markup::*; pub use inline_keyboard_markup::*;
@ -178,6 +179,7 @@ mod general_forum_topic_hidden;
mod general_forum_topic_unhidden; mod general_forum_topic_unhidden;
mod giveaway; mod giveaway;
mod giveaway_created; mod giveaway_created;
mod giveaway_winners;
mod inaccessible_message; mod inaccessible_message;
mod inline_keyboard_button; mod inline_keyboard_button;
mod inline_keyboard_markup; mod inline_keyboard_markup;

View file

@ -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<Utc>,
/// Total number of winners in the giveaway
pub winner_count: u32,
/// List of up to 100 winners of the giveaway
pub winners: Vec<User>,
/// The number of other chats the user had to join in order to be eligible
/// for the giveaway
pub additional_chat_count: Option<u16>,
/// The number of months the Telegram Premium subscription won from the
/// giveaway will be active for
pub premium_subscription_month_count: Option<u8>,
/// Number of undistributed prizes
pub unclaimed_prize_count: Option<u32>,
/// `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<String>,
}

View file

@ -7,7 +7,7 @@ use url::Url;
use crate::types::{ use crate::types::{
Animation, Audio, BareChatId, Chat, ChatId, ChatShared, Contact, Dice, Document, Animation, Audio, BareChatId, Chat, ChatId, ChatShared, Contact, Dice, Document,
ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game, ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game,
GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, GiveawayCreated, GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, GiveawayCreated, GiveawayWinners,
InlineKeyboardMarkup, Invoice, Location, MaybeInaccessibleMessage, InlineKeyboardMarkup, Invoice, Location, MaybeInaccessibleMessage,
MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin,
PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, Story, SuccessfulPayment,
@ -79,6 +79,7 @@ pub enum MessageKind {
GeneralForumTopicUnhidden(MessageGeneralForumTopicUnhidden), GeneralForumTopicUnhidden(MessageGeneralForumTopicUnhidden),
Giveaway(MessageGiveaway), Giveaway(MessageGiveaway),
GiveawayCreated(MessageGiveawayCreated), GiveawayCreated(MessageGiveawayCreated),
GiveawayWinners(MessageGiveawayWinners),
VideoChatScheduled(MessageVideoChatScheduled), VideoChatScheduled(MessageVideoChatScheduled),
VideoChatStarted(MessageVideoChatStarted), VideoChatStarted(MessageVideoChatStarted),
VideoChatEnded(MessageVideoChatEnded), VideoChatEnded(MessageVideoChatEnded),
@ -615,6 +616,16 @@ pub struct MessageGiveawayCreated {
pub giveaway_created: GiveawayCreated, 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] #[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatScheduled { pub struct MessageVideoChatScheduled {