Use ChatOrInlineMessage

This commit is contained in:
Temirkhan Myrzamadi 2020-01-03 15:40:43 +06:00
parent 4f9820ecd9
commit 08d11a85d4
20 changed files with 153 additions and 1014 deletions

View file

@ -4,13 +4,10 @@ use crate::{
AnswerPreCheckoutQuery, AnswerShippingQuery, CreateNewStickerSet, AnswerPreCheckoutQuery, AnswerShippingQuery, CreateNewStickerSet,
DeleteChatPhoto, DeleteChatStickerSet, DeleteMessage, DeleteChatPhoto, DeleteChatStickerSet, DeleteMessage,
DeleteStickerFromSet, DeleteWebhook, EditMessageCaption, DeleteStickerFromSet, DeleteWebhook, EditMessageCaption,
EditMessageCaptionInline, EditMessageLiveLocation, EditMessageLiveLocation, EditMessageMedia, EditMessageReplyMarkup,
EditMessageLiveLocationInline, EditMessageMedia, EditMessageText, ExportChatInviteLink, ForwardMessage, GetChat,
EditMessageMediaInline, EditMessageReplyMarkup, GetChatAdministrators, GetChatMember, GetChatMembersCount, GetFile,
EditMessageReplyMarkupInline, EditMessageText, EditMessageTextInline, GetGameHighScores, GetMe, GetStickerSet, GetUpdates,
ExportChatInviteLink, ForwardMessage, GetChat, GetChatAdministrators,
GetChatMember, GetChatMembersCount, GetFile, GetGameHighScores,
GetGameHighScoresInline, GetMe, GetStickerSet, GetUpdates,
GetUserProfilePhotos, GetWebhookInfo, KickChatMember, LeaveChat, GetUserProfilePhotos, GetWebhookInfo, KickChatMember, LeaveChat,
PinChatMessage, PromoteChatMember, RestrictChatMember, SendAnimation, PinChatMessage, PromoteChatMember, RestrictChatMember, SendAnimation,
SendAudio, SendChatAction, SendChatActionKind, SendContact, SendAudio, SendChatAction, SendChatActionKind, SendContact,
@ -18,14 +15,13 @@ use crate::{
SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue, SendVideo, SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue, SendVideo,
SendVideoNote, SendVoice, SetChatAdministratorCustomTitle, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle,
SetChatDescription, SetChatPermissions, SetChatPhoto, SetChatDescription, SetChatPermissions, SetChatPhoto,
SetChatStickerSet, SetChatTitle, SetGameScore, SetGameScoreInline, SetChatStickerSet, SetChatTitle, SetGameScore, SetStickerPositionInSet,
SetStickerPositionInSet, SetWebhook, StopMessageLiveLocation, SetWebhook, StopMessageLiveLocation, StopPoll, UnbanChatMember,
StopMessageLiveLocationInline, StopPoll, UnbanChatMember,
UnpinChatMessage, UploadStickerFile, UnpinChatMessage, UploadStickerFile,
}, },
types::{ types::{
ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, ChatId, ChatOrInlineMessage, ChatPermissions, InlineQueryResult,
LabeledPrice, InputFile, InputMedia, LabeledPrice,
}, },
Bot, Bot,
}; };
@ -156,57 +152,25 @@ impl Bot {
SendLocation::new(self, chat_id, latitude, longitude) SendLocation::new(self, chat_id, latitude, longitude)
} }
pub fn edit_message_live_location_inline<I>( pub fn edit_message_live_location(
&self, &self,
inline_message_id: I, chat_or_inline_message: ChatOrInlineMessage,
latitude: f32, latitude: f32,
longitude: f32, longitude: f32,
) -> EditMessageLiveLocationInline ) -> EditMessageLiveLocation {
where EditMessageLiveLocation::new(
I: Into<String>,
{
EditMessageLiveLocationInline::new(
self, self,
inline_message_id, chat_or_inline_message,
latitude, latitude,
longitude, longitude,
) )
} }
pub fn edit_message_live_location<C>( pub fn stop_message_live_location(
&self, &self,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32, ) -> StopMessageLiveLocation {
latitude: f32, StopMessageLiveLocation::new(self, chat_or_inline_message)
longitude: f32,
) -> EditMessageLiveLocation
where
C: Into<ChatId>,
{
EditMessageLiveLocation::new(
self, chat_id, message_id, latitude, longitude,
)
}
pub fn stop_message_live_location_inline<I>(
&self,
inline_message_id: I,
) -> StopMessageLiveLocationInline
where
I: Into<String>,
{
StopMessageLiveLocationInline::new(self, inline_message_id)
}
pub fn stop_message_live_location<C>(
&self,
chat_id: C,
message_id: i32,
) -> StopMessageLiveLocation
where
C: Into<ChatId>,
{
StopMessageLiveLocation::new(self, chat_id, message_id)
} }
pub fn send_venue<C, T, A>( pub fn send_venue<C, T, A>(
@ -459,94 +423,37 @@ impl Bot {
AnswerCallbackQuery::new(self, callback_query_id) AnswerCallbackQuery::new(self, callback_query_id)
} }
pub fn edit_message_text_inline<I, T>( pub fn edit_message_text<T>(
&self, &self,
inline_message_id: I, chat_or_inline_message: ChatOrInlineMessage,
text: T,
) -> EditMessageTextInline
where
I: Into<String>,
T: Into<String>,
{
EditMessageTextInline::new(self, inline_message_id, text)
}
pub fn edit_message_text<C, T>(
&self,
chat_id: C,
message_id: i32,
text: T, text: T,
) -> EditMessageText ) -> EditMessageText
where where
C: Into<ChatId>,
T: Into<String>, T: Into<String>,
{ {
EditMessageText::new(self, chat_id, message_id, text) EditMessageText::new(self, chat_or_inline_message, text)
} }
pub fn edit_message_caption_inline<I>( pub fn edit_message_caption(
&self, &self,
inline_message_id: I, chat_or_inline_message: ChatOrInlineMessage,
) -> EditMessageCaptionInline ) -> EditMessageCaption {
where EditMessageCaption::new(self, chat_or_inline_message)
I: Into<String>,
{
EditMessageCaptionInline::new(self, inline_message_id)
} }
pub fn edit_message_caption<C>( pub fn edit_message_media(
&self, &self,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
) -> EditMessageCaption
where
C: Into<ChatId>,
{
EditMessageCaption::new(self, chat_id, message_id)
}
pub fn edit_message_media_inline<I>(
&self,
inline_message_id: I,
media: InputMedia, media: InputMedia,
) -> EditMessageMediaInline ) -> EditMessageMedia {
where EditMessageMedia::new(self, chat_or_inline_message, media)
I: Into<String>,
{
EditMessageMediaInline::new(self, inline_message_id, media)
} }
pub fn edit_message_media<C>( pub fn edit_message_reply_markup(
&self, &self,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32, ) -> EditMessageReplyMarkup {
media: InputMedia, EditMessageReplyMarkup::new(self, chat_or_inline_message)
) -> EditMessageMedia
where
C: Into<ChatId>,
{
EditMessageMedia::new(self, chat_id, message_id, media)
}
pub fn edit_message_reply_markup_inline<I>(
&self,
inline_message_id: I,
) -> EditMessageReplyMarkupInline
where
I: Into<String>,
{
EditMessageReplyMarkupInline::new(self, inline_message_id)
}
pub fn edit_message_reply_markup<C>(
&self,
chat_id: C,
message_id: i32,
) -> EditMessageReplyMarkup
where
C: Into<ChatId>,
{
EditMessageReplyMarkup::new(self, chat_id, message_id)
} }
pub fn stop_poll<C>(&self, chat_id: C, message_id: i32) -> StopPoll pub fn stop_poll<C>(&self, chat_id: C, message_id: i32) -> StopPoll
@ -719,52 +626,21 @@ impl Bot {
SendGame::new(self, chat_id, game_short_name) SendGame::new(self, chat_id, game_short_name)
} }
pub fn set_game_score_inline<I>( pub fn set_game_score(
&self, &self,
inline_message_id: I, chat_or_inline_message: ChatOrInlineMessage,
user_id: i32, user_id: i32,
score: i32, score: i32,
) -> SetGameScoreInline ) -> SetGameScore {
where SetGameScore::new(self, chat_or_inline_message, user_id, score)
I: Into<String>,
{
SetGameScoreInline::new(self, inline_message_id, user_id, score)
} }
pub fn set_game_score<C>( pub fn get_game_high_scores(
&self, &self,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
user_id: i32, user_id: i32,
score: i32, ) -> GetGameHighScores {
) -> SetGameScore GetGameHighScores::new(self, chat_or_inline_message, user_id)
where
C: Into<ChatId>,
{
SetGameScore::new(self, chat_id, message_id, user_id, score)
}
pub fn get_game_high_scores_inline<I>(
&self,
inline_message_id: I,
user_id: i32,
) -> GetGameHighScoresInline
where
I: Into<String>,
{
GetGameHighScoresInline::new(self, inline_message_id, user_id)
}
pub fn get_game_high_scores<C>(
&self,
chat_id: C,
message_id: i32,
user_id: i32,
) -> GetGameHighScores
where
C: Into<ChatId>,
{
GetGameHighScores::new(self, chat_id, message_id, user_id)
} }
pub fn set_chat_administrator_custom_title<C, CT>( pub fn set_chat_administrator_custom_title<C, CT>(

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message, ParseMode}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
Bot, Bot,
}; };
@ -16,11 +16,9 @@ pub struct EditMessageCaption<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel #[serde(flatten)]
/// (in the format @channelusername) chat_or_inline_message: ChatOrInlineMessage,
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
/// New caption of the message /// New caption of the message
caption: Option<String>, caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
@ -44,31 +42,21 @@ impl Request<Message> for EditMessageCaption<'_> {
} }
impl<'a> EditMessageCaption<'a> { impl<'a> EditMessageCaption<'a> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self pub(crate) fn new(
where bot: &'a Bot,
C: Into<ChatId>, chat_or_inline_message: ChatOrInlineMessage,
{ ) -> Self {
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
caption: None, caption: None,
parse_mode: None, parse_mode: None,
reply_markup: None, reply_markup: None,
} }
} }
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,83 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, Message, ParseMode},
Bot,
};
/// Use this method to edit captions of messages. On success, if edited message
/// is sent by the bot, the edited Message is returned, otherwise True is
/// returned.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct EditMessageCaptionInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// New caption of the message
caption: Option<String>,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in the media caption.
parse_mode: Option<ParseMode>,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageCaptionInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),
self.bot.token(),
"editMessageCaption",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> EditMessageCaptionInline<'a> {
pub(crate) fn new<I>(bot: &'a Bot, inline_message_id: I) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
caption: None,
parse_mode: None,
reply_markup: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn caption<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
@ -17,11 +17,9 @@ pub struct EditMessageLiveLocation<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel #[serde(flatten)]
/// (in the format @channelusername) chat_or_inline_message: ChatOrInlineMessage,
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
/// Latitude of new location /// Latitude of new location
latitude: f32, latitude: f32,
/// Longitude of new location /// Longitude of new location
@ -44,37 +42,23 @@ impl Request<Message> for EditMessageLiveLocation<'_> {
} }
impl<'a> EditMessageLiveLocation<'a> { impl<'a> EditMessageLiveLocation<'a> {
pub(crate) fn new<C>( pub(crate) fn new(
bot: &'a Bot, bot: &'a Bot,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
latitude: f32, latitude: f32,
longitude: f32, longitude: f32,
) -> Self ) -> Self {
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
latitude, latitude,
longitude, longitude,
reply_markup: None, reply_markup: None,
} }
} }
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,85 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, Message},
Bot,
};
/// Use this method to edit live location messages. A location can be edited
/// until its live_period expires or editing is explicitly disabled by a call to
/// stopMessageLiveLocation. On success, if the edited message was sent by the
/// bot, the edited Message is returned, otherwise True is returned.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct EditMessageLiveLocationInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// Latitude of new location
latitude: f32,
/// Longitude of new location
longitude: f32,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageLiveLocationInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),
self.bot.token(),
"editMessageLiveLocation",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> EditMessageLiveLocationInline<'a> {
pub(crate) fn new<I>(
bot: &'a Bot,
inline_message_id: I,
latitude: f32,
longitude: f32,
) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
latitude,
longitude,
reply_markup: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn latitude(mut self, val: f32) -> Self {
self.latitude = val;
self
}
pub fn longitude(mut self, val: f32) -> Self {
self.longitude = val;
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{form_builder::FormBuilder, Request, ResponseResult}, requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, InputMedia, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message},
Bot, Bot,
}; };
@ -20,11 +20,9 @@ pub struct EditMessageMedia<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel #[serde(flatten)]
/// (in the format @channelusername) chat_or_inline_message: ChatOrInlineMessage,
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
/// A JSON-serialized object for a new media content of the message /// A JSON-serialized object for a new media content of the message
media: InputMedia, media: InputMedia,
/// A JSON-serialized object for a new inline keyboard. /// A JSON-serialized object for a new inline keyboard.
@ -34,13 +32,27 @@ pub struct EditMessageMedia<'a> {
#[async_trait::async_trait] #[async_trait::async_trait]
impl Request<Message> for EditMessageMedia<'_> { impl Request<Message> for EditMessageMedia<'_> {
async fn send(&self) -> ResponseResult<Message> { async fn send(&self) -> ResponseResult<Message> {
let mut params = FormBuilder::new();
match &self.chat_or_inline_message {
ChatOrInlineMessage::Chat {
chat_id,
message_id,
} => {
params = params
.add("chat_id", chat_id)
.add("message_id", message_id);
}
ChatOrInlineMessage::Inline { inline_message_id } => {
params = params.add("inline_message_id", inline_message_id);
}
}
network::request_multipart( network::request_multipart(
self.bot.client(), self.bot.client(),
self.bot.token(), self.bot.token(),
"editMessageMedia", "editMessageMedia",
FormBuilder::new() params
.add("chat_id", &self.chat_id)
.add("message_id", &self.message_id)
.add("media", &self.media) .add("media", &self.media)
.add("reply_markup", &self.reply_markup) .add("reply_markup", &self.reply_markup)
.build(), .build(),
@ -50,35 +62,21 @@ impl Request<Message> for EditMessageMedia<'_> {
} }
impl<'a> EditMessageMedia<'a> { impl<'a> EditMessageMedia<'a> {
pub(crate) fn new<C>( pub(crate) fn new(
bot: &'a Bot, bot: &'a Bot,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
media: InputMedia, media: InputMedia,
) -> Self ) -> Self {
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
media, media,
reply_markup: None, reply_markup: None,
} }
} }
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,83 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{InlineKeyboardMarkup, InputMedia, Message},
Bot,
};
/// Use this method to edit animation, audio, document, photo, or video
/// messages. If a message is a part of a message album, then it can be edited
/// only to a photo or a video. Otherwise, message type can be changed
/// arbitrarily. When inline message is edited, new file can't be uploaded. Use
/// previously uploaded file via its file_id or specify a URL. On success, if
/// the edited message was sent by the bot, the edited Message is returned,
/// otherwise True is returned.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct EditMessageMediaInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// A JSON-serialized object for a new media content of the message
media: InputMedia,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageMediaInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),
self.bot.token(),
"editMessageMedia",
FormBuilder::new()
.add("inline_message_id", &self.inline_message_id)
.add("media", &self.media)
.add("reply_markup", &self.reply_markup)
.build(),
)
.await
}
}
impl<'a> EditMessageMediaInline<'a> {
pub(crate) fn new<I>(
bot: &'a Bot,
inline_message_id: I,
media: InputMedia,
) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
media,
reply_markup: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn media(mut self, val: InputMedia) -> Self {
self.media = val;
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
@ -16,11 +16,9 @@ pub struct EditMessageReplyMarkup<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel #[serde(flatten)]
/// (in the format @channelusername) chat_or_inline_message: ChatOrInlineMessage,
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
/// A JSON-serialized object for an inline keyboard. /// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -39,29 +37,19 @@ impl Request<Message> for EditMessageReplyMarkup<'_> {
} }
impl<'a> EditMessageReplyMarkup<'a> { impl<'a> EditMessageReplyMarkup<'a> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self pub(crate) fn new(
where bot: &'a Bot,
C: Into<ChatId>, chat_or_inline_message: ChatOrInlineMessage,
{ ) -> Self {
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
reply_markup: None, reply_markup: None,
} }
} }
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,63 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, Message},
Bot,
};
/// Use this method to edit only the reply markup of messages. On success, if
/// edited message is sent by the bot, the edited Message is returned, otherwise
/// True is returned.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct EditMessageReplyMarkupInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageReplyMarkupInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),
self.bot.token(),
"editMessageReplyMarkup",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> EditMessageReplyMarkupInline<'a> {
pub(crate) fn new<I>(bot: &'a Bot, inline_message_id: I) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
reply_markup: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message, ParseMode}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
Bot, Bot,
}; };
@ -16,11 +16,9 @@ pub struct EditMessageText<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel #[serde(flatten)]
/// (in the format @channelusername) chat_or_inline_message: ChatOrInlineMessage,
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
/// New text of the message /// New text of the message
text: String, text: String,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic, /// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
@ -46,39 +44,26 @@ impl Request<Message> for EditMessageText<'_> {
} }
impl<'a> EditMessageText<'a> { impl<'a> EditMessageText<'a> {
pub(crate) fn new<C, T>( pub(crate) fn new<T>(
bot: &'a Bot, bot: &'a Bot,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
text: T, text: T,
) -> Self ) -> Self
where where
C: Into<ChatId>,
T: Into<String>, T: Into<String>,
{ {
let chat_id = chat_id.into();
let text = text.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id, text: text.into(),
text,
parse_mode: None, parse_mode: None,
disable_web_page_preview: None, disable_web_page_preview: None,
reply_markup: None, reply_markup: None,
} }
} }
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,93 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, Message, ParseMode},
Bot,
};
/// Use this method to edit text and game messages. On success, if edited
/// message is sent by the bot, the edited Message is returned, otherwise True
/// is returned.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct EditMessageTextInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// New text of the message
text: String,
/// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
/// fixed-width text or inline URLs in your bot's message.
parse_mode: Option<ParseMode>,
/// Disables link previews for links in this message
disable_web_page_preview: Option<bool>,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageTextInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),
self.bot.token(),
"editMessageText",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> EditMessageTextInline<'a> {
pub(crate) fn new<I, T>(bot: &'a Bot, inline_message_id: I, text: T) -> Self
where
I: Into<String>,
T: Into<String>,
{
let inline_message_id = inline_message_id.into();
let text = text.into();
Self {
bot,
inline_message_id,
text,
parse_mode: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn text<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.text = val.into();
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
self.disable_web_page_preview = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, GameHighScore}, types::{ChatOrInlineMessage, GameHighScore},
Bot, Bot,
}; };
@ -19,12 +19,11 @@ pub struct GetGameHighScores<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// Target user id /// Target user id
user_id: i32, user_id: i32,
/// Unique identifier for the target chat
chat_id: ChatId,
/// Identifier of the sent message
message_id: i32,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
@ -41,34 +40,20 @@ impl Request<Vec<GameHighScore>> for GetGameHighScores<'_> {
} }
impl<'a> GetGameHighScores<'a> { impl<'a> GetGameHighScores<'a> {
pub(crate) fn new<C>( pub(crate) fn new(
bot: &'a Bot, bot: &'a Bot,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
user_id: i32, user_id: i32,
) -> Self ) -> Self {
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
user_id, user_id,
} }
} }
pub fn chat_id<C>(mut self, val: C) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
C: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,70 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::GameHighScore,
Bot,
};
/// Use this method to get data for high score tables. Will return the score of
/// the specified user and several of his neighbors in a game. On success,
/// returns an Array of GameHighScore objects.This method will currently return
/// scores for the target user, plus two of his closest neighbors on each side.
/// Will also return the top three users if the user and his neighbors are not
/// among them. Please note that this behavior is subject to change.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct GetGameHighScoresInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// Target user id
user_id: i32,
}
#[async_trait::async_trait]
impl Request<Vec<GameHighScore>> for GetGameHighScoresInline<'_> {
async fn send(&self) -> ResponseResult<Vec<GameHighScore>> {
network::request_json(
self.bot.client(),
self.bot.token(),
"getGameHighScores",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> GetGameHighScoresInline<'a> {
pub(crate) fn new<I>(
bot: &'a Bot,
inline_message_id: I,
user_id: i32,
) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
user_id,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
}

View file

@ -10,15 +10,10 @@ mod delete_message;
mod delete_sticker_from_set; mod delete_sticker_from_set;
mod delete_webhook; mod delete_webhook;
mod edit_message_caption; mod edit_message_caption;
mod edit_message_caption_inline;
mod edit_message_live_location; mod edit_message_live_location;
mod edit_message_live_location_inline;
mod edit_message_media; mod edit_message_media;
mod edit_message_media_inline;
mod edit_message_reply_markup; mod edit_message_reply_markup;
mod edit_message_reply_markup_inline;
mod edit_message_text; mod edit_message_text;
mod edit_message_text_inline;
mod export_chat_invite_link; mod export_chat_invite_link;
mod forward_message; mod forward_message;
mod get_chat; mod get_chat;
@ -27,7 +22,6 @@ mod get_chat_member;
mod get_chat_members_count; mod get_chat_members_count;
mod get_file; mod get_file;
mod get_game_high_scores; mod get_game_high_scores;
mod get_game_high_scores_inline;
mod get_me; mod get_me;
mod get_sticker_set; mod get_sticker_set;
mod get_updates; mod get_updates;
@ -62,11 +56,9 @@ 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_game_score_inline;
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;
mod stop_message_live_location_inline;
mod stop_poll; mod stop_poll;
mod unban_chat_member; mod unban_chat_member;
mod unpin_chat_message; mod unpin_chat_message;
@ -84,15 +76,10 @@ pub use delete_message::*;
pub use delete_sticker_from_set::*; pub use delete_sticker_from_set::*;
pub use delete_webhook::*; pub use delete_webhook::*;
pub use edit_message_caption::*; pub use edit_message_caption::*;
pub use edit_message_caption_inline::*;
pub use edit_message_live_location::*; pub use edit_message_live_location::*;
pub use edit_message_live_location_inline::*;
pub use edit_message_media::*; pub use edit_message_media::*;
pub use edit_message_media_inline::*;
pub use edit_message_reply_markup::*; pub use edit_message_reply_markup::*;
pub use edit_message_reply_markup_inline::*;
pub use edit_message_text::*; pub use edit_message_text::*;
pub use edit_message_text_inline::*;
pub use export_chat_invite_link::*; pub use export_chat_invite_link::*;
pub use forward_message::*; pub use forward_message::*;
pub use get_chat::*; pub use get_chat::*;
@ -101,7 +88,6 @@ pub use get_chat_member::*;
pub use get_chat_members_count::*; pub use get_chat_members_count::*;
pub use get_file::*; pub use get_file::*;
pub use get_game_high_scores::*; pub use get_game_high_scores::*;
pub use get_game_high_scores_inline::*;
pub use get_me::*; pub use get_me::*;
pub use get_sticker_set::*; pub use get_sticker_set::*;
pub use get_updates::*; pub use get_updates::*;
@ -136,12 +122,10 @@ 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_game_score_inline::*;
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;
pub use stop_message_live_location::*; pub use stop_message_live_location::*;
pub use stop_message_live_location_inline::*;
pub use stop_poll::*; pub use stop_poll::*;
pub use unban_chat_member::*; pub use unban_chat_member::*;
pub use unpin_chat_message::*; pub use unpin_chat_message::*;

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, Message}, types::{ChatOrInlineMessage, Message},
Bot, Bot,
}; };
@ -17,10 +17,9 @@ pub struct SetGameScore<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat #[serde(flatten)]
chat_id: ChatId, chat_or_inline_message: ChatOrInlineMessage,
/// Identifier of the sent message
message_id: i32,
/// User identifier /// User identifier
user_id: i32, user_id: i32,
/// New score, must be non-negative /// New score, must be non-negative
@ -47,21 +46,15 @@ impl Request<Message> for SetGameScore<'_> {
} }
impl<'a> SetGameScore<'a> { impl<'a> SetGameScore<'a> {
pub(crate) fn new<C>( pub(crate) fn new(
bot: &'a Bot, bot: &'a Bot,
chat_id: C, chat_or_inline_message: ChatOrInlineMessage,
message_id: i32,
user_id: i32, user_id: i32,
score: i32, score: i32,
) -> Self ) -> Self {
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
user_id, user_id,
score, score,
force: None, force: None,
@ -69,16 +62,8 @@ impl<'a> SetGameScore<'a> {
} }
} }
pub fn chat_id<C>(mut self, val: C) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
C: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,95 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::Message,
Bot,
};
/// Use this method to set the score of the specified user in a game. On
/// success, if the message was sent by the bot, returns the edited Message,
/// otherwise returns True. Returns an error, if the new score is not greater
/// than the user's current score in the chat and force is False.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct SetGameScoreInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// User identifier
user_id: i32,
/// New score, must be non-negative
score: i32,
/// Pass True, if the high score is allowed to decrease. This can be useful
/// when fixing mistakes or banning cheaters
force: Option<bool>,
/// Pass True, if the game message should not be automatically edited to
/// include the current scoreboard
disable_edit_message: Option<bool>,
}
#[async_trait::async_trait]
impl Request<Message> for SetGameScoreInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),
self.bot.token(),
"setGameScore",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> SetGameScoreInline<'a> {
pub(crate) fn new<I>(
bot: &'a Bot,
inline_message_id: I,
user_id: i32,
score: i32,
) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
user_id,
score,
force: None,
disable_edit_message: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = val;
self
}
pub fn score(mut self, val: i32) -> Self {
self.score = val;
self
}
pub fn force(mut self, val: bool) -> Self {
self.force = Some(val);
self
}
pub fn disable_edit_message(mut self, val: bool) -> Self {
self.disable_edit_message = Some(val);
self
}
}

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{ use crate::{
network, network,
requests::{Request, ResponseResult}, requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot, Bot,
}; };
@ -16,11 +16,9 @@ pub struct StopMessageLiveLocation<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
bot: &'a Bot, bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel #[serde(flatten)]
/// (in the format @channelusername) chat_or_inline_message: ChatOrInlineMessage,
chat_id: ChatId,
/// Identifier of the message with live location to stop
message_id: i32,
/// A JSON-serialized object for a new inline keyboard. /// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>, reply_markup: Option<InlineKeyboardMarkup>,
} }
@ -39,29 +37,19 @@ impl Request<Message> for StopMessageLiveLocation<'_> {
} }
impl<'a> StopMessageLiveLocation<'a> { impl<'a> StopMessageLiveLocation<'a> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self pub(crate) fn new(
where bot: &'a Bot,
C: Into<ChatId>, chat_or_inline_message: ChatOrInlineMessage,
{ ) -> Self {
let chat_id = chat_id.into();
Self { Self {
bot, bot,
chat_id, chat_or_inline_message,
message_id,
reply_markup: None, reply_markup: None,
} }
} }
pub fn chat_id<T>(mut self, val: T) -> Self pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
where self.chat_or_inline_message = val;
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self self
} }

View file

@ -1,63 +0,0 @@
use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{InlineKeyboardMarkup, Message},
Bot,
};
/// Use this method to stop updating a live location message before live_period
/// expires. On success, if the message was sent by the bot, the sent Message is
/// returned, otherwise True is returned.
#[serde_with_macros::skip_serializing_none]
#[derive(Debug, Clone, Serialize)]
pub struct StopMessageLiveLocationInline<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Identifier of the inline message
inline_message_id: String,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
#[async_trait::async_trait]
impl Request<Message> for StopMessageLiveLocationInline<'_> {
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),
self.bot.token(),
"stopMessageLiveLocation",
&serde_json::to_string(self).unwrap(),
)
.await
}
}
impl<'a> StopMessageLiveLocationInline<'a> {
pub(crate) fn new<I>(bot: &'a Bot, inline_message_id: I) -> Self
where
I: Into<String>,
{
let inline_message_id = inline_message_id.into();
Self {
bot,
inline_message_id,
reply_markup: None,
}
}
pub fn inline_message_id<T>(mut self, val: T) -> Self
where
T: Into<String>,
{
self.inline_message_id = val.into();
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -0,0 +1,11 @@
use crate::types::ChatId;
use serde::{Deserialize, Serialize};
/// A chat message or inline message.
#[derive(Serialize, Deserialize, Clone, Eq, Hash, PartialEq, Debug)]
#[serde(untagged)]
pub enum ChatOrInlineMessage {
Chat { chat_id: ChatId, message_id: i32 },
Inline { inline_message_id: i32 },
}

View file

@ -9,6 +9,7 @@ pub use chat::*;
pub use chat_action::*; pub use chat_action::*;
pub use chat_id::*; pub use chat_id::*;
pub use chat_member::*; pub use chat_member::*;
pub use chat_or_inline_message::*;
pub use chat_permissions::*; pub use chat_permissions::*;
pub use chat_photo::*; pub use chat_photo::*;
pub use chosen_inline_result::*; pub use chosen_inline_result::*;
@ -93,6 +94,7 @@ mod chat;
mod chat_action; mod chat_action;
mod chat_id; mod chat_id;
mod chat_member; mod chat_member;
mod chat_or_inline_message;
mod chat_permissions; mod chat_permissions;
mod chat_photo; mod chat_photo;
mod chosen_inline_result; mod chosen_inline_result;