Add Giveaway struct

This commit is contained in:
Andrey Brusnik 2024-07-16 16:48:23 +04:00
parent c0f97fae0e
commit 62da0027e3
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
3 changed files with 64 additions and 6 deletions

View file

@ -41,6 +41,7 @@ pub use game::*;
pub use game_high_score::*;
pub use general_forum_topic_hidden::*;
pub use general_forum_topic_unhidden::*;
pub use giveaway::*;
pub use inaccessible_message::*;
pub use inline_keyboard_button::*;
pub use inline_keyboard_markup::*;
@ -174,6 +175,7 @@ mod game;
mod game_high_score;
mod general_forum_topic_hidden;
mod general_forum_topic_unhidden;
mod giveaway;
mod inaccessible_message;
mod inline_keyboard_button;
mod inline_keyboard_markup;

View file

@ -0,0 +1,45 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::Chat;
/// This object represents a message about a scheduled giveaway.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Giveaway {
/// The list of chats which the user must join to participate in the
/// giveaway.
pub chats: Vec<Chat>,
/// Point in time (Unix timestamp) when winners of the giveaway will be
/// selected
#[serde(with = "crate::types::serde_date_from_unix_timestamp")]
pub winners_selection_date: DateTime<Utc>,
/// The number of users which are supposed to be selected as winners of the
/// giveaway
pub winner_count: u32,
/// `true`, if only users who join the chats after the giveaway started
/// should be eligible to win
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub only_new_members: bool,
/// `true`, if the list of giveaway winners will be visible to everyone
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub has_public_winners: bool,
/// Description of additional giveaway prize
pub prize_description: Option<String>,
/// A list of two-letter [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country codes indicating the
/// countries from which eligible users for the giveaway must come. If
/// empty, then all users can participate in the giveaway. Users with a
/// phone number that was bought on Fragment can always participate in
/// giveaways.
pub country_codes: Option<Vec<String>>,
/// The number of months the Telegram Premium subscription won from the
/// giveaway will be active for
pub premium_subscription_month_count: Option<u8>,
}

View file

@ -7,12 +7,12 @@ use url::Url;
use crate::types::{
Animation, Audio, BareChatId, Chat, ChatId, ChatShared, Contact, Dice, Document,
ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, Game,
GeneralForumTopicHidden, GeneralForumTopicUnhidden, InlineKeyboardMarkup, Invoice, 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,
GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, InlineKeyboardMarkup, Invoice,
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.
@ -76,6 +76,7 @@ pub enum MessageKind {
ForumTopicReopened(MessageForumTopicReopened),
GeneralForumTopicHidden(MessageGeneralForumTopicHidden),
GeneralForumTopicUnhidden(MessageGeneralForumTopicUnhidden),
Giveaway(MessageGiveaway),
VideoChatScheduled(MessageVideoChatScheduled),
VideoChatStarted(MessageVideoChatStarted),
VideoChatEnded(MessageVideoChatEnded),
@ -592,6 +593,16 @@ pub struct MessageGeneralForumTopicUnhidden {
pub general_forum_topic_unhidden: GeneralForumTopicUnhidden,
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageGiveaway {
/// Message is giveaway, information about a scheduled giveaway. [More about
/// giveaways »]
///
/// [More about giveaways »]: https://core.telegram.org/api#giveaways-amp-gifts
pub giveaway: Giveaway,
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct MessageVideoChatScheduled {