feat: set bot commands
This commit is contained in:
parent
c2735ccf25
commit
e53405a060
1 changed files with 27 additions and 1 deletions
28
src/main.rs
28
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
|
||||
|
|
Loading…
Add table
Reference in a new issue