use crate::Client;
use crate::errors::Result;
use crate::methods::accepted;
use crate::raw::{base, functions};
use crate::types::{BotCommand, BotCommandScope};
#[must_use = "a request does nothing until it is awaited"]
pub struct SetBotCommands<'a> {
client: &'a Client,
commands: Vec<base::BotCommand>,
scope: BotCommandScope,
language_code: String,
}
impl Client {
pub fn set_bot_commands(&self, commands: impl IntoIterator<Item = BotCommand>) -> SetBotCommands<'_> {
SetBotCommands {
client: self,
commands: commands.into_iter().map(BotCommand::write).collect(),
scope: BotCommandScope::Default,
language_code: String::new(),
}
}
}
impl SetBotCommands<'_> {
pub fn scope(mut self, scope: BotCommandScope) -> Self {
self.scope = scope;
self
}
pub fn language_code(mut self, language_code: impl Into<String>) -> Self {
self.language_code = language_code.into();
self
}
async fn send(self) -> Result<()> {
let request = functions::bots::SetBotCommands {
scope: self.scope.write(self.client).await?,
lang_code: self.language_code,
commands: self.commands,
};
accepted(self.client.invoke(&request).await?)
}
}
into_future!(SetBotCommands, ());