ferrisgram/methods/
set_my_commands.rs#![allow(clippy::too_many_arguments)]
use serde::Serialize;
use crate::error::Result;
use crate::types::{BotCommand, BotCommandScope};
use crate::Bot;
impl Bot {
pub fn set_my_commands(&self, commands: Vec<BotCommand>) -> SetMyCommandsBuilder {
SetMyCommandsBuilder::new(self, commands)
}
}
#[derive(Serialize)]
pub struct SetMyCommandsBuilder<'a> {
#[serde(skip)]
bot: &'a Bot,
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>,
}
impl<'a> SetMyCommandsBuilder<'a> {
pub fn new(bot: &'a Bot, commands: Vec<BotCommand>) -> Self {
Self {
bot,
commands,
scope: None,
language_code: None,
}
}
pub fn commands(mut self, commands: Vec<BotCommand>) -> Self {
self.commands = commands;
self
}
pub fn scope(mut self, scope: BotCommandScope) -> Self {
self.scope = Some(scope);
self
}
pub fn language_code(mut self, language_code: String) -> Self {
self.language_code = Some(language_code);
self
}
pub async fn send(self) -> Result<bool> {
let form = serde_json::to_value(&self)?;
self.bot.get::<bool>("setMyCommands", Some(&form)).await
}
}