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
use serde::{Deserialize, Serialize};
/// This object represents a game. Use `BotFather` to create and edit games, their short names will act as unique identifiers.
/// # Documentation
/// <https://core.telegram.org/bots/api#game>
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Game {
/// Title of the game
pub title: Box<str>,
/// Description of the game
pub description: Box<str>,
/// Photo that will be displayed in the game message in chats.
pub photo: Box<[crate::types::PhotoSize]>,
/// Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<Box<str>>,
/// Special entities that appear in text, such as usernames, URLs, bot commands, etc.
#[serde(skip_serializing_if = "Option::is_none")]
pub text_entities: Option<Box<[crate::types::MessageEntity]>>,
/// Animation that will be displayed in the game message in chats. Upload via `BotFather`
#[serde(skip_serializing_if = "Option::is_none")]
pub animation: Option<Box<crate::types::Animation>>,
}
impl Game {
/// Creates a new `Game`.
///
/// # Arguments
/// * `title` - Title of the game
/// * `description` - Description of the game
/// * `photo` - Photo that will be displayed in the game message in chats.
///
/// # Notes
/// Use builder methods to set optional fields.
#[must_use]
pub fn new<
T0: Into<Box<str>>,
T1: Into<Box<str>>,
T2Item: Into<crate::types::PhotoSize>,
T2: IntoIterator<Item = T2Item>,
>(
title: T0,
description: T1,
photo: T2,
) -> Self {
Self {
title: title.into(),
description: description.into(),
photo: photo.into_iter().map(Into::into).collect(),
text: None,
text_entities: None,
animation: None,
}
}
/// Title of the game
#[must_use]
pub fn title<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.title = val.into();
this
}
/// Description of the game
#[must_use]
pub fn description<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.description = val.into();
this
}
/// Photo that will be displayed in the game message in chats.
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn photos<T: Into<Box<[crate::types::PhotoSize]>>>(self, val: T) -> Self {
let mut this = self;
this.photo = this
.photo
.into_vec()
.into_iter()
.chain(val.into())
.collect();
this
}
/// Photo that will be displayed in the game message in chats.
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn photo<T: Into<crate::types::PhotoSize>>(self, val: T) -> Self {
let mut this = self;
this.photo = this
.photo
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect();
this
}
/// Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
#[must_use]
pub fn text<T: Into<Box<str>>>(self, val: T) -> Self {
let mut this = self;
this.text = Some(val.into());
this
}
/// Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
#[must_use]
pub fn text_option<T: Into<Box<str>>>(self, val: Option<T>) -> Self {
let mut this = self;
this.text = val.map(Into::into);
this
}
/// Special entities that appear in text, such as usernames, URLs, bot commands, etc.
///
/// # Notes
/// Adds multiple elements.
#[must_use]
pub fn text_entities<T: Into<Box<[crate::types::MessageEntity]>>>(self, val: T) -> Self {
let mut this = self;
this.text_entities = Some(
this.text_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(val.into())
.collect(),
);
this
}
/// Special entities that appear in text, such as usernames, URLs, bot commands, etc.
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn text_entity<T: Into<crate::types::MessageEntity>>(self, val: T) -> Self {
let mut this = self;
this.text_entities = Some(
this.text_entities
.unwrap_or_default()
.into_vec()
.into_iter()
.chain(Some(val.into()))
.collect(),
);
this
}
/// Special entities that appear in text, such as usernames, URLs, bot commands, etc.
///
/// # Notes
/// Adds a single element.
#[must_use]
pub fn text_entities_option<T: Into<Box<[crate::types::MessageEntity]>>>(
self,
val: Option<T>,
) -> Self {
let mut this = self;
this.text_entities = val.map(Into::into);
this
}
/// Animation that will be displayed in the game message in chats. Upload via `BotFather`
#[must_use]
pub fn animation<T: Into<crate::types::Animation>>(self, val: T) -> Self {
let mut this = self;
this.animation = Some(Box::new(val.into()));
this
}
/// Animation that will be displayed in the game message in chats. Upload via `BotFather`
#[must_use]
pub fn animation_option<T: Into<crate::types::Animation>>(self, val: Option<T>) -> Self {
let mut this = self;
this.animation = val.map(|val| Box::new(val.into()));
this
}
}