From e53405a060c0c6be8c056a6d0ce89752b3eba30b Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Wed, 27 Nov 2024 18:28:34 +0400 Subject: [PATCH] feat: set bot commands --- src/main.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index cac576e..9c63eb1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,14 @@ const POLL_TYPES: &str = r#"["message"]"#; async fn main() -> std::io::Result<()> { let cfg = { let token = std::env::var("BOT_TOKEN").expect("invalid BOT_TOKEN env var value"); + let client = Client::new(); + + init_cmds(&client, &token) + .await + .expect("could not make request to API"); + Config { - client: Client::new(), + client, upd_url: Url::parse(&format!("{BOT_URL}{token}/getUpdates")) .unwrap() .into(), @@ -57,6 +63,26 @@ async fn main() -> std::io::Result<()> { Ok(()) } +async fn init_cmds(client: &Client, token: &str) -> Result<(), reqwest::Error> { + client + .get(format!("{BOT_URL}{token}/setMyCommands")) + .query(&[( + "commands", + serde_json::json!([ + { + "command": COMMAND[1..], // cmd name without leading slash + "description": "Get XKCD comic by id", + } + ]) + .to_string(), + )]) + .send() + .await? + .error_for_status()?; + + Ok(()) +} + async fn handler(cfg: &Config, s: &mut State) -> Result<(), reqwest::Error> { let mut updates = cfg .client