use mobot_derive::BotRequest;
use serde::{Deserialize, Serialize};
use super::API;
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct BotCommand {
pub command: String,
pub description: String,
}
#[derive(Debug, Serialize, Clone, BotRequest)]
pub enum BotCommnandScopeType {
#[serde(rename = "default")]
Default,
#[serde(rename = "all_private_chats")]
AllPrivateChats,
#[serde(rename = "all_group_chats")]
AllGroupChats,
#[serde(rename = "all_chat_administrators")]
AllChatAdministrators,
#[serde(rename = "chat")]
Chat,
#[serde(rename = "chat_administrators")]
ChatAdministrators,
#[serde(rename = "chat_member")]
ChatMember,
}
#[derive(Debug, Serialize, Clone, BotRequest)]
pub struct BotCommandScope {
#[serde(rename = "type")]
pub type_: BotCommnandScopeType,
#[serde(skip_serializing_if = "Option::is_none")]
pub chat_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_id: Option<i64>,
}
#[derive(Default, Debug, Serialize, Clone, BotRequest)]
pub struct SetMyCommandsRequest {
pub commands: Vec<BotCommand>,
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
}
#[derive(Debug, Serialize, Clone, BotRequest)]
pub struct DeleteMyCommandsRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub scope: Option<BotCommandScope>,
#[serde(skip_serializing_if = "Option::is_none")]
pub language_code: Option<String>,
}
type GetMyCommandsRequest = DeleteMyCommandsRequest;
impl API {
pub async fn get_my_commands(
&self,
req: &GetMyCommandsRequest,
) -> anyhow::Result<Vec<BotCommand>> {
self.client.post("getMyCommands", req).await
}
pub async fn set_my_commands(&self, req: &SetMyCommandsRequest) -> anyhow::Result<bool> {
self.client.post("setMyCommands", req).await
}
pub async fn delete_my_commands(&self, req: &DeleteMyCommandsRequest) -> anyhow::Result<bool> {
self.client.post("deleteMyCommands", req).await
}
}