mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-09 19:49:19 +01:00
Add SetMyCommands + Bot::set_my_commands
This commit is contained in:
parent
57a4a068c7
commit
0c6246295b
3 changed files with 70 additions and 4 deletions
|
@ -12,12 +12,12 @@ use crate::{
|
||||||
SendInvoice, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll, SendSticker,
|
SendInvoice, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll, SendSticker,
|
||||||
SendVenue, SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle,
|
SendVenue, SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle,
|
||||||
SetChatDescription, SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle,
|
SetChatDescription, SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle,
|
||||||
SetGameScore, SetStickerPositionInSet, SetWebhook, StopMessageLiveLocation, StopPoll,
|
SetGameScore, SetMyCommands, SetStickerPositionInSet, SetWebhook, StopMessageLiveLocation,
|
||||||
UnbanChatMember, UnpinChatMessage, UploadStickerFile,
|
StopPoll, UnbanChatMember, UnpinChatMessage, UploadStickerFile,
|
||||||
},
|
},
|
||||||
types::{
|
types::{
|
||||||
ChatId, ChatOrInlineMessage, ChatPermissions, InlineQueryResult, InputFile, InputMedia,
|
BotCommand, ChatId, ChatOrInlineMessage, ChatPermissions, InlineQueryResult, InputFile,
|
||||||
LabeledPrice,
|
InputMedia, LabeledPrice,
|
||||||
},
|
},
|
||||||
Bot,
|
Bot,
|
||||||
};
|
};
|
||||||
|
@ -1523,4 +1523,18 @@ impl Bot {
|
||||||
pub fn get_my_commands(&self) -> GetMyCommands {
|
pub fn get_my_commands(&self) -> GetMyCommands {
|
||||||
GetMyCommands::new(self.clone())
|
GetMyCommands::new(self.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use this method to change the list of the bot's commands.
|
||||||
|
///
|
||||||
|
/// [The official docs](https://core.telegram.org/bots/api#setmycommands).
|
||||||
|
///
|
||||||
|
/// # Params
|
||||||
|
/// - `commands`: A JSON-serialized list of bot commands to be set as the
|
||||||
|
/// list of the bot's commands. At most 100 commands can be specified.
|
||||||
|
pub fn set_my_commands<C>(&self, commands: C) -> SetMyCommands
|
||||||
|
where
|
||||||
|
C: Into<Vec<BotCommand>>,
|
||||||
|
{
|
||||||
|
SetMyCommands::new(self.clone(), commands)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ mod set_chat_photo;
|
||||||
mod set_chat_sticker_set;
|
mod set_chat_sticker_set;
|
||||||
mod set_chat_title;
|
mod set_chat_title;
|
||||||
mod set_game_score;
|
mod set_game_score;
|
||||||
|
mod set_my_commands;
|
||||||
mod set_sticker_position_in_set;
|
mod set_sticker_position_in_set;
|
||||||
mod set_webhook;
|
mod set_webhook;
|
||||||
mod stop_message_live_location;
|
mod stop_message_live_location;
|
||||||
|
@ -126,6 +127,7 @@ pub use set_chat_photo::*;
|
||||||
pub use set_chat_sticker_set::*;
|
pub use set_chat_sticker_set::*;
|
||||||
pub use set_chat_title::*;
|
pub use set_chat_title::*;
|
||||||
pub use set_game_score::*;
|
pub use set_game_score::*;
|
||||||
|
pub use set_my_commands::*;
|
||||||
pub use set_sticker_position_in_set::*;
|
pub use set_sticker_position_in_set::*;
|
||||||
pub use set_webhook::*;
|
pub use set_webhook::*;
|
||||||
pub use std::pin::Pin;
|
pub use std::pin::Pin;
|
||||||
|
|
50
src/requests/all/set_my_commands.rs
Normal file
50
src/requests/all/set_my_commands.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
net,
|
||||||
|
requests::{Request, ResponseResult},
|
||||||
|
types::{BotCommand, True},
|
||||||
|
Bot,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Use this method to change the list of the bot's commands.
|
||||||
|
///
|
||||||
|
/// [The official docs](https://core.telegram.org/bots/api#setmycommands).
|
||||||
|
#[serde_with_macros::skip_serializing_none]
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct SetMyCommands {
|
||||||
|
#[serde(skip_serializing)]
|
||||||
|
bot: Bot,
|
||||||
|
|
||||||
|
commands: Vec<BotCommand>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl Request for SetMyCommands {
|
||||||
|
type Output = True;
|
||||||
|
|
||||||
|
async fn send(&self) -> ResponseResult<Self::Output> {
|
||||||
|
net::request_json(self.bot.client(), self.bot.token(), "setMyCommands", &self).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SetMyCommands {
|
||||||
|
pub(crate) fn new<C>(bot: Bot, commands: C) -> Self
|
||||||
|
where
|
||||||
|
C: Into<Vec<BotCommand>>,
|
||||||
|
{
|
||||||
|
Self { bot, commands: commands.into() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A JSON-serialized list of bot commands to be set as the list of the
|
||||||
|
/// bot's commands.
|
||||||
|
///
|
||||||
|
/// At most 100 commands can be specified.
|
||||||
|
pub fn commands<C>(mut self, commands: C) -> Self
|
||||||
|
where
|
||||||
|
C: Into<Vec<BotCommand>>,
|
||||||
|
{
|
||||||
|
self.commands = commands.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue