conogram/methods/
set_game_score.rs1use std::{
2 future::{Future, IntoFuture},
3 pin::Pin,
4};
5
6use serde::Serialize;
7
8use crate::{
9 api::API, entities::message::Message, errors::ConogramError, impl_into_future,
10 request::RequestT, utils::deserialize_utils::is_false,
11};
12
13#[derive(Debug, Clone, Serialize)]
14pub struct SetGameScoreParams {
15 pub user_id: i64,
16 pub score: i64,
17 #[serde(default, skip_serializing_if = "is_false")]
18 pub force: bool,
19 #[serde(default, skip_serializing_if = "is_false")]
20 pub disable_edit_message: bool,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub chat_id: Option<i64>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub message_id: Option<i64>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub inline_message_id: Option<String>,
27}
28
29impl_into_future!(SetGameScoreRequest<'a>);
30
31#[derive(Clone)]
33pub struct SetGameScoreRequest<'a> {
34 api: &'a API,
35 params: SetGameScoreParams,
36}
37
38impl<'a> RequestT for SetGameScoreRequest<'a> {
39 type ParamsType = SetGameScoreParams;
40 type ReturnType = Option<Message>;
41 fn get_name() -> &'static str {
42 "setGameScore"
43 }
44 fn get_api_ref(&self) -> &API {
45 self.api
46 }
47 fn get_params_ref(&self) -> &Self::ParamsType {
48 &self.params
49 }
50 fn is_multipart() -> bool {
51 false
52 }
53}
54impl<'a> SetGameScoreRequest<'a> {
55 pub fn new(api: &'a API, user_id: impl Into<i64>, score: impl Into<i64>) -> Self {
56 Self {
57 api,
58 params: SetGameScoreParams {
59 user_id: user_id.into(),
60 score: score.into(),
61 force: bool::default(),
62 disable_edit_message: bool::default(),
63 chat_id: Option::default(),
64 message_id: Option::default(),
65 inline_message_id: Option::default(),
66 },
67 }
68 }
69
70 #[must_use]
72 pub fn user_id(mut self, user_id: impl Into<i64>) -> Self {
73 self.params.user_id = user_id.into();
74 self
75 }
76
77 #[must_use]
79 pub fn score(mut self, score: impl Into<i64>) -> Self {
80 self.params.score = score.into();
81 self
82 }
83
84 #[must_use]
86 pub fn force(mut self, force: impl Into<bool>) -> Self {
87 self.params.force = force.into();
88 self
89 }
90
91 #[must_use]
93 pub fn disable_edit_message(mut self, disable_edit_message: impl Into<bool>) -> Self {
94 self.params.disable_edit_message = disable_edit_message.into();
95 self
96 }
97
98 #[must_use]
100 pub fn chat_id(mut self, chat_id: impl Into<i64>) -> Self {
101 self.params.chat_id = Some(chat_id.into());
102 self
103 }
104
105 #[must_use]
107 pub fn message_id(mut self, message_id: impl Into<i64>) -> Self {
108 self.params.message_id = Some(message_id.into());
109 self
110 }
111
112 #[must_use]
114 pub fn inline_message_id(mut self, inline_message_id: impl Into<String>) -> Self {
115 self.params.inline_message_id = Some(inline_message_id.into());
116 self
117 }
118}
119
120impl API {
121 pub fn set_game_score(
123 &self,
124 user_id: impl Into<i64>,
125 score: impl Into<i64>,
126 ) -> SetGameScoreRequest {
127 SetGameScoreRequest::new(self, user_id, score)
128 }
129}
130
131