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,
DeleteChatPhoto, DeleteChatStickerSet, DeleteMessage,
DeleteStickerFromSet, DeleteWebhook, EditMessageCaption,
EditMessageCaptionInline, EditMessageLiveLocation,
EditMessageLiveLocationInline, EditMessageMedia,
EditMessageMediaInline, EditMessageReplyMarkup,
EditMessageReplyMarkupInline, EditMessageText, EditMessageTextInline,
ExportChatInviteLink, ForwardMessage, GetChat, GetChatAdministrators,
GetChatMember, GetChatMembersCount, GetFile, GetGameHighScores,
GetGameHighScoresInline, GetMe, GetStickerSet, GetUpdates,
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,
@ -18,14 +15,13 @@ use crate::{
SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue, SendVideo,
SendVideoNote, SendVoice, SetChatAdministratorCustomTitle,
SetChatDescription, SetChatPermissions, SetChatPhoto,
SetChatStickerSet, SetChatTitle, SetGameScore, SetGameScoreInline,
SetStickerPositionInSet, SetWebhook, StopMessageLiveLocation,
StopMessageLiveLocationInline, StopPoll, UnbanChatMember,
SetChatStickerSet, SetChatTitle, SetGameScore, SetStickerPositionInSet,
SetWebhook, StopMessageLiveLocation, StopPoll, UnbanChatMember,
UnpinChatMessage, UploadStickerFile,
},
types::{
ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia,
LabeledPrice,
ChatId, ChatOrInlineMessage, ChatPermissions, InlineQueryResult,
InputFile, InputMedia, LabeledPrice,
},
Bot,
};
@ -156,57 +152,25 @@ impl Bot {
SendLocation::new(self, chat_id, latitude, longitude)
}
pub fn edit_message_live_location_inline<I>(
pub fn edit_message_live_location(
&self,
inline_message_id: I,
chat_or_inline_message: ChatOrInlineMessage,
latitude: f32,
longitude: f32,
) -> EditMessageLiveLocationInline
where
I: Into<String>,
{
EditMessageLiveLocationInline::new(
) -> EditMessageLiveLocation {
EditMessageLiveLocation::new(
self,
inline_message_id,
chat_or_inline_message,
latitude,
longitude,
)
}
pub fn edit_message_live_location<C>(
pub fn stop_message_live_location(
&self,
chat_id: C,
message_id: i32,
latitude: f32,
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)
chat_or_inline_message: ChatOrInlineMessage,
) -> StopMessageLiveLocation {
StopMessageLiveLocation::new(self, chat_or_inline_message)
}
pub fn send_venue<C, T, A>(
@ -459,94 +423,37 @@ impl Bot {
AnswerCallbackQuery::new(self, callback_query_id)
}
pub fn edit_message_text_inline<I, T>(
pub fn edit_message_text<T>(
&self,
inline_message_id: I,
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,
chat_or_inline_message: ChatOrInlineMessage,
text: T,
) -> EditMessageText
where
C: Into<ChatId>,
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,
inline_message_id: I,
) -> EditMessageCaptionInline
where
I: Into<String>,
{
EditMessageCaptionInline::new(self, inline_message_id)
chat_or_inline_message: ChatOrInlineMessage,
) -> EditMessageCaption {
EditMessageCaption::new(self, chat_or_inline_message)
}
pub fn edit_message_caption<C>(
pub fn edit_message_media(
&self,
chat_id: C,
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,
chat_or_inline_message: ChatOrInlineMessage,
media: InputMedia,
) -> EditMessageMediaInline
where
I: Into<String>,
{
EditMessageMediaInline::new(self, inline_message_id, media)
) -> EditMessageMedia {
EditMessageMedia::new(self, chat_or_inline_message, media)
}
pub fn edit_message_media<C>(
pub fn edit_message_reply_markup(
&self,
chat_id: C,
message_id: i32,
media: InputMedia,
) -> 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)
chat_or_inline_message: ChatOrInlineMessage,
) -> EditMessageReplyMarkup {
EditMessageReplyMarkup::new(self, chat_or_inline_message)
}
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)
}
pub fn set_game_score_inline<I>(
pub fn set_game_score(
&self,
inline_message_id: I,
chat_or_inline_message: ChatOrInlineMessage,
user_id: i32,
score: i32,
) -> SetGameScoreInline
where
I: Into<String>,
{
SetGameScoreInline::new(self, inline_message_id, user_id, score)
) -> SetGameScore {
SetGameScore::new(self, chat_or_inline_message, user_id, score)
}
pub fn set_game_score<C>(
pub fn get_game_high_scores(
&self,
chat_id: C,
message_id: i32,
chat_or_inline_message: ChatOrInlineMessage,
user_id: i32,
score: i32,
) -> SetGameScore
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)
) -> GetGameHighScores {
GetGameHighScores::new(self, chat_or_inline_message, user_id)
}
pub fn set_chat_administrator_custom_title<C, CT>(

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message, ParseMode},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
Bot,
};
@ -16,11 +16,9 @@ pub struct EditMessageCaption<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// New caption of the message
caption: Option<String>,
/// 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> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
pub(crate) fn new(
bot: &'a Bot,
chat_or_inline_message: ChatOrInlineMessage,
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
caption: None,
parse_mode: None,
reply_markup: None,
}
}
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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::{
network,
requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot,
};
@ -17,11 +17,9 @@ pub struct EditMessageLiveLocation<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// Latitude of new location
latitude: f32,
/// Longitude of new location
@ -44,37 +42,23 @@ impl Request<Message> for EditMessageLiveLocation<'_> {
}
impl<'a> EditMessageLiveLocation<'a> {
pub(crate) fn new<C>(
pub(crate) fn new(
bot: &'a Bot,
chat_id: C,
message_id: i32,
chat_or_inline_message: ChatOrInlineMessage,
latitude: f32,
longitude: f32,
) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
latitude,
longitude,
reply_markup: None,
}
}
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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::{
network,
requests::{form_builder::FormBuilder, Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, InputMedia, Message},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message},
Bot,
};
@ -20,11 +20,9 @@ pub struct EditMessageMedia<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for a new media content of the message
media: InputMedia,
/// A JSON-serialized object for a new inline keyboard.
@ -34,13 +32,27 @@ pub struct EditMessageMedia<'a> {
#[async_trait::async_trait]
impl Request<Message> for EditMessageMedia<'_> {
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(
self.bot.client(),
self.bot.token(),
"editMessageMedia",
FormBuilder::new()
.add("chat_id", &self.chat_id)
.add("message_id", &self.message_id)
params
.add("media", &self.media)
.add("reply_markup", &self.reply_markup)
.build(),
@ -50,35 +62,21 @@ impl Request<Message> for EditMessageMedia<'_> {
}
impl<'a> EditMessageMedia<'a> {
pub(crate) fn new<C>(
pub(crate) fn new(
bot: &'a Bot,
chat_id: C,
message_id: i32,
chat_or_inline_message: ChatOrInlineMessage,
media: InputMedia,
) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
media,
reply_markup: None,
}
}
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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::{
network,
requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot,
};
@ -16,11 +16,9 @@ pub struct EditMessageReplyMarkup<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for an inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -39,29 +37,19 @@ impl Request<Message> for EditMessageReplyMarkup<'_> {
}
impl<'a> EditMessageReplyMarkup<'a> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
pub(crate) fn new(
bot: &'a Bot,
chat_or_inline_message: ChatOrInlineMessage,
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
reply_markup: None,
}
}
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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::{
network,
requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message, ParseMode},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode},
Bot,
};
@ -16,11 +16,9 @@ pub struct EditMessageText<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId,
/// Identifier of the message to edit
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// New text of the message
text: String,
/// 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> {
pub(crate) fn new<C, T>(
pub(crate) fn new<T>(
bot: &'a Bot,
chat_id: C,
message_id: i32,
chat_or_inline_message: ChatOrInlineMessage,
text: T,
) -> Self
where
C: Into<ChatId>,
T: Into<String>,
{
let chat_id = chat_id.into();
let text = text.into();
Self {
bot,
chat_id,
message_id,
text,
chat_or_inline_message,
text: text.into(),
parse_mode: None,
disable_web_page_preview: None,
reply_markup: None,
}
}
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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::{
network,
requests::{Request, ResponseResult},
types::{ChatId, GameHighScore},
types::{ChatOrInlineMessage, GameHighScore},
Bot,
};
@ -19,12 +19,11 @@ pub struct GetGameHighScores<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// Target user id
user_id: i32,
/// Unique identifier for the target chat
chat_id: ChatId,
/// Identifier of the sent message
message_id: i32,
}
#[async_trait::async_trait]
@ -41,34 +40,20 @@ impl Request<Vec<GameHighScore>> for GetGameHighScores<'_> {
}
impl<'a> GetGameHighScores<'a> {
pub(crate) fn new<C>(
pub(crate) fn new(
bot: &'a Bot,
chat_id: C,
message_id: i32,
chat_or_inline_message: ChatOrInlineMessage,
user_id: i32,
) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
user_id,
}
}
pub fn chat_id<C>(mut self, val: C) -> Self
where
C: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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_webhook;
mod edit_message_caption;
mod edit_message_caption_inline;
mod edit_message_live_location;
mod edit_message_live_location_inline;
mod edit_message_media;
mod edit_message_media_inline;
mod edit_message_reply_markup;
mod edit_message_reply_markup_inline;
mod edit_message_text;
mod edit_message_text_inline;
mod export_chat_invite_link;
mod forward_message;
mod get_chat;
@ -27,7 +22,6 @@ mod get_chat_member;
mod get_chat_members_count;
mod get_file;
mod get_game_high_scores;
mod get_game_high_scores_inline;
mod get_me;
mod get_sticker_set;
mod get_updates;
@ -62,11 +56,9 @@ mod set_chat_photo;
mod set_chat_sticker_set;
mod set_chat_title;
mod set_game_score;
mod set_game_score_inline;
mod set_sticker_position_in_set;
mod set_webhook;
mod stop_message_live_location;
mod stop_message_live_location_inline;
mod stop_poll;
mod unban_chat_member;
mod unpin_chat_message;
@ -84,15 +76,10 @@ pub use delete_message::*;
pub use delete_sticker_from_set::*;
pub use delete_webhook::*;
pub use edit_message_caption::*;
pub use edit_message_caption_inline::*;
pub use edit_message_live_location::*;
pub use edit_message_live_location_inline::*;
pub use edit_message_media::*;
pub use edit_message_media_inline::*;
pub use edit_message_reply_markup::*;
pub use edit_message_reply_markup_inline::*;
pub use edit_message_text::*;
pub use edit_message_text_inline::*;
pub use export_chat_invite_link::*;
pub use forward_message::*;
pub use get_chat::*;
@ -101,7 +88,6 @@ pub use get_chat_member::*;
pub use get_chat_members_count::*;
pub use get_file::*;
pub use get_game_high_scores::*;
pub use get_game_high_scores_inline::*;
pub use get_me::*;
pub use get_sticker_set::*;
pub use get_updates::*;
@ -136,12 +122,10 @@ pub use set_chat_photo::*;
pub use set_chat_sticker_set::*;
pub use set_chat_title::*;
pub use set_game_score::*;
pub use set_game_score_inline::*;
pub use set_sticker_position_in_set::*;
pub use set_webhook::*;
pub use std::pin::Pin;
pub use stop_message_live_location::*;
pub use stop_message_live_location_inline::*;
pub use stop_poll::*;
pub use unban_chat_member::*;
pub use unpin_chat_message::*;

View file

@ -3,7 +3,7 @@ use serde::Serialize;
use crate::{
network,
requests::{Request, ResponseResult},
types::{ChatId, Message},
types::{ChatOrInlineMessage, Message},
Bot,
};
@ -17,10 +17,9 @@ pub struct SetGameScore<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat
chat_id: ChatId,
/// Identifier of the sent message
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// User identifier
user_id: i32,
/// New score, must be non-negative
@ -47,21 +46,15 @@ impl Request<Message> for SetGameScore<'_> {
}
impl<'a> SetGameScore<'a> {
pub(crate) fn new<C>(
pub(crate) fn new(
bot: &'a Bot,
chat_id: C,
message_id: i32,
chat_or_inline_message: ChatOrInlineMessage,
user_id: i32,
score: i32,
) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
user_id,
score,
force: None,
@ -69,16 +62,8 @@ impl<'a> SetGameScore<'a> {
}
}
pub fn chat_id<C>(mut self, val: C) -> Self
where
C: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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::{
network,
requests::{Request, ResponseResult},
types::{ChatId, InlineKeyboardMarkup, Message},
types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message},
Bot,
};
@ -16,11 +16,9 @@ pub struct StopMessageLiveLocation<'a> {
#[serde(skip_serializing)]
bot: &'a Bot,
/// Unique identifier for the target chat or username of the target channel
/// (in the format @channelusername)
chat_id: ChatId,
/// Identifier of the message with live location to stop
message_id: i32,
#[serde(flatten)]
chat_or_inline_message: ChatOrInlineMessage,
/// A JSON-serialized object for a new inline keyboard.
reply_markup: Option<InlineKeyboardMarkup>,
}
@ -39,29 +37,19 @@ impl Request<Message> for StopMessageLiveLocation<'_> {
}
impl<'a> StopMessageLiveLocation<'a> {
pub(crate) fn new<C>(bot: &'a Bot, chat_id: C, message_id: i32) -> Self
where
C: Into<ChatId>,
{
let chat_id = chat_id.into();
pub(crate) fn new(
bot: &'a Bot,
chat_or_inline_message: ChatOrInlineMessage,
) -> Self {
Self {
bot,
chat_id,
message_id,
chat_or_inline_message,
reply_markup: None,
}
}
pub fn chat_id<T>(mut self, val: T) -> Self
where
T: Into<ChatId>,
{
self.chat_id = val.into();
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
pub fn chat_or_inline_message(mut self, val: ChatOrInlineMessage) -> Self {
self.chat_or_inline_message = val;
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_id::*;
pub use chat_member::*;
pub use chat_or_inline_message::*;
pub use chat_permissions::*;
pub use chat_photo::*;
pub use chosen_inline_result::*;
@ -93,6 +94,7 @@ mod chat;
mod chat_action;
mod chat_id;
mod chat_member;
mod chat_or_inline_message;
mod chat_permissions;
mod chat_photo;
mod chosen_inline_result;