telers/methods/
set_game_score.rs

1use super::base::{Request, TelegramMethod};
2
3use crate::{client::Bot, types::MessageOrTrue};
4
5use serde::Serialize;
6use serde_with::skip_serializing_none;
7
8/// Use this method to send a game
9/// # Documentation
10/// <https://core.telegram.org/bots/api#setgamescore>
11/// # Returns
12/// On success, the sent [`MessageOrTrue`] is returned
13#[skip_serializing_none]
14#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
15pub struct SetGameScore {
16    /// User identifier
17    pub user_id: i64,
18    /// New score, must be non-negative
19    pub score: u64,
20    /// Pass `true`, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
21    pub force: Option<bool>,
22    /// Pass `true`, if the game message should not be automatically edited to include the current scoreboard
23    pub disable_edit_message: Option<bool>,
24    /// Required if `inline_message_id` is not specified. Unique identifier for the target chat
25    pub chat_id: Option<i64>,
26    /// Required if `inline_message_id` is not specified. Identifier of the sent message
27    pub message_id: Option<i64>,
28    /// Required if `chat_id` and `message_id` are not specified. Identifier of the inline message
29    pub inline_message_id: Option<String>,
30}
31
32impl SetGameScore {
33    #[must_use]
34    pub fn new(user_id: i64, score: u64) -> Self {
35        Self {
36            user_id,
37            score,
38            force: None,
39            disable_edit_message: None,
40            chat_id: None,
41            message_id: None,
42            inline_message_id: None,
43        }
44    }
45
46    #[must_use]
47    pub fn user_id(self, val: i64) -> Self {
48        Self {
49            user_id: val,
50            ..self
51        }
52    }
53
54    #[must_use]
55    pub fn score(self, val: u64) -> Self {
56        Self { score: val, ..self }
57    }
58
59    #[must_use]
60    pub fn force(self, val: bool) -> Self {
61        Self {
62            force: Some(val),
63            ..self
64        }
65    }
66
67    #[must_use]
68    pub fn disable_edit_message(self, val: bool) -> Self {
69        Self {
70            disable_edit_message: Some(val),
71            ..self
72        }
73    }
74
75    #[must_use]
76    pub fn chat_id(self, val: i64) -> Self {
77        Self {
78            chat_id: Some(val),
79            ..self
80        }
81    }
82
83    #[must_use]
84    pub fn message_id(self, val: i64) -> Self {
85        Self {
86            message_id: Some(val),
87            ..self
88        }
89    }
90
91    #[must_use]
92    pub fn inline_message_id(self, val: impl Into<String>) -> Self {
93        Self {
94            inline_message_id: Some(val.into()),
95            ..self
96        }
97    }
98}
99
100impl SetGameScore {
101    #[must_use]
102    pub fn force_option(self, val: Option<bool>) -> Self {
103        Self { force: val, ..self }
104    }
105
106    #[must_use]
107    pub fn disable_edit_message_option(self, val: Option<bool>) -> Self {
108        Self {
109            disable_edit_message: val,
110            ..self
111        }
112    }
113
114    #[must_use]
115    pub fn chat_id_option(self, val: Option<i64>) -> Self {
116        Self {
117            chat_id: val,
118            ..self
119        }
120    }
121
122    #[must_use]
123    pub fn message_id_option(self, val: Option<i64>) -> Self {
124        Self {
125            message_id: val,
126            ..self
127        }
128    }
129
130    #[must_use]
131    pub fn inline_message_id_option(self, val: Option<impl Into<String>>) -> Self {
132        Self {
133            inline_message_id: val.map(Into::into),
134            ..self
135        }
136    }
137}
138
139impl TelegramMethod for SetGameScore {
140    type Method = Self;
141    type Return = MessageOrTrue;
142
143    fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
144        Request::new("setGameScore", self, None)
145    }
146}
147
148impl AsRef<SetGameScore> for SetGameScore {
149    fn as_ref(&self) -> &Self {
150        self
151    }
152}