1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
use serde::{Deserialize, Serialize};
use crate::types::{Chat, Integer, Message, User};
/// Represents a message about a scheduled giveaway.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
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.
pub winners_selection_date: Integer,
/// The number of users which are supposed to be selected as winners of the giveaway.
pub winner_count: Integer,
/// A list of two-letter 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>>,
/// Whether the list of giveaway winners will be visible to everyone.
pub has_public_winners: Option<bool>,
/// Whether only users who join the chats after the giveaway started should be eligible to win.
pub only_new_members: Option<bool>,
/// The number of months the Telegram Premium subscription won from the giveaway will be active for.
pub premium_subscription_month_count: Option<Integer>,
/// Description of additional giveaway prize.
pub prize_description: Option<String>,
/// The number of Telegram Stars to be split between giveaway winners;
/// for Telegram Star giveaways only.
pub prize_star_count: Option<Integer>,
}
impl Giveaway {
/// Creates a new `Giveaway`.
///
/// # Arguments
///
/// * `chats` - The list of chats which the user must join to participate in the giveaway.
/// * `winners_selection_date` - Point in time (Unix timestamp) when winners of the giveaway will be selected.
/// * `winner_count` - The number of users which are supposed to be selected as winners of the giveaway.
pub fn new<A, B>(chats: A, winners_selection_date: Integer, winner_count: Integer) -> Self
where
A: IntoIterator<Item = B>,
B: Into<Chat>,
{
Self {
chats: chats.into_iter().map(Into::into).collect(),
winners_selection_date,
winner_count,
country_codes: None,
has_public_winners: None,
only_new_members: None,
premium_subscription_month_count: None,
prize_description: None,
prize_star_count: None,
}
}
/// Sets a new list of country codes.
///
/// # Arguments
///
/// * `value` - A list of two-letter ISO 3166-1 alpha-2 country codes.
pub fn with_country_codes<A, B>(mut self, value: A) -> Self
where
A: IntoIterator<Item = B>,
B: Into<String>,
{
self.country_codes = Some(value.into_iter().map(Into::into).collect());
self
}
/// Sets a new value for the `has_public_winners` flag.
///
/// # Arguments
///
/// * `value` - Whether the list of giveaway winners will be visible to everyone.
pub fn with_has_public_winners(mut self, value: bool) -> Self {
self.has_public_winners = Some(value);
self
}
/// Sets a new value for the `only_new_members` flag.
///
/// # Arguments
///
/// * `value` - Whether only users who join the chats after the giveaway started should be eligible to win.
pub fn with_only_new_members(mut self, value: bool) -> Self {
self.only_new_members = Some(value);
self
}
/// Sets a new number of premium subscription months.
///
/// # Arguments
///
/// * `value` - The number of months the Telegram Premium subscription won from the giveaway will be active for.
pub fn with_premium_subscription_month_count(mut self, value: Integer) -> Self {
self.premium_subscription_month_count = Some(value);
self
}
/// Sets a new description of additional prizes.
///
/// # Arguments
///
/// * `value` - Description of additional giveaway prize.
pub fn with_prize_description<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.prize_description = Some(value.into());
self
}
/// Sets a new prize star count.
///
/// # Arguments
///
/// * `value` - The number of Telegram Stars to be split between giveaway winners;
/// for Telegram Star giveaways only.
pub fn with_prize_star_count(mut self, value: Integer) -> Self {
self.prize_star_count = Some(value);
self
}
}
/// Represents a service message about the creation of a scheduled giveaway.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct GiveawayCreated {
/// The number of Telegram Stars to be split between giveaway winners;
/// for Telegram Star giveaways only.
pub prize_star_count: Option<Integer>,
}
impl GiveawayCreated {
/// Sets a new prize star count.
///
/// # Arguments
///
/// * `value` - The number of Telegram Stars to be split between giveaway winners;
/// for Telegram Star giveaways only.
pub fn with_prize_star_count(mut self, value: Integer) -> Self {
self.prize_star_count = Some(value);
self
}
}
/// Represents a service message about the completion of a giveaway without public winners.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GiveawayCompleted {
/// Number of winners in the giveaway.
pub winner_count: Integer,
/// Message with the giveaway that was completed, if it wasn't deleted.
pub giveaway_message: Option<Box<Message>>,
/// Whether the giveaway is a Telegram Star giveaway.
///
/// Otherwise, currently, the giveaway is a Telegram Premium giveaway.
pub is_star_giveaway: Option<bool>,
/// Number of undistributed prizes.
pub unclaimed_prize_count: Option<Integer>,
}
impl GiveawayCompleted {
/// Creates a new `GiveawayCompleted`.
///
/// # Arguments
///
/// * `winner_count` - Number of winners in the giveaway.
pub fn new(winner_count: Integer) -> Self {
Self {
winner_count,
giveaway_message: None,
is_star_giveaway: None,
unclaimed_prize_count: None,
}
}
/// Sets a new giveaway message.
///
/// # Arguments
///
/// * `value` - Message with the giveaway that was completed.
pub fn with_giveaway_message(mut self, value: Message) -> Self {
self.giveaway_message = Some(Box::new(value));
self
}
/// Sets a new value for the `is_star_giveaway` flag.
///
/// # Arguments
///
/// * `value` - Whether the giveaway is a Telegram Star giveaway.
/// Otherwise, currently, the giveaway is a Telegram Premium giveaway.
pub fn with_is_star_giveaway(mut self, value: bool) -> Self {
self.is_star_giveaway = Some(value);
self
}
/// Sets a new unclaimed prize count.
///
/// # Arguments
///
/// * `value` - Number of undistributed prizes.
pub fn with_unclaimed_prize_count(mut self, value: Integer) -> Self {
self.unclaimed_prize_count = Some(value);
self
}
}
/// Represents a message about the completion of a giveaway with public winners.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct GiveawayWinners {
/// The chat that created the giveaway.
pub chat: Chat,
/// Identifier of the messsage with the giveaway in the chat.
pub giveaway_message_id: Integer,
/// Total number of winners in the giveaway.
pub winner_count: Integer,
/// List of up to 100 winners of the giveaway.
pub winners: Vec<User>,
/// Point in time (Unix timestamp) when winners of the giveaway were selected.
pub winners_selection_date: Integer,
/// The number of other chats the user had to join in order to be eligible for the giveaway.
pub additional_chat_count: Option<Integer>,
/// Whether only users who had joined the chats after the giveaway started were eligible to win.
pub only_new_members: Option<bool>,
/// The number of months the Telegram Premium subscription won from the giveaway will be active for.
pub premium_subscription_month_count: Option<Integer>,
/// Description of additional giveaway prize.
pub prize_description: Option<String>,
/// The number of Telegram Stars that were split between giveaway winners;
/// for Telegram Star giveaways only.
pub prize_star_count: Option<Integer>,
/// Number of undistributed prizes.
pub unclaimed_prize_count: Option<Integer>,
/// Whether the giveaway was canceled because the payment for it was refunded.
pub was_refunded: Option<bool>,
}
impl GiveawayWinners {
/// Creates a new `GiveawayWinners`.
///
///
/// # Arguments
///
/// * `chat` - The chat that created the giveaway.
/// * `giveaway_message_id` - Identifier of the messsage with the giveaway in the chat.
/// * `winner_count` - Total number of winners in the giveaway.
/// * `winners` - List of up to 100 winners of the giveaway.
/// * `winners_selection_date` - Point in time (Unix timestamp) when winners of the giveaway were selected.
pub fn new<A, B>(
chat: A,
giveaway_message_id: Integer,
winner_count: Integer,
winners: B,
winners_selection_date: Integer,
) -> Self
where
A: Into<Chat>,
B: IntoIterator<Item = User>,
{
Self {
chat: chat.into(),
giveaway_message_id,
winner_count,
winners: winners.into_iter().collect(),
winners_selection_date,
additional_chat_count: None,
only_new_members: None,
premium_subscription_month_count: None,
prize_description: None,
prize_star_count: None,
unclaimed_prize_count: None,
was_refunded: None,
}
}
/// Sets a new number of additional chats.
///
/// # Arguments
///
/// * `value` - The number of other chats the user had to join in order to be eligible for the giveaway.
pub fn with_additional_chat_count(mut self, value: Integer) -> Self {
self.additional_chat_count = Some(value);
self
}
/// Sets a new value for the `only_new_members` flag.
///
/// # Arguments
///
/// * `value` - Whether only users who had joined the chats after the giveaway started were eligible to win.
pub fn with_only_new_members(mut self, value: bool) -> Self {
self.only_new_members = Some(value);
self
}
/// Sets a new number of premium subscription months.
///
/// # Arguments
///
/// * `value` - The number of months the Telegram Premium subscription won from the giveaway will be active for.
pub fn with_premium_subscription_month_count(mut self, value: Integer) -> Self {
self.premium_subscription_month_count = Some(value);
self
}
/// Sets a new prize description.
///
/// # Arguments
///
/// * `value` - Description of additional giveaway prize.
pub fn with_prize_description<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.prize_description = Some(value.into());
self
}
/// Sets a new prize star count.
///
/// # Arguments
///
/// * `value` - The number of Telegram Stars to be split between giveaway winners;
/// for Telegram Star giveaways only.
pub fn with_prize_star_count(mut self, value: Integer) -> Self {
self.prize_star_count = Some(value);
self
}
/// Sets a new number of unclaimed prizes.
///
/// # Arguments
///
/// * `value` - Number of undistributed prizes.
pub fn with_unclaimed_prize_count(mut self, value: Integer) -> Self {
self.unclaimed_prize_count = Some(value);
self
}
/// Sets a new value for the `was_refunded` flag.
///
/// # Arguments
///
/// * `value` - Whether the giveaway was canceled because the payment for it was refunded.
pub fn with_was_refunded(mut self, value: bool) -> Self {
self.was_refunded = Some(value);
self
}
}