Skip to main content

rust_tg_bot_raw/bot/
games_methods.rs

1use super::{push_opt, push_opt_str, Bot, MessageOrBool, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{games, message, reply};
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Games
9    // ======================================================================
10
11    /// Use this method to send a game.
12    ///
13    /// Calls the Telegram `sendGame` API method.
14    pub async fn send_game_raw(
15        &self,
16        chat_id: i64,
17        game_short_name: &str,
18        disable_notification: Option<bool>,
19        protect_content: Option<bool>,
20        reply_parameters: Option<reply::ReplyParameters>,
21        reply_markup: Option<serde_json::Value>,
22        message_thread_id: Option<i64>,
23        business_connection_id: Option<&str>,
24        message_effect_id: Option<&str>,
25        allow_paid_broadcast: Option<bool>,
26    ) -> Result<message::Message> {
27        let mut params = vec![
28            RequestParameter::new("chat_id", serde_json::to_value(chat_id)?),
29            RequestParameter::new(
30                "game_short_name",
31                serde_json::Value::String(game_short_name.to_owned()),
32            ),
33        ];
34        push_opt(&mut params, "disable_notification", &disable_notification)?;
35        push_opt(&mut params, "protect_content", &protect_content)?;
36        push_opt(&mut params, "reply_parameters", &reply_parameters)?;
37        push_opt(&mut params, "reply_markup", &reply_markup)?;
38        push_opt(&mut params, "message_thread_id", &message_thread_id)?;
39        push_opt_str(
40            &mut params,
41            "business_connection_id",
42            business_connection_id,
43        );
44        push_opt_str(&mut params, "message_effect_id", message_effect_id);
45        push_opt(&mut params, "allow_paid_broadcast", &allow_paid_broadcast)?;
46        self.do_post("sendGame", params).await
47    }
48
49    /// Use this method to set the score of the specified user in a game message.
50    ///
51    /// Calls the Telegram `setGameScore` API method.
52    pub async fn set_game_score_raw(
53        &self,
54        user_id: i64,
55        score: i64,
56        force: Option<bool>,
57        disable_edit_message: Option<bool>,
58        chat_id: Option<i64>,
59        message_id: Option<i64>,
60        inline_message_id: Option<&str>,
61    ) -> Result<MessageOrBool> {
62        let mut params = vec![
63            RequestParameter::new("user_id", serde_json::to_value(user_id)?),
64            RequestParameter::new("score", serde_json::to_value(score)?),
65        ];
66        push_opt(&mut params, "force", &force)?;
67        push_opt(&mut params, "disable_edit_message", &disable_edit_message)?;
68        push_opt(&mut params, "chat_id", &chat_id)?;
69        push_opt(&mut params, "message_id", &message_id)?;
70        push_opt_str(&mut params, "inline_message_id", inline_message_id);
71        self.do_post("setGameScore", params).await
72    }
73
74    /// Use this method to get data for high score tables.
75    ///
76    /// Calls the Telegram `getGameHighScores` API method.
77    pub async fn get_game_high_scores_raw(
78        &self,
79        user_id: i64,
80        chat_id: Option<i64>,
81        message_id: Option<i64>,
82        inline_message_id: Option<&str>,
83    ) -> Result<Vec<games::game_high_score::GameHighScore>> {
84        let mut params = vec![RequestParameter::new(
85            "user_id",
86            serde_json::to_value(user_id)?,
87        )];
88        push_opt(&mut params, "chat_id", &chat_id)?;
89        push_opt(&mut params, "message_id", &message_id)?;
90        push_opt_str(&mut params, "inline_message_id", inline_message_id);
91        self.do_post("getGameHighScores", params).await
92    }
93}