From 57a4a068c745d11e03628d97f7ea3eb0dabf9e33 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 29 Jul 2020 16:51:20 +0600 Subject: [PATCH] Add GetMyCommands + Bot::get_my_commands --- src/bot/api.rs | 27 +++++++++++++++-------- src/requests/all/get_my_commands.rs | 33 +++++++++++++++++++++++++++++ src/requests/all/mod.rs | 2 ++ 3 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/requests/all/get_my_commands.rs diff --git a/src/bot/api.rs b/src/bot/api.rs index e94f9d99..4c8180b9 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -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()) + } } diff --git a/src/requests/all/get_my_commands.rs b/src/requests/all/get_my_commands.rs new file mode 100644 index 00000000..586bfa28 --- /dev/null +++ b/src/requests/all/get_my_commands.rs @@ -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; + + async fn send(&self) -> ResponseResult { + net::request_json(self.bot.client(), self.bot.token(), "getMyCommands", &self).await + } +} + +impl GetMyCommands { + pub(crate) fn new(bot: Bot) -> Self { + Self { bot } + } +} diff --git a/src/requests/all/mod.rs b/src/requests/all/mod.rs index d92a079f..038531a3 100644 --- a/src/requests/all/mod.rs +++ b/src/requests/all/mod.rs @@ -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::*;