botcat-capoo 1.0.3

A NapCat based QQ bot implemented in Rust
Documentation
use serde_json::Value;

use crate::{config::AppConfig, error::Error};

pub async fn napcat_request(config: &AppConfig, path: &str, body: &Value) -> Result<Value, Error> {
    let api_url = format!("{}:{}{}", config.napcat.api_url, config.napcat.port, path);
    let client = reqwest::Client::new();
    let res = client
        .post(&api_url)
        .bearer_auth(&config.secret.http_client_token)
        .json(&body)
        .send()
        .await;

    let response = res.map_err(Error::from)?;
    let response = response.error_for_status().map_err(Error::from)?;
    let json = response.json().await.map_err(Error::from)?;
    Ok(json)
}