diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index c1e4f0cd..eee34f27 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -2,21 +2,17 @@ //! //! [`Bot`]: crate::Bot use crate::{prelude::*, types::*}; -use teloxide_core::{ - payloads::*, - requests::{JsonRequest, MultipartRequest}, -}; /// Syntax sugar for [`Message`] manipulations. /// /// [`Message`]: crate::types::Message -pub trait BotMessagesExt { +pub trait BotMessagesExt: Requester { /// This function is the same as [`Bot::forward_message`], /// but can take in [`Message`] to forward it. /// /// [`Bot::forward_message`]: crate::Bot::forward_message /// [`Message`]: crate::types::Message - fn forward(&self, to_chat_id: C, message: &Message) -> JsonRequest + fn forward(&self, to_chat_id: C, message: &Message) -> Self::ForwardMessage where C: Into; @@ -30,42 +26,42 @@ pub trait BotMessagesExt { message: &Message, latitude: f64, longitude: f64, - ) -> JsonRequest; + ) -> Self::EditMessageLiveLocation; /// This function is the same as [`Bot::stop_message_live_location`], /// but can take in [`Message`] to stop the live location in it. /// /// [`Bot::stop_message_live_location`]: crate::Bot::stop_message_live_location /// [`Message`]: crate::types::Message - fn stop_live_location(&self, message: &Message) -> JsonRequest; + fn stop_live_location(&self, message: &Message) -> Self::StopMessageLiveLocation; /// This function is the same as [`Bot::set_message_reaction`], /// but can take in [`Message`] to set a reaction on it. /// /// [`Bot::set_message_reaction`]: crate::Bot::set_message_reaction /// [`Message`]: crate::types::Message - fn set_reaction(&self, message: &Message) -> JsonRequest; + fn set_reaction(&self, message: &Message) -> Self::SetMessageReaction; /// This function is the same as [`Bot::pin_chat_message`], /// but can take in [`Message`] to pin it. /// /// [`Bot::pin_chat_message`]: crate::Bot::pin_chat_message /// [`Message`]: crate::types::Message - fn pin(&self, message: &Message) -> JsonRequest; + fn pin(&self, message: &Message) -> Self::PinChatMessage; /// This function is the same as [`Bot::unpin_chat_message`], /// but can take in [`Message`] to unpin it. /// /// [`Bot::unpin_chat_message`]: crate::Bot::unpin_chat_message /// [`Message`]: crate::types::Message - fn unpin(&self, message: &Message) -> JsonRequest; + fn unpin(&self, message: &Message) -> Self::UnpinChatMessage; /// This function is the same as [`Bot::edit_message_text`], /// but can take in [`Message`] to edit it. /// /// [`Bot::edit_message_text`]: crate::Bot::edit_message_text /// [`Message`]: crate::types::Message - fn edit_text(&self, message: &Message, text: T) -> JsonRequest + fn edit_text(&self, message: &Message, text: T) -> Self::EditMessageText where T: Into; @@ -74,52 +70,51 @@ pub trait BotMessagesExt { /// /// [`Bot::edit_message_caption`]: crate::Bot::edit_message_caption /// [`Message`]: crate::types::Message - fn edit_caption(&self, message: &Message) -> JsonRequest; + fn edit_caption(&self, message: &Message) -> Self::EditMessageCaption; /// This function is the same as [`Bot::edit_message_media`], /// but can take in [`Message`] to edit it. /// /// [`Bot::edit_message_media`]: crate::Bot::edit_message_media /// [`Message`]: crate::types::Message - fn edit_media( - &self, - message: &Message, - media: InputMedia, - ) -> MultipartRequest; + fn edit_media(&self, message: &Message, media: InputMedia) -> Self::EditMessageMedia; /// This function is the same as [`Bot::edit_message_reply_markup`], /// but can take in [`Message`] to edit it. /// /// [`Bot::edit_message_reply_markup`]: crate::Bot::edit_message_reply_markup /// [`Message`]: crate::types::Message - fn edit_reply_markup(&self, message: &Message) -> JsonRequest; + fn edit_reply_markup(&self, message: &Message) -> Self::EditMessageReplyMarkup; /// This function is the same as [`Bot::stop_poll`], /// but can take in [`Message`] to stop the poll in it. /// /// [`Bot::stop_poll`]: crate::Bot::stop_poll /// [`Message`]: crate::types::Message - fn stop_poll_message(&self, message: &Message) -> JsonRequest; + fn stop_poll_message(&self, message: &Message) -> Self::StopPoll; /// This function is the same as [`Bot::delete_message`], /// but can take in [`Message`] to delete it. /// /// [`Bot::delete_message`]: crate::Bot::delete_message /// [`Message`]: crate::types::Message - fn delete(&self, message: &Message) -> JsonRequest; + fn delete(&self, message: &Message) -> Self::DeleteMessage; /// This function is the same as [`Bot::copy_message`], /// but can take in [`Message`] to copy it. /// /// [`Bot::copy_messages`]: crate::Bot::copy_message /// [`Message`]: crate::types::Message - fn copy(&self, to_chat_id: C, message: &Message) -> JsonRequest + fn copy(&self, to_chat_id: C, message: &Message) -> Self::CopyMessage where C: Into; } -impl BotMessagesExt for Bot { - fn forward(&self, to_chat_id: C, message: &Message) -> JsonRequest +impl BotMessagesExt for R +where + R: Requester, +{ + fn forward(&self, to_chat_id: C, message: &Message) -> Self::ForwardMessage where C: Into, { @@ -131,58 +126,54 @@ impl BotMessagesExt for Bot { message: &Message, latitude: f64, longitude: f64, - ) -> JsonRequest { + ) -> Self::EditMessageLiveLocation { self.edit_message_live_location(message.chat.id, message.id, latitude, longitude) } - fn stop_live_location(&self, message: &Message) -> JsonRequest { + fn stop_live_location(&self, message: &Message) -> Self::StopMessageLiveLocation { self.stop_message_live_location(message.chat.id, message.id) } - fn set_reaction(&self, message: &Message) -> JsonRequest { + fn set_reaction(&self, message: &Message) -> Self::SetMessageReaction { self.set_message_reaction(message.chat.id, message.id) } - fn pin(&self, message: &Message) -> JsonRequest { + fn pin(&self, message: &Message) -> Self::PinChatMessage { self.pin_chat_message(message.chat.id, message.id) } - fn unpin(&self, message: &Message) -> JsonRequest { + fn unpin(&self, message: &Message) -> Self::UnpinChatMessage { self.unpin_chat_message(message.chat.id).message_id(message.id) } - fn edit_text(&self, message: &Message, text: T) -> JsonRequest + fn edit_text(&self, message: &Message, text: T) -> Self::EditMessageText where T: Into, { self.edit_message_text(message.chat.id, message.id, text) } - fn edit_caption(&self, message: &Message) -> JsonRequest { + fn edit_caption(&self, message: &Message) -> Self::EditMessageCaption { self.edit_message_caption(message.chat.id, message.id) } - fn edit_media( - &self, - message: &Message, - media: InputMedia, - ) -> MultipartRequest { + fn edit_media(&self, message: &Message, media: InputMedia) -> Self::EditMessageMedia { self.edit_message_media(message.chat.id, message.id, media) } - fn edit_reply_markup(&self, message: &Message) -> JsonRequest { + fn edit_reply_markup(&self, message: &Message) -> Self::EditMessageReplyMarkup { self.edit_message_reply_markup(message.chat.id, message.id) } - fn stop_poll_message(&self, message: &Message) -> JsonRequest { + fn stop_poll_message(&self, message: &Message) -> Self::StopPoll { self.stop_poll(message.chat.id, message.id) } - fn delete(&self, message: &Message) -> JsonRequest { + fn delete(&self, message: &Message) -> Self::DeleteMessage { self.delete_message(message.chat.id, message.id) } - fn copy(&self, to_chat_id: C, message: &Message) -> JsonRequest + fn copy(&self, to_chat_id: C, message: &Message) -> Self::CopyMessage where C: Into, {