runbot 0.1.3

QQ client framework
Documentation
use std::time::Duration;

use crate::error::Result;
use crate::prelude::BotContext;
use crate::prelude::EchoAsyncResponse;
use serde_derive::{Deserialize, Serialize};
use serde_json::json;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UploadGroupFile {
    pub file_id: String,
}

pub struct UploadGroupFileWating(EchoAsyncResponse);

impl UploadGroupFileWating {
    pub async fn wait(self, timeout: Duration) -> Result<UploadGroupFile> {
        let response = self.0.data(timeout).await?;
        let data: UploadGroupFile = serde_json::from_value(response)?;
        Ok(data)
    }
}

impl BotContext {
    pub async fn upload_group_file_with(
        &self,
        group_id: i64,
        file: &str,
        name: &str,
        folder_id: impl Into<Option<&str>>,
    ) -> Result<UploadGroupFileWating> {
        let response = self
            .websocket_send(
                "upload_group_file",
                json!({
                    "group_id": group_id,
                    "file": file,
                    "name": name,
                    "folder_id": folder_id.into(),
                }),
            )
            .await?;
        Ok(UploadGroupFileWating(response))
    }
}