Add GetMyCommands + Bot::get_my_commands

This commit is contained in:
Temirkhan Myrzamadi 2020-07-29 16:51:20 +06:00
parent 17373a143f
commit 57a4a068c7
3 changed files with 53 additions and 9 deletions

View file

@ -5,15 +5,15 @@ use crate::{
DeleteMessage, DeleteStickerFromSet, DeleteWebhook, EditMessageCaption,
EditMessageLiveLocation, EditMessageMedia, EditMessageReplyMarkup, EditMessageText,
ExportChatInviteLink, ForwardMessage, GetChat, GetChatAdministrators, GetChatMember,
GetChatMembersCount, GetFile, GetGameHighScores, GetMe, GetStickerSet, GetUpdates,
GetUserProfilePhotos, GetWebhookInfo, KickChatMember, LeaveChat, PinChatMessage,
PromoteChatMember, RestrictChatMember, SendAnimation, SendAudio, SendChatAction,
SendChatActionKind, SendContact, SendDice, SendDocument, SendGame, SendInvoice,
SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue,
SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle, SetChatDescription,
SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle, SetGameScore,
SetStickerPositionInSet, SetWebhook, StopMessageLiveLocation, StopPoll, UnbanChatMember,
UnpinChatMessage, UploadStickerFile,
GetChatMembersCount, GetFile, GetGameHighScores, GetMe, GetMyCommands, GetStickerSet,
GetUpdates, GetUserProfilePhotos, GetWebhookInfo, KickChatMember, LeaveChat,
PinChatMessage, PromoteChatMember, RestrictChatMember, SendAnimation, SendAudio,
SendChatAction, SendChatActionKind, SendContact, SendDice, SendDocument, SendGame,
SendInvoice, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll, SendSticker,
SendVenue, SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle,
SetChatDescription, SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle,
SetGameScore, SetStickerPositionInSet, SetWebhook, StopMessageLiveLocation, StopPoll,
UnbanChatMember, UnpinChatMessage, UploadStickerFile,
},
types::{
ChatId, ChatOrInlineMessage, ChatPermissions, InlineQueryResult, InputFile, InputMedia,
@ -1505,6 +1505,8 @@ impl Bot {
/// Use this method to send an animated emoji that will display a random
/// value.
///
/// [The official docs](https://core.telegram.org/bots/api#senddice).
///
/// # Params
/// - `chat_id`: Unique identifier for the target chat or username of the
/// target channel (in the format `@channelusername`).
@ -1514,4 +1516,11 @@ impl Bot {
{
SendDice::new(self.clone(), chat_id)
}
/// Use this method to get the current list of the bot's commands.
///
/// [The official docs](https://core.telegram.org/bots/api#getmycommands).
pub fn get_my_commands(&self) -> GetMyCommands {
GetMyCommands::new(self.clone())
}
}

View file

@ -0,0 +1,33 @@
use serde::Serialize;
use crate::{
net,
requests::{Request, ResponseResult},
types::BotCommand,
Bot,
};
/// Use this method to get the current list of the bot's commands.
///
/// [The official docs](https://core.telegram.org/bots/api#getmycommands).
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct GetMyCommands {
#[serde(skip_serializing)]
bot: Bot,
}
#[async_trait::async_trait]
impl Request for GetMyCommands {
type Output = Vec<BotCommand>;
async fn send(&self) -> ResponseResult<Self::Output> {
net::request_json(self.bot.client(), self.bot.token(), "getMyCommands", &self).await
}
}
impl GetMyCommands {
pub(crate) fn new(bot: Bot) -> Self {
Self { bot }
}
}

View file

@ -23,6 +23,7 @@ mod get_chat_members_count;
mod get_file;
mod get_game_high_scores;
mod get_me;
mod get_my_commands;
mod get_sticker_set;
mod get_updates;
mod get_user_profile_photos;
@ -90,6 +91,7 @@ pub use get_chat_members_count::*;
pub use get_file::*;
pub use get_game_high_scores::*;
pub use get_me::*;
pub use get_my_commands::*;
pub use get_sticker_set::*;
pub use get_updates::*;
pub use get_user_profile_photos::*;