tg_flows/types/game.rs
1use serde::{Deserialize, Serialize};
2
3use crate::types::{Animation, MessageEntity, PhotoSize, User};
4
5/// This object represents a game.
6///
7/// Use [@Botfather] to create and edit games, their short names will act as
8/// unique identifiers.
9///
10/// [@Botfather]: https://t.me/botfather
11#[serde_with_macros::skip_serializing_none]
12#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
13pub struct Game {
14 /// Title of the game.
15 pub title: String,
16
17 /// Description of the game.
18 pub description: String,
19
20 /// Photo that will be displayed in the game message in chats.
21 pub photo: Vec<PhotoSize>,
22
23 /// Brief description of the game or high scores included in the game
24 /// message. Can be automatically edited to include current high scores
25 /// for the game when the bot calls [`SetGameScore`], or manually
26 /// edited using [`EditMessageText`]. 0-4096 characters.
27 ///
28 /// [`SetGameScore`]: crate::payloads::SetGameScore
29 /// [`EditMessageText`]: crate::payloads::EditMessageText
30 pub text: Option<String>,
31
32 /// Special entities that appear in text, such as usernames, URLs, bot
33 /// commands, etc.
34 pub text_entities: Option<Vec<MessageEntity>>,
35
36 /// Animation that will be displayed in the game message in chats. Upload
37 /// via [@Botfather].
38 ///
39 /// [@Botfather]: https://t.me/botfather
40 pub animation: Option<Animation>,
41}
42
43impl Game {
44 /// Returns all users that are "contained" in this `Game`
45 /// structure.
46 ///
47 /// This might be useful to track information about users.
48 ///
49 /// Note that this function can return duplicate users.
50 pub fn mentioned_users(&self) -> impl Iterator<Item = &User> {
51 use crate::util::{flatten, mentioned_users_from_entities};
52
53 flatten(self.text_entities.as_deref().map(mentioned_users_from_entities))
54 }
55}