Skip to main content

rustigram_types/
games.rs

1use crate::file::{Animation, PhotoSize};
2use crate::message::MessageEntity;
3use crate::user::User;
4use serde::{Deserialize, Serialize};
5
6/// A game to be played in a Telegram chat.
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
8#[non_exhaustive]
9pub struct Game {
10    /// Title of the game.
11    pub title: String,
12    /// Description of the game.
13    pub description: String,
14    /// Photo displayed in the game message in chats.
15    pub photo: Vec<PhotoSize>,
16    /// Brief description of the game, or high scores included in the message.
17    ///
18    /// Set by calling [`setGameScore`](https://core.telegram.org/bots/api#setgamescore),
19    /// or edited via
20    /// [`editMessageText`](https://core.telegram.org/bots/api#editmessagetext).
21    /// 0–4096 characters.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub text: Option<String>,
24    /// Special entities that appear in `text`.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub text_entities: Option<Vec<MessageEntity>>,
27    /// Animation displayed in the game message in chats.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub animation: Option<Animation>,
30}
31
32/// Placeholder identifying a game callback button.
33///
34/// Telegram documents this as an object with no fields, so it is an empty
35/// braced struct rather than a unit struct — the wire value is `{}`, and a unit
36/// struct would only deserialize from `null`.
37#[derive(Debug, Clone, Default, Serialize, Deserialize)]
38#[non_exhaustive]
39pub struct CallbackGame {}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
42/// One entry in a game high score table.
43///
44/// Returned as a list by [`getGameHighScores`](https://core.telegram.org/bots/api#getgamehighscores).
45pub struct GameHighScore {
46    /// Position in the high score table.
47    pub position: u32,
48    /// The user at this position.
49    pub user: User,
50    /// Score of the user.
51    pub score: i64,
52}