diff --git a/src/bot/api.rs b/src/bot/api.rs index fe44008d..a1058d49 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -25,6 +25,7 @@ use crate::{ }, Bot, }; +use std::sync::Arc; impl Bot { /// Use this method to receive incoming updates using long polling ([wiki]). @@ -37,8 +38,8 @@ impl Bot { /// [The official docs](https://core.telegram.org/bots/api#getupdates). /// /// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling - pub fn get_updates(&self) -> GetUpdates { - GetUpdates::new(self) + pub fn get_updates(self: &Arc) -> GetUpdates { + GetUpdates::new(Arc::clone(self)) } /// Use this method to specify a url and receive incoming updates via an @@ -62,11 +63,11 @@ impl Bot { /// Use an empty string to remove webhook integration. /// /// [`Update`]: crate::types::Update - pub fn set_webhook(&self, url: U) -> SetWebhook + pub fn set_webhook(self: &Arc, url: U) -> SetWebhook where U: Into, { - SetWebhook::new(self, url) + SetWebhook::new(Arc::clone(self), url) } /// Use this method to remove webhook integration if you decide to switch @@ -75,8 +76,8 @@ impl Bot { /// [The official docs](https://core.telegram.org/bots/api#deletewebhook). /// /// [Bot::get_updates]: crate::Bot::get_updates - pub fn delete_webhook(&self) -> DeleteWebhook { - DeleteWebhook::new(self) + pub fn delete_webhook(self: &Arc) -> DeleteWebhook { + DeleteWebhook::new(Arc::clone(self)) } /// Use this method to get current webhook status. @@ -87,16 +88,16 @@ impl Bot { /// [The official docs](https://core.telegram.org/bots/api#getwebhookinfo). /// /// [`Bot::get_updates`]: crate::Bot::get_updates - pub fn get_webhook_info(&self) -> GetWebhookInfo { - GetWebhookInfo::new(self) + pub fn get_webhook_info(self: &Arc) -> GetWebhookInfo { + GetWebhookInfo::new(Arc::clone(self)) } /// A simple method for testing your bot's auth token. Requires no /// parameters. /// /// [The official docs](https://core.telegram.org/bots/api#getme). - pub fn get_me(&self) -> GetMe { - GetMe::new(self) + pub fn get_me(self: &Arc) -> GetMe { + GetMe::new(Arc::clone(self)) } /// Use this method to send text messages. @@ -107,12 +108,16 @@ impl Bot { /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). /// - `text`: Text of the message to be sent. - pub fn send_message(&self, chat_id: C, text: T) -> SendMessage + pub fn send_message( + self: &Arc, + chat_id: C, + text: T, + ) -> SendMessage where C: Into, T: Into, { - SendMessage::new(self, chat_id, text) + SendMessage::new(Arc::clone(self), chat_id, text) } /// Use this method to forward messages of any kind. @@ -130,7 +135,7 @@ impl Bot { /// /// [`from_chat_id`]: ForwardMessage::from_chat_id pub fn forward_message( - &self, + self: &Arc, chat_id: C, from_chat_id: F, message_id: i32, @@ -139,7 +144,7 @@ impl Bot { C: Into, F: Into, { - ForwardMessage::new(self, chat_id, from_chat_id, message_id) + ForwardMessage::new(Arc::clone(self), chat_id, from_chat_id, message_id) } /// Use this method to send photos. @@ -161,11 +166,15 @@ impl Bot { /// [`InputFile::FileId`]: crate::types::InputFile::FileId /// /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files - pub fn send_photo(&self, chat_id: C, photo: InputFile) -> SendPhoto + pub fn send_photo( + self: &Arc, + chat_id: C, + photo: InputFile, + ) -> SendPhoto where C: Into, { - SendPhoto::new(self, chat_id, photo) + SendPhoto::new(Arc::clone(self), chat_id, photo) } /// @@ -173,11 +182,15 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn send_audio(&self, chat_id: C, audio: InputFile) -> SendAudio + pub fn send_audio( + self: &Arc, + chat_id: C, + audio: InputFile, + ) -> SendAudio where C: Into, { - SendAudio::new(self, chat_id, audio) + SendAudio::new(Arc::clone(self), chat_id, audio) } /// Use this method to send general files. @@ -199,14 +212,14 @@ impl Bot { /// /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files pub fn send_document( - &self, + self: &Arc, chat_id: C, document: InputFile, ) -> SendDocument where C: Into, { - SendDocument::new(self, chat_id, document) + SendDocument::new(Arc::clone(self), chat_id, document) } /// Use this method to send video files, Telegram clients support mp4 videos @@ -230,11 +243,15 @@ impl Bot { /// [`InputFile::File`]: crate::types::InputFile::File /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId - pub fn send_video(&self, chat_id: C, video: InputFile) -> SendVideo + pub fn send_video( + self: &Arc, + chat_id: C, + video: InputFile, + ) -> SendVideo where C: Into, { - SendVideo::new(self, chat_id, video) + SendVideo::new(Arc::clone(self), chat_id, video) } /// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video @@ -250,14 +267,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `animation`: Animation to send. pub fn send_animation( - &self, + self: &Arc, chat_id: C, animation: InputFile, ) -> SendAnimation where C: Into, { - SendAnimation::new(self, chat_id, animation) + SendAnimation::new(Arc::clone(self), chat_id, animation) } /// Use this method to send audio files, if you want Telegram clients to @@ -287,11 +304,15 @@ impl Bot { /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files - pub fn send_voice(&self, chat_id: C, voice: InputFile) -> SendVoice + pub fn send_voice( + self: &Arc, + chat_id: C, + voice: InputFile, + ) -> SendVoice where C: Into, { - SendVoice::new(self, chat_id, voice) + SendVoice::new(Arc::clone(self), chat_id, voice) } /// As of [v.4.0], Telegram clients support rounded square mp4 videos of up @@ -315,14 +336,14 @@ impl Bot { /// [`InputFile::FileId`]: crate::types::InputFile::FileId /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files pub fn send_video_note( - &self, + self: &Arc, chat_id: C, video_note: InputFile, ) -> SendVideoNote where C: Into, { - SendVideoNote::new(self, chat_id, video_note) + SendVideoNote::new(Arc::clone(self), chat_id, video_note) } /// Use this method to send a group of photos or videos as an album. @@ -334,12 +355,16 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `media`: A JSON-serialized array describing photos and videos to be /// sent, must include 2–10 items. - pub fn send_media_group(&self, chat_id: C, media: M) -> SendMediaGroup + pub fn send_media_group( + self: &Arc, + chat_id: C, + media: M, + ) -> SendMediaGroup where C: Into, M: Into>, { - SendMediaGroup::new(self, chat_id, media) + SendMediaGroup::new(Arc::clone(self), chat_id, media) } /// Use this method to send point on the map. @@ -352,7 +377,7 @@ impl Bot { /// - `latitude`: Latitude of the location. /// - `longitude`: Latitude of the location. pub fn send_location( - &self, + self: &Arc, chat_id: C, latitude: f32, longitude: f32, @@ -360,7 +385,7 @@ impl Bot { where C: Into, { - SendLocation::new(self, chat_id, latitude, longitude) + SendLocation::new(Arc::clone(self), chat_id, latitude, longitude) } /// Use this method to edit live location messages. @@ -379,13 +404,13 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_live_location( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, latitude: f32, longitude: f32, ) -> EditMessageLiveLocation { EditMessageLiveLocation::new( - self, + Arc::clone(self), chat_or_inline_message, latitude, longitude, @@ -403,10 +428,10 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn stop_message_live_location( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, ) -> StopMessageLiveLocation { - StopMessageLiveLocation::new(self, chat_or_inline_message) + StopMessageLiveLocation::new(Arc::clone(self), chat_or_inline_message) } /// Use this method to send information about a venue. @@ -421,7 +446,7 @@ impl Bot { /// - `title`: Name of the venue. /// - `address`: Address of the venue. pub fn send_venue( - &self, + self: &Arc, chat_id: C, latitude: f32, longitude: f32, @@ -433,7 +458,14 @@ impl Bot { T: Into, A: Into, { - SendVenue::new(self, chat_id, latitude, longitude, title, address) + SendVenue::new( + Arc::clone(self), + chat_id, + latitude, + longitude, + title, + address, + ) } /// Use this method to send phone contacts. @@ -447,7 +479,7 @@ impl Bot { /// - `phone_number`: Contact's phone number. /// - `first_name`: Contact's first name. pub fn send_contact( - &self, + self: &Arc, chat_id: C, phone_number: P, first_name: F, @@ -457,7 +489,7 @@ impl Bot { P: Into, F: Into, { - SendContact::new(self, chat_id, phone_number, first_name) + SendContact::new(Arc::clone(self), chat_id, phone_number, first_name) } /// Use this method to send a native poll. A native poll can't be sent to a @@ -473,7 +505,7 @@ impl Bot { /// - `options`: List of answer options, 2-10 strings 1-100 characters /// each. pub fn send_poll( - &self, + self: &Arc, chat_id: C, question: Q, options: O, @@ -483,7 +515,7 @@ impl Bot { Q: Into, O: Into>, { - SendPoll::new(self, chat_id, question, options) + SendPoll::new(Arc::clone(self), chat_id, question, options) } /// Use this method when you need to tell the user that something is @@ -509,14 +541,14 @@ impl Bot { /// [ImageBot]: https://t.me/imagebot /// [`Bot::send_chat_action`]: crate::Bot::send_chat_action pub fn send_chat_action( - &self, + self: &Arc, chat_id: C, action: SendChatActionKind, ) -> SendChatAction where C: Into, { - SendChatAction::new(self, chat_id, action) + SendChatAction::new(Arc::clone(self), chat_id, action) } /// Use this method to get a list of profile pictures for a user. @@ -526,10 +558,10 @@ impl Bot { /// # Params /// - `user_id`: Unique identifier of the target user. pub fn get_user_profile_photos( - &self, + self: &Arc, user_id: i32, ) -> GetUserProfilePhotos { - GetUserProfilePhotos::new(self, user_id) + GetUserProfilePhotos::new(Arc::clone(self), user_id) } /// Use this method to get basic info about a file and prepare it for @@ -554,11 +586,11 @@ impl Bot { /// /// [`File`]: crate::types::file /// [`GetFile`]: self::GetFile - pub fn get_file(&self, file_id: F) -> GetFile + pub fn get_file(self: &Arc, file_id: F) -> GetFile where F: Into, { - GetFile::new(self, file_id) + GetFile::new(Arc::clone(self), file_id) } /// Use this method to kick a user from a group, a supergroup or a channel. @@ -577,14 +609,14 @@ impl Bot { /// /// [unbanned]: crate::Bot::unban_chat_member pub fn kick_chat_member( - &self, + self: &Arc, chat_id: C, user_id: i32, ) -> KickChatMember where C: Into, { - KickChatMember::new(self, chat_id, user_id) + KickChatMember::new(Arc::clone(self), chat_id, user_id) } /// Use this method to unban a previously kicked user in a supergroup or @@ -599,14 +631,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `user_id`: Unique identifier of the target user. pub fn unban_chat_member( - &self, + self: &Arc, chat_id: C, user_id: i32, ) -> UnbanChatMember where C: Into, { - UnbanChatMember::new(self, chat_id, user_id) + UnbanChatMember::new(Arc::clone(self), chat_id, user_id) } /// Use this method to restrict a user in a supergroup. @@ -623,7 +655,7 @@ impl Bot { /// - `user_id`: Unique identifier of the target user. /// - `permissions`: New user permissions. pub fn restrict_chat_member( - &self, + self: &Arc, chat_id: C, user_id: i32, permissions: ChatPermissions, @@ -631,7 +663,7 @@ impl Bot { where C: Into, { - RestrictChatMember::new(self, chat_id, user_id, permissions) + RestrictChatMember::new(Arc::clone(self), chat_id, user_id, permissions) } /// Use this method to promote or demote a user in a supergroup or a @@ -648,14 +680,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `user_id`: Unique identifier of the target user. pub fn promote_chat_member( - &self, + self: &Arc, chat_id: C, user_id: i32, ) -> PromoteChatMember where C: Into, { - PromoteChatMember::new(self, chat_id, user_id) + PromoteChatMember::new(Arc::clone(self), chat_id, user_id) } /// Use this method to set default chat permissions for all members. @@ -670,14 +702,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `permissions`: New default chat permissions. pub fn set_chat_permissions( - &self, + self: &Arc, chat_id: C, permissions: ChatPermissions, ) -> SetChatPermissions where C: Into, { - SetChatPermissions::new(self, chat_id, permissions) + SetChatPermissions::new(Arc::clone(self), chat_id, permissions) } /// Use this method to generate a new invite link for a chat; any previously @@ -703,11 +735,14 @@ impl Bot { /// /// [`Bot::export_chat_invite_link`]: crate::Bot::export_chat_invite_link /// [`Bot::get_chat`]: crate::Bot::get_chat - pub fn export_chat_invite_link(&self, chat_id: C) -> ExportChatInviteLink + pub fn export_chat_invite_link( + self: &Arc, + chat_id: C, + ) -> ExportChatInviteLink where C: Into, { - ExportChatInviteLink::new(self, chat_id) + ExportChatInviteLink::new(Arc::clone(self), chat_id) } /// Use this method to set a new profile photo for the chat. @@ -723,14 +758,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `photo`: New chat photo, uploaded using `multipart/form-data`. pub fn set_chat_photo( - &self, + self: &Arc, chat_id: C, photo: InputFile, ) -> SetChatPhoto where C: Into, { - SetChatPhoto::new(self, chat_id, photo) + SetChatPhoto::new(Arc::clone(self), chat_id, photo) } /// Use this method to delete a chat photo. Photos can't be changed for @@ -742,11 +777,11 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn delete_chat_photo(&self, chat_id: C) -> DeleteChatPhoto + pub fn delete_chat_photo(self: &Arc, chat_id: C) -> DeleteChatPhoto where C: Into, { - DeleteChatPhoto::new(self, chat_id) + DeleteChatPhoto::new(Arc::clone(self), chat_id) } /// Use this method to change the title of a chat. @@ -761,12 +796,16 @@ impl Bot { /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). /// - `title`: New chat title, 1-255 characters. - pub fn set_chat_title(&self, chat_id: C, title: T) -> SetChatTitle + pub fn set_chat_title( + self: &Arc, + chat_id: C, + title: T, + ) -> SetChatTitle where C: Into, T: Into, { - SetChatTitle::new(self, chat_id, title) + SetChatTitle::new(Arc::clone(self), chat_id, title) } /// Use this method to change the description of a group, a supergroup or a @@ -780,11 +819,14 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn set_chat_description(&self, chat_id: C) -> SetChatDescription + pub fn set_chat_description( + self: &Arc, + chat_id: C, + ) -> SetChatDescription where C: Into, { - SetChatDescription::new(self, chat_id) + SetChatDescription::new(Arc::clone(self), chat_id) } /// Use this method to pin a message in a group, a supergroup, or a channel. @@ -800,14 +842,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `message_id`: Identifier of a message to pin. pub fn pin_chat_message( - &self, + self: &Arc, chat_id: C, message_id: i32, ) -> PinChatMessage where C: Into, { - PinChatMessage::new(self, chat_id, message_id) + PinChatMessage::new(Arc::clone(self), chat_id, message_id) } /// Use this method to unpin a message in a group, a supergroup, or a @@ -822,11 +864,14 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn unpin_chat_message(&self, chat_id: C) -> UnpinChatMessage + pub fn unpin_chat_message( + self: &Arc, + chat_id: C, + ) -> UnpinChatMessage where C: Into, { - UnpinChatMessage::new(self, chat_id) + UnpinChatMessage::new(Arc::clone(self), chat_id) } /// Use this method for your bot to leave a group, supergroup or channel. @@ -836,11 +881,11 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn leave_chat(&self, chat_id: C) -> LeaveChat + pub fn leave_chat(self: &Arc, chat_id: C) -> LeaveChat where C: Into, { - LeaveChat::new(self, chat_id) + LeaveChat::new(Arc::clone(self), chat_id) } /// Use this method to get up to date information about the chat (current @@ -852,11 +897,11 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn get_chat(&self, chat_id: C) -> GetChat + pub fn get_chat(self: &Arc, chat_id: C) -> GetChat where C: Into, { - GetChat::new(self, chat_id) + GetChat::new(Arc::clone(self), chat_id) } /// Use this method to get a list of administrators in a chat. @@ -870,13 +915,13 @@ impl Bot { /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). pub fn get_chat_administrators( - &self, + self: &Arc, chat_id: C, ) -> GetChatAdministrators where C: Into, { - GetChatAdministrators::new(self, chat_id) + GetChatAdministrators::new(Arc::clone(self), chat_id) } /// Use this method to get the number of members in a chat. @@ -886,11 +931,14 @@ impl Bot { /// # Params /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). - pub fn get_chat_members_count(&self, chat_id: C) -> GetChatMembersCount + pub fn get_chat_members_count( + self: &Arc, + chat_id: C, + ) -> GetChatMembersCount where C: Into, { - GetChatMembersCount::new(self, chat_id) + GetChatMembersCount::new(Arc::clone(self), chat_id) } /// Use this method to get information about a member of a chat. @@ -901,11 +949,15 @@ impl Bot { /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). /// - `user_id`: Unique identifier of the target user. - pub fn get_chat_member(&self, chat_id: C, user_id: i32) -> GetChatMember + pub fn get_chat_member( + self: &Arc, + chat_id: C, + user_id: i32, + ) -> GetChatMember where C: Into, { - GetChatMember::new(self, chat_id, user_id) + GetChatMember::new(Arc::clone(self), chat_id, user_id) } /// Use this method to set a new group sticker set for a supergroup. @@ -923,7 +975,7 @@ impl Bot { /// - `sticker_set_name`: Name of the sticker set to be set as the group /// sticker set. pub fn set_chat_sticker_set( - &self, + self: &Arc, chat_id: C, sticker_set_name: S, ) -> SetChatStickerSet @@ -931,7 +983,7 @@ impl Bot { C: Into, S: Into, { - SetChatStickerSet::new(self, chat_id, sticker_set_name) + SetChatStickerSet::new(Arc::clone(self), chat_id, sticker_set_name) } /// Use this method to delete a group sticker set from a supergroup. @@ -948,11 +1000,14 @@ impl Bot { /// target supergroup (in the format `@supergroupusername`). /// /// [`Bot::get_chat`]: crate::Bot::get_chat - pub fn delete_chat_sticker_set(&self, chat_id: C) -> DeleteChatStickerSet + pub fn delete_chat_sticker_set( + self: &Arc, + chat_id: C, + ) -> DeleteChatStickerSet where C: Into, { - DeleteChatStickerSet::new(self, chat_id) + DeleteChatStickerSet::new(Arc::clone(self), chat_id) } /// Use this method to send answers to callback queries sent from [inline @@ -968,13 +1023,13 @@ impl Bot { /// /// [inline keyboards]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating pub fn answer_callback_query( - &self, + self: &Arc, callback_query_id: C, ) -> AnswerCallbackQuery where C: Into, { - AnswerCallbackQuery::new(self, callback_query_id) + AnswerCallbackQuery::new(Arc::clone(self), callback_query_id) } /// Use this method to edit text and game messages. @@ -990,14 +1045,14 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_text( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, text: T, ) -> EditMessageText where T: Into, { - EditMessageText::new(self, chat_or_inline_message, text) + EditMessageText::new(Arc::clone(self), chat_or_inline_message, text) } /// Use this method to edit captions of messages. @@ -1010,10 +1065,10 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_caption( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, ) -> EditMessageCaption { - EditMessageCaption::new(self, chat_or_inline_message) + EditMessageCaption::new(Arc::clone(self), chat_or_inline_message) } /// Use this method to edit animation, audio, document, photo, or video @@ -1031,11 +1086,11 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_media( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, media: InputMedia, ) -> EditMessageMedia { - EditMessageMedia::new(self, chat_or_inline_message, media) + EditMessageMedia::new(Arc::clone(self), chat_or_inline_message, media) } /// Use this method to edit only the reply markup of messages. @@ -1048,10 +1103,10 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_reply_markup( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, ) -> EditMessageReplyMarkup { - EditMessageReplyMarkup::new(self, chat_or_inline_message) + EditMessageReplyMarkup::new(Arc::clone(self), chat_or_inline_message) } /// Use this method to stop a poll which was sent by the bot. @@ -1063,11 +1118,15 @@ impl Bot { /// - `chat_id`: Unique identifier for the target chat or username of the /// target channel (in the format `@channelusername`). /// - `message_id`: Identifier of the original message with the poll. - pub fn stop_poll(&self, chat_id: C, message_id: i32) -> StopPoll + pub fn stop_poll( + self: &Arc, + chat_id: C, + message_id: i32, + ) -> StopPoll where C: Into, { - StopPoll::new(self, chat_id, message_id) + StopPoll::new(Arc::clone(self), chat_id, message_id) } /// Use this method to delete a message, including service messages. @@ -1091,14 +1150,14 @@ impl Bot { /// target channel (in the format `@channelusername`). /// - `message_id`: Identifier of the message to delete. pub fn delete_message( - &self, + self: &Arc, chat_id: C, message_id: i32, ) -> DeleteMessage where C: Into, { - DeleteMessage::new(self, chat_id, message_id) + DeleteMessage::new(Arc::clone(self), chat_id, message_id) } /// Use this method to send static .WEBP or [animated] .TGS stickers. @@ -1120,11 +1179,15 @@ impl Bot { /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files - pub fn send_sticker(&self, chat_id: C, sticker: InputFile) -> SendSticker + pub fn send_sticker( + self: &Arc, + chat_id: C, + sticker: InputFile, + ) -> SendSticker where C: Into, { - SendSticker::new(self, chat_id, sticker) + SendSticker::new(Arc::clone(self), chat_id, sticker) } /// Use this method to get a sticker set. @@ -1133,11 +1196,11 @@ impl Bot { /// /// # Params /// - `name`: Name of the sticker set. - pub fn get_sticker_set(&self, name: N) -> GetStickerSet + pub fn get_sticker_set(self: &Arc, name: N) -> GetStickerSet where N: Into, { - GetStickerSet::new(self, name) + GetStickerSet::new(Arc::clone(self), name) } /// Use this method to upload a .png file with a sticker for later use in @@ -1157,11 +1220,11 @@ impl Bot { /// [`Bot::create_new_sticker_set`]: crate::Bot::create_new_sticker_set /// [`Bot::add_sticker_to_set`]: crate::Bot::add_sticker_to_set pub fn upload_sticker_file( - &self, + self: &Arc, user_id: i32, png_sticker: InputFile, ) -> UploadStickerFile { - UploadStickerFile::new(self, user_id, png_sticker) + UploadStickerFile::new(Arc::clone(self), user_id, png_sticker) } /// Use this method to create new sticker set owned by a user. The bot will @@ -1193,7 +1256,7 @@ impl Bot { /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId pub fn create_new_sticker_set( - &self, + self: &Arc, user_id: i32, name: N, title: T, @@ -1206,7 +1269,7 @@ impl Bot { E: Into, { CreateNewStickerSet::new( - self, + Arc::clone(self), user_id, name, title, @@ -1236,7 +1299,7 @@ impl Bot { /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId pub fn add_sticker_to_set( - &self, + self: &Arc, user_id: i32, name: N, png_sticker: InputFile, @@ -1246,7 +1309,13 @@ impl Bot { N: Into, E: Into, { - AddStickerToSet::new(self, user_id, name, png_sticker, emojis) + AddStickerToSet::new( + Arc::clone(self), + user_id, + name, + png_sticker, + emojis, + ) } /// Use this method to move a sticker in a set created by the bot to a @@ -1258,14 +1327,14 @@ impl Bot { /// - `sticker`: File identifier of the sticker. /// - `position`: New sticker position in the set, zero-based. pub fn set_sticker_position_in_set( - &self, + self: &Arc, sticker: S, position: i32, ) -> SetStickerPositionInSet where S: Into, { - SetStickerPositionInSet::new(self, sticker, position) + SetStickerPositionInSet::new(Arc::clone(self), sticker, position) } /// Use this method to delete a sticker from a set created by the bot. @@ -1274,11 +1343,14 @@ impl Bot { /// /// # Params /// - `sticker`: File identifier of the sticker. - pub fn delete_sticker_from_set(&self, sticker: S) -> DeleteStickerFromSet + pub fn delete_sticker_from_set( + self: &Arc, + sticker: S, + ) -> DeleteStickerFromSet where S: Into, { - DeleteStickerFromSet::new(self, sticker) + DeleteStickerFromSet::new(Arc::clone(self), sticker) } /// Use this method to send answers to an inline query. @@ -1291,7 +1363,7 @@ impl Bot { /// - `inline_query_id`: Unique identifier for the answered query. /// - `results`: A JSON-serialized array of results for the inline query. pub fn answer_inline_query( - &self, + self: &Arc, inline_query_id: I, results: R, ) -> AnswerInlineQuery @@ -1299,7 +1371,7 @@ impl Bot { I: Into, R: Into>, { - AnswerInlineQuery::new(self, inline_query_id, results) + AnswerInlineQuery::new(Arc::clone(self), inline_query_id, results) } /// Use this method to send invoices. @@ -1325,7 +1397,7 @@ impl Bot { /// [@Botfather]: https://t.me/botfather #[allow(clippy::too_many_arguments)] pub fn send_invoice( - &self, + self: &Arc, chat_id: i32, title: T, description: D, @@ -1345,7 +1417,7 @@ impl Bot { Pr: Into>, { SendInvoice::new( - self, + Arc::clone(self), chat_id, title, description, @@ -1373,14 +1445,14 @@ impl Bot { /// /// [`Update`]: crate::types::Update pub fn answer_shipping_query( - &self, + self: &Arc, shipping_query_id: S, ok: bool, ) -> AnswerShippingQuery where S: Into, { - AnswerShippingQuery::new(self, shipping_query_id, ok) + AnswerShippingQuery::new(Arc::clone(self), shipping_query_id, ok) } /// Once the user has confirmed their payment and shipping details, the Bot @@ -1400,14 +1472,14 @@ impl Bot { /// /// [`Update`]: crate::types::Update pub fn answer_pre_checkout_query

( - &self, + self: &Arc, pre_checkout_query_id: P, ok: bool, ) -> AnswerPreCheckoutQuery where P: Into, { - AnswerPreCheckoutQuery::new(self, pre_checkout_query_id, ok) + AnswerPreCheckoutQuery::new(Arc::clone(self), pre_checkout_query_id, ok) } /// Use this method to send a game. @@ -1420,11 +1492,15 @@ impl Bot { /// identifier for the game. Set up your games via [@Botfather]. /// /// [@Botfather]: https://t.me/botfather - pub fn send_game(&self, chat_id: i32, game_short_name: G) -> SendGame + pub fn send_game( + self: &Arc, + chat_id: i32, + game_short_name: G, + ) -> SendGame where G: Into, { - SendGame::new(self, chat_id, game_short_name) + SendGame::new(Arc::clone(self), chat_id, game_short_name) } /// Use this method to set the score of the specified user in a game. @@ -1443,12 +1519,17 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn set_game_score( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, score: i32, ) -> SetGameScore { - SetGameScore::new(self, chat_or_inline_message, user_id, score) + SetGameScore::new( + Arc::clone(self), + chat_or_inline_message, + user_id, + score, + ) } /// Use this method to get data for high score tables. @@ -1467,11 +1548,15 @@ impl Bot { /// # Params /// - `user_id`: Target user id. pub fn get_game_high_scores( - &self, + self: &Arc, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, ) -> GetGameHighScores { - GetGameHighScores::new(self, chat_or_inline_message, user_id) + GetGameHighScores::new( + Arc::clone(self), + chat_or_inline_message, + user_id, + ) } /// Use this method to set a custom title for an administrator in a @@ -1486,7 +1571,7 @@ impl Bot { /// - `custom_title`: New custom title for the administrator; 0-16 /// characters, emoji are not allowed. pub fn set_chat_administrator_custom_title( - &self, + self: &Arc, chat_id: C, user_id: i32, custom_title: CT, @@ -1496,7 +1581,7 @@ impl Bot { CT: Into, { SetChatAdministratorCustomTitle::new( - self, + Arc::clone(self), chat_id, user_id, custom_title, diff --git a/src/requests/all/add_sticker_to_set.rs b/src/requests/all/add_sticker_to_set.rs index 760f4b54..119bd7e1 100644 --- a/src/requests/all/add_sticker_to_set.rs +++ b/src/requests/all/add_sticker_to_set.rs @@ -5,15 +5,15 @@ use crate::{ Bot, }; -use super::BotWrapper; use crate::requests::{Request, ResponseResult}; +use std::sync::Arc; /// Use this method to add a new sticker to a set created by the bot. /// /// [The official docs](https://core.telegram.org/bots/api#addstickertoset). -#[derive(PartialEq, Debug, Clone)] -pub struct AddStickerToSet<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct AddStickerToSet { + bot: Arc, user_id: i32, name: String, png_sticker: InputFile, @@ -22,7 +22,7 @@ pub struct AddStickerToSet<'a> { } #[async_trait::async_trait] -impl Request for AddStickerToSet<'_> { +impl Request for AddStickerToSet { type Output = True; async fn send(&self) -> ResponseResult { @@ -47,9 +47,9 @@ impl Request for AddStickerToSet<'_> { } } -impl<'a> AddStickerToSet<'a> { +impl AddStickerToSet { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, user_id: i32, name: N, png_sticker: InputFile, @@ -60,7 +60,7 @@ impl<'a> AddStickerToSet<'a> { E: Into, { Self { - bot: BotWrapper(bot), + bot, user_id, name: name.into(), png_sticker, diff --git a/src/requests/all/answer_callback_query.rs b/src/requests/all/answer_callback_query.rs index 38f0c856..a636e314 100644 --- a/src/requests/all/answer_callback_query.rs +++ b/src/requests/all/answer_callback_query.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::True, Bot, }; +use std::sync::Arc; /// Use this method to send answers to callback queries sent from [inline /// keyboards]. @@ -18,10 +18,10 @@ use crate::{ /// /// [inline keyboards]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct AnswerCallbackQuery<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct AnswerCallbackQuery { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, callback_query_id: String, text: Option, show_alert: Option, @@ -30,7 +30,7 @@ pub struct AnswerCallbackQuery<'a> { } #[async_trait::async_trait] -impl Request for AnswerCallbackQuery<'_> { +impl Request for AnswerCallbackQuery { type Output = True; async fn send(&self) -> ResponseResult { @@ -44,14 +44,14 @@ impl Request for AnswerCallbackQuery<'_> { } } -impl<'a> AnswerCallbackQuery<'a> { - pub(crate) fn new(bot: &'a Bot, callback_query_id: C) -> Self +impl AnswerCallbackQuery { + pub(crate) fn new(bot: Arc, callback_query_id: C) -> Self where C: Into, { let callback_query_id = callback_query_id.into(); Self { - bot: BotWrapper(bot), + bot, callback_query_id, text: None, show_alert: None, diff --git a/src/requests/all/answer_inline_query.rs b/src/requests/all/answer_inline_query.rs index 1236423a..ad75ea06 100644 --- a/src/requests/all/answer_inline_query.rs +++ b/src/requests/all/answer_inline_query.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{InlineQueryResult, True}, Bot, }; +use std::sync::Arc; /// Use this method to send answers to an inline query. /// @@ -14,10 +14,10 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#answerinlinequery). #[serde_with_macros::skip_serializing_none] -#[derive(PartialEq, Debug, Clone, Serialize)] -pub struct AnswerInlineQuery<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct AnswerInlineQuery { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, inline_query_id: String, results: Vec, cache_time: Option, @@ -28,7 +28,7 @@ pub struct AnswerInlineQuery<'a> { } #[async_trait::async_trait] -impl Request for AnswerInlineQuery<'_> { +impl Request for AnswerInlineQuery { type Output = True; async fn send(&self) -> ResponseResult { @@ -42,9 +42,9 @@ impl Request for AnswerInlineQuery<'_> { } } -impl<'a> AnswerInlineQuery<'a> { +impl AnswerInlineQuery { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, inline_query_id: I, results: R, ) -> Self @@ -55,7 +55,7 @@ impl<'a> AnswerInlineQuery<'a> { let inline_query_id = inline_query_id.into(); let results = results.into(); Self { - bot: BotWrapper(bot), + bot, inline_query_id, results, cache_time: None, diff --git a/src/requests/all/answer_pre_checkout_query.rs b/src/requests/all/answer_pre_checkout_query.rs index 8d8dd0fb..cdff1e28 100644 --- a/src/requests/all/answer_pre_checkout_query.rs +++ b/src/requests/all/answer_pre_checkout_query.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::True, Bot, }; +use std::sync::Arc; /// Once the user has confirmed their payment and shipping details, the Bot API /// sends the final confirmation in the form of an [`Update`] with the field @@ -18,17 +18,17 @@ use crate::{ /// /// [`Update`]: crate::types::Update #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct AnswerPreCheckoutQuery<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct AnswerPreCheckoutQuery { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, pre_checkout_query_id: String, ok: bool, error_message: Option, } #[async_trait::async_trait] -impl Request for AnswerPreCheckoutQuery<'_> { +impl Request for AnswerPreCheckoutQuery { type Output = True; async fn send(&self) -> ResponseResult { @@ -42,9 +42,9 @@ impl Request for AnswerPreCheckoutQuery<'_> { } } -impl<'a> AnswerPreCheckoutQuery<'a> { +impl AnswerPreCheckoutQuery { pub(crate) fn new

( - bot: &'a Bot, + bot: Arc, pre_checkout_query_id: P, ok: bool, ) -> Self @@ -53,7 +53,7 @@ impl<'a> AnswerPreCheckoutQuery<'a> { { let pre_checkout_query_id = pre_checkout_query_id.into(); Self { - bot: BotWrapper(bot), + bot, pre_checkout_query_id, ok, error_message: None, diff --git a/src/requests/all/answer_shipping_query.rs b/src/requests/all/answer_shipping_query.rs index 45435362..452c93ed 100644 --- a/src/requests/all/answer_shipping_query.rs +++ b/src/requests/all/answer_shipping_query.rs @@ -1,12 +1,13 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ShippingOption, True}, Bot, }; +use std::sync::Arc; + /// If you sent an invoice requesting a shipping address and the parameter /// `is_flexible` was specified, the Bot API will send an [`Update`] with a /// shipping_query field to the bot. Use this method to reply to shipping @@ -16,10 +17,10 @@ use crate::{ /// /// [`Update`]: crate::types::Update #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct AnswerShippingQuery<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct AnswerShippingQuery { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, shipping_query_id: String, ok: bool, shipping_options: Option>, @@ -27,7 +28,7 @@ pub struct AnswerShippingQuery<'a> { } #[async_trait::async_trait] -impl Request for AnswerShippingQuery<'_> { +impl Request for AnswerShippingQuery { type Output = True; async fn send(&self) -> ResponseResult { @@ -41,14 +42,14 @@ impl Request for AnswerShippingQuery<'_> { } } -impl<'a> AnswerShippingQuery<'a> { - pub(crate) fn new(bot: &'a Bot, shipping_query_id: S, ok: bool) -> Self +impl AnswerShippingQuery { + pub(crate) fn new(bot: Arc, shipping_query_id: S, ok: bool) -> Self where S: Into, { let shipping_query_id = shipping_query_id.into(); Self { - bot: BotWrapper(bot), + bot, shipping_query_id, ok, shipping_options: None, diff --git a/src/requests/all/bot_wrapper.rs b/src/requests/all/bot_wrapper.rs deleted file mode 100644 index 87857725..00000000 --- a/src/requests/all/bot_wrapper.rs +++ /dev/null @@ -1,33 +0,0 @@ -use crate::Bot; -use std::ops::Deref; - -/// A wrapper that implements `Clone`, Copy, `PartialEq`, `Eq`, `Debug`, but -/// performs no copying, cloning and comparison. -/// -/// Used in the requests bodies. -#[derive(Debug)] -pub struct BotWrapper<'a>(pub &'a Bot); - -impl PartialEq for BotWrapper<'_> { - fn eq(&self, other: &BotWrapper<'_>) -> bool { - self.0.token() == other.0.token() - } -} - -impl Eq for BotWrapper<'_> {} - -impl<'a> Clone for BotWrapper<'a> { - fn clone(&self) -> BotWrapper<'a> { - Self(self.0) - } -} - -impl Copy for BotWrapper<'_> {} - -impl Deref for BotWrapper<'_> { - type Target = Bot; - - fn deref(&self) -> &Bot { - &self.0 - } -} diff --git a/src/requests/all/create_new_sticker_set.rs b/src/requests/all/create_new_sticker_set.rs index a72556f4..cfb98634 100644 --- a/src/requests/all/create_new_sticker_set.rs +++ b/src/requests/all/create_new_sticker_set.rs @@ -1,18 +1,18 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{InputFile, MaskPosition, True}, Bot, }; +use std::sync::Arc; /// Use this method to create new sticker set owned by a user. The bot will be /// able to edit the created sticker set. /// /// [The official docs](https://core.telegram.org/bots/api#createnewstickerset). -#[derive(PartialEq, Debug, Clone)] -pub struct CreateNewStickerSet<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct CreateNewStickerSet { + bot: Arc, user_id: i32, name: String, title: String, @@ -23,7 +23,7 @@ pub struct CreateNewStickerSet<'a> { } #[async_trait::async_trait] -impl Request for CreateNewStickerSet<'_> { +impl Request for CreateNewStickerSet { type Output = True; async fn send(&self) -> ResponseResult { @@ -52,9 +52,9 @@ impl Request for CreateNewStickerSet<'_> { } } -impl<'a> CreateNewStickerSet<'a> { +impl CreateNewStickerSet { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, user_id: i32, name: N, title: T, @@ -67,7 +67,7 @@ impl<'a> CreateNewStickerSet<'a> { E: Into, { Self { - bot: BotWrapper(bot), + bot, user_id, name: name.into(), title: title.into(), diff --git a/src/requests/all/delete_chat_photo.rs b/src/requests/all/delete_chat_photo.rs index af1b330e..d9ab17e1 100644 --- a/src/requests/all/delete_chat_photo.rs +++ b/src/requests/all/delete_chat_photo.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to delete a chat photo. Photos can't be changed for private /// chats. The bot must be an administrator in the chat for this to work and @@ -14,15 +14,15 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#deletechatphoto). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct DeleteChatPhoto<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct DeleteChatPhoto { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for DeleteChatPhoto<'_> { +impl Request for DeleteChatPhoto { type Output = True; async fn send(&self) -> ResponseResult { @@ -36,16 +36,13 @@ impl Request for DeleteChatPhoto<'_> { } } -impl<'a> DeleteChatPhoto<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl DeleteChatPhoto { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target channel diff --git a/src/requests/all/delete_chat_sticker_set.rs b/src/requests/all/delete_chat_sticker_set.rs index b10962dc..0ad7ead9 100644 --- a/src/requests/all/delete_chat_sticker_set.rs +++ b/src/requests/all/delete_chat_sticker_set.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to delete a group sticker set from a supergroup. /// @@ -19,15 +19,15 @@ use crate::{ /// /// [`Bot::get_chat`]: crate::Bot::get_chat #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct DeleteChatStickerSet<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct DeleteChatStickerSet { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for DeleteChatStickerSet<'_> { +impl Request for DeleteChatStickerSet { type Output = True; async fn send(&self) -> ResponseResult { @@ -41,16 +41,13 @@ impl Request for DeleteChatStickerSet<'_> { } } -impl<'a> DeleteChatStickerSet<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl DeleteChatStickerSet { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target diff --git a/src/requests/all/delete_message.rs b/src/requests/all/delete_message.rs index 0dbb88c8..cf28eb23 100644 --- a/src/requests/all/delete_message.rs +++ b/src/requests/all/delete_message.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to delete a message, including service messages. /// @@ -24,16 +24,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#deletemessage). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct DeleteMessage<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct DeleteMessage { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, message_id: i32, } #[async_trait::async_trait] -impl Request for DeleteMessage<'_> { +impl Request for DeleteMessage { type Output = True; async fn send(&self) -> ResponseResult { @@ -47,14 +47,14 @@ impl Request for DeleteMessage<'_> { } } -impl<'a> DeleteMessage<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, message_id: i32) -> Self +impl DeleteMessage { + pub(crate) fn new(bot: Arc, chat_id: C, message_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, message_id, } diff --git a/src/requests/all/delete_sticker_from_set.rs b/src/requests/all/delete_sticker_from_set.rs index 111622f1..41f41f80 100644 --- a/src/requests/all/delete_sticker_from_set.rs +++ b/src/requests/all/delete_sticker_from_set.rs @@ -1,26 +1,26 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::True, Bot, }; +use std::sync::Arc; /// Use this method to delete a sticker from a set created by the bot. /// /// [The official docs](https://core.telegram.org/bots/api#deletestickerfromset). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct DeleteStickerFromSet<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct DeleteStickerFromSet { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, sticker: String, } #[async_trait::async_trait] -impl Request for DeleteStickerFromSet<'_> { +impl Request for DeleteStickerFromSet { type Output = True; async fn send(&self) -> ResponseResult { @@ -34,16 +34,13 @@ impl Request for DeleteStickerFromSet<'_> { } } -impl<'a> DeleteStickerFromSet<'a> { - pub(crate) fn new(bot: &'a Bot, sticker: S) -> Self +impl DeleteStickerFromSet { + pub(crate) fn new(bot: Arc, sticker: S) -> Self where S: Into, { let sticker = sticker.into(); - Self { - bot: BotWrapper(bot), - sticker, - } + Self { bot, sticker } } /// File identifier of the sticker. diff --git a/src/requests/all/delete_webhook.rs b/src/requests/all/delete_webhook.rs index 10511a1b..dbfcda20 100644 --- a/src/requests/all/delete_webhook.rs +++ b/src/requests/all/delete_webhook.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::True, Bot, }; +use std::sync::Arc; /// Use this method to remove webhook integration if you decide to switch back /// to [Bot::get_updates]. @@ -15,14 +15,14 @@ use crate::{ /// /// [Bot::get_updates]: crate::Bot::get_updates #[serde_with_macros::skip_serializing_none] -#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)] -pub struct DeleteWebhook<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct DeleteWebhook { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, } #[async_trait::async_trait] -impl Request for DeleteWebhook<'_> { +impl Request for DeleteWebhook { type Output = True; #[allow(clippy::trivially_copy_pass_by_ref)] @@ -37,10 +37,8 @@ impl Request for DeleteWebhook<'_> { } } -impl<'a> DeleteWebhook<'a> { - pub(crate) fn new(bot: &'a Bot) -> Self { - Self { - bot: BotWrapper(bot), - } +impl DeleteWebhook { + pub(crate) fn new(bot: Arc) -> Self { + Self { bot } } } diff --git a/src/requests/all/edit_message_caption.rs b/src/requests/all/edit_message_caption.rs index e873d2dc..6a5d0e1d 100644 --- a/src/requests/all/edit_message_caption.rs +++ b/src/requests/all/edit_message_caption.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode}, Bot, }; +use std::sync::Arc; /// Use this method to edit captions of messages. /// @@ -18,10 +18,10 @@ use crate::{ /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct EditMessageCaption<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct EditMessageCaption { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, caption: Option, @@ -30,7 +30,7 @@ pub struct EditMessageCaption<'a> { } #[async_trait::async_trait] -impl Request for EditMessageCaption<'_> { +impl Request for EditMessageCaption { type Output = Message; async fn send(&self) -> ResponseResult { @@ -44,13 +44,13 @@ impl Request for EditMessageCaption<'_> { } } -impl<'a> EditMessageCaption<'a> { +impl EditMessageCaption { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, caption: None, parse_mode: None, diff --git a/src/requests/all/edit_message_live_location.rs b/src/requests/all/edit_message_live_location.rs index 1362366c..1e6bf9b1 100644 --- a/src/requests/all/edit_message_live_location.rs +++ b/src/requests/all/edit_message_live_location.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, Bot, }; +use std::sync::Arc; /// Use this method to edit live location messages. /// @@ -20,10 +20,10 @@ use crate::{ /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True #[serde_with_macros::skip_serializing_none] -#[derive(PartialEq, Debug, Clone, Serialize)] -pub struct EditMessageLiveLocation<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct EditMessageLiveLocation { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, latitude: f32, @@ -32,7 +32,7 @@ pub struct EditMessageLiveLocation<'a> { } #[async_trait::async_trait] -impl Request for EditMessageLiveLocation<'_> { +impl Request for EditMessageLiveLocation { type Output = Message; async fn send(&self) -> ResponseResult { @@ -46,15 +46,15 @@ impl Request for EditMessageLiveLocation<'_> { } } -impl<'a> EditMessageLiveLocation<'a> { +impl EditMessageLiveLocation { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, latitude: f32, longitude: f32, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, latitude, longitude, diff --git a/src/requests/all/edit_message_media.rs b/src/requests/all/edit_message_media.rs index 685a0356..31cd350d 100644 --- a/src/requests/all/edit_message_media.rs +++ b/src/requests/all/edit_message_media.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message}, Bot, }; +use std::sync::Arc; /// Use this method to edit animation, audio, document, photo, or video /// messages. @@ -20,16 +20,16 @@ use crate::{ /// /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct EditMessageMedia<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct EditMessageMedia { + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, media: InputMedia, reply_markup: Option, } #[async_trait::async_trait] -impl Request for EditMessageMedia<'_> { +impl Request for EditMessageMedia { type Output = Message; async fn send(&self) -> ResponseResult { @@ -67,14 +67,14 @@ impl Request for EditMessageMedia<'_> { } } -impl<'a> EditMessageMedia<'a> { +impl EditMessageMedia { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, media: InputMedia, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, media, reply_markup: None, diff --git a/src/requests/all/edit_message_reply_markup.rs b/src/requests/all/edit_message_reply_markup.rs index 7c7de32e..9b60c224 100644 --- a/src/requests/all/edit_message_reply_markup.rs +++ b/src/requests/all/edit_message_reply_markup.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, Bot, }; +use std::sync::Arc; /// Use this method to edit only the reply markup of messages. /// @@ -18,17 +18,17 @@ use crate::{ /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct EditMessageReplyMarkup<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct EditMessageReplyMarkup { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, reply_markup: Option, } #[async_trait::async_trait] -impl Request for EditMessageReplyMarkup<'_> { +impl Request for EditMessageReplyMarkup { type Output = Message; async fn send(&self) -> ResponseResult { @@ -42,13 +42,13 @@ impl Request for EditMessageReplyMarkup<'_> { } } -impl<'a> EditMessageReplyMarkup<'a> { +impl EditMessageReplyMarkup { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, reply_markup: None, } diff --git a/src/requests/all/edit_message_text.rs b/src/requests/all/edit_message_text.rs index ffe71b4c..d517db38 100644 --- a/src/requests/all/edit_message_text.rs +++ b/src/requests/all/edit_message_text.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode}, Bot, }; +use std::sync::Arc; /// Use this method to edit text and game messages. /// @@ -18,10 +18,10 @@ use crate::{ /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct EditMessageText<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct EditMessageText { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, text: String, @@ -31,7 +31,7 @@ pub struct EditMessageText<'a> { } #[async_trait::async_trait] -impl Request for EditMessageText<'_> { +impl Request for EditMessageText { type Output = Message; async fn send(&self) -> ResponseResult { @@ -45,9 +45,9 @@ impl Request for EditMessageText<'_> { } } -impl<'a> EditMessageText<'a> { +impl EditMessageText { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, text: T, ) -> Self @@ -55,7 +55,7 @@ impl<'a> EditMessageText<'a> { T: Into, { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, text: text.into(), parse_mode: None, diff --git a/src/requests/all/export_chat_invite_link.rs b/src/requests/all/export_chat_invite_link.rs index ec2f93eb..7e31cf96 100644 --- a/src/requests/all/export_chat_invite_link.rs +++ b/src/requests/all/export_chat_invite_link.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::ChatId, Bot, }; +use std::sync::Arc; /// Use this method to generate a new invite link for a chat; any previously /// generated link is revoked. @@ -28,15 +28,15 @@ use crate::{ /// [`Bot::export_chat_invite_link`]: crate::Bot::export_chat_invite_link /// [`Bot::get_chat`]: crate::Bot::get_chat #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct ExportChatInviteLink<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct ExportChatInviteLink { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for ExportChatInviteLink<'_> { +impl Request for ExportChatInviteLink { type Output = String; /// Returns the new invite link as `String` on success. @@ -51,16 +51,13 @@ impl Request for ExportChatInviteLink<'_> { } } -impl<'a> ExportChatInviteLink<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl ExportChatInviteLink { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target channel diff --git a/src/requests/all/forward_message.rs b/src/requests/all/forward_message.rs index 0b765f09..c37b71c6 100644 --- a/src/requests/all/forward_message.rs +++ b/src/requests/all/forward_message.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, Message}, Bot, }; +use std::sync::Arc; /// Use this method to forward messages of any kind. /// /// [`The official docs`](https://core.telegram.org/bots/api#forwardmessage). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct ForwardMessage<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct ForwardMessage { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, from_chat_id: ChatId, disable_notification: Option, @@ -23,7 +23,7 @@ pub struct ForwardMessage<'a> { } #[async_trait::async_trait] -impl Request for ForwardMessage<'_> { +impl Request for ForwardMessage { type Output = Message; async fn send(&self) -> ResponseResult { @@ -37,9 +37,9 @@ impl Request for ForwardMessage<'_> { } } -impl<'a> ForwardMessage<'a> { +impl ForwardMessage { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, from_chat_id: F, message_id: i32, @@ -51,7 +51,7 @@ impl<'a> ForwardMessage<'a> { let chat_id = chat_id.into(); let from_chat_id = from_chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, from_chat_id, message_id, diff --git a/src/requests/all/get_chat.rs b/src/requests/all/get_chat.rs index ce939041..c726908e 100644 --- a/src/requests/all/get_chat.rs +++ b/src/requests/all/get_chat.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{Chat, ChatId}, Bot, }; +use std::sync::Arc; /// Use this method to get up to date information about the chat (current name /// of the user for one-on-one conversations, current username of a user, group @@ -14,15 +14,15 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#getchat). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetChat<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetChat { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for GetChat<'_> { +impl Request for GetChat { type Output = Chat; async fn send(&self) -> ResponseResult { @@ -31,16 +31,13 @@ impl Request for GetChat<'_> { } } -impl<'a> GetChat<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl GetChat { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target diff --git a/src/requests/all/get_chat_administrators.rs b/src/requests/all/get_chat_administrators.rs index bff1adb2..cc575a27 100644 --- a/src/requests/all/get_chat_administrators.rs +++ b/src/requests/all/get_chat_administrators.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, ChatMember}, Bot, }; +use std::sync::Arc; /// Use this method to get a list of administrators in a chat. /// @@ -15,15 +15,15 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#getchatadministrators). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetChatAdministrators<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetChatAdministrators { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for GetChatAdministrators<'_> { +impl Request for GetChatAdministrators { type Output = Vec; /// On success, returns an array that contains information about all chat @@ -39,16 +39,13 @@ impl Request for GetChatAdministrators<'_> { } } -impl<'a> GetChatAdministrators<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl GetChatAdministrators { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target diff --git a/src/requests/all/get_chat_member.rs b/src/requests/all/get_chat_member.rs index e3a4f190..6b5aabea 100644 --- a/src/requests/all/get_chat_member.rs +++ b/src/requests/all/get_chat_member.rs @@ -1,27 +1,27 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, ChatMember}, Bot, }; +use std::sync::Arc; /// Use this method to get information about a member of a chat. /// /// [The official docs](https://core.telegram.org/bots/api#getchatmember). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetChatMember<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetChatMember { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, user_id: i32, } #[async_trait::async_trait] -impl Request for GetChatMember<'_> { +impl Request for GetChatMember { type Output = ChatMember; async fn send(&self) -> ResponseResult { @@ -35,14 +35,14 @@ impl Request for GetChatMember<'_> { } } -impl<'a> GetChatMember<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, user_id: i32) -> Self +impl GetChatMember { + pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, user_id, } diff --git a/src/requests/all/get_chat_members_count.rs b/src/requests/all/get_chat_members_count.rs index 1d5e4c55..89deea55 100644 --- a/src/requests/all/get_chat_members_count.rs +++ b/src/requests/all/get_chat_members_count.rs @@ -1,26 +1,26 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::ChatId, Bot, }; +use std::sync::Arc; /// Use this method to get the number of members in a chat. /// /// [The official docs](https://core.telegram.org/bots/api#getchatmemberscount). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetChatMembersCount<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetChatMembersCount { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for GetChatMembersCount<'_> { +impl Request for GetChatMembersCount { type Output = i32; async fn send(&self) -> ResponseResult { @@ -34,16 +34,13 @@ impl Request for GetChatMembersCount<'_> { } } -impl<'a> GetChatMembersCount<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl GetChatMembersCount { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target diff --git a/src/requests/all/get_file.rs b/src/requests/all/get_file.rs index 4c470827..2694e20f 100644 --- a/src/requests/all/get_file.rs +++ b/src/requests/all/get_file.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::File, Bot, }; +use std::sync::Arc; /// Use this method to get basic info about a file and prepare it for /// downloading. @@ -28,15 +28,15 @@ use crate::{ /// [`File`]: crate::types::file /// [`GetFile`]: self::GetFile #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetFile<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetFile { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, file_id: String, } #[async_trait::async_trait] -impl Request for GetFile<'_> { +impl Request for GetFile { type Output = File; async fn send(&self) -> ResponseResult { @@ -45,13 +45,13 @@ impl Request for GetFile<'_> { } } -impl<'a> GetFile<'a> { - pub(crate) fn new(bot: &'a Bot, file_id: F) -> Self +impl GetFile { + pub(crate) fn new(bot: Arc, file_id: F) -> Self where F: Into, { Self { - bot: BotWrapper(bot), + bot, file_id: file_id.into(), } } diff --git a/src/requests/all/get_game_high_scores.rs b/src/requests/all/get_game_high_scores.rs index 04d43c5d..6026bfef 100644 --- a/src/requests/all/get_game_high_scores.rs +++ b/src/requests/all/get_game_high_scores.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, GameHighScore}, Bot, }; +use std::sync::Arc; /// Use this method to get data for high score tables. /// @@ -21,17 +21,17 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#getgamehighscores). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetGameHighScores<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetGameHighScores { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, user_id: i32, } #[async_trait::async_trait] -impl Request for GetGameHighScores<'_> { +impl Request for GetGameHighScores { type Output = Vec; async fn send(&self) -> ResponseResult> { @@ -45,14 +45,14 @@ impl Request for GetGameHighScores<'_> { } } -impl<'a> GetGameHighScores<'a> { +impl GetGameHighScores { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, user_id, } diff --git a/src/requests/all/get_me.rs b/src/requests/all/get_me.rs index e56ad3b6..857c8a6b 100644 --- a/src/requests/all/get_me.rs +++ b/src/requests/all/get_me.rs @@ -1,4 +1,3 @@ -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, @@ -6,18 +5,19 @@ use crate::{ Bot, }; use serde::Serialize; +use std::sync::Arc; /// A simple method for testing your bot's auth token. Requires no parameters. /// /// [The official docs](https://core.telegram.org/bots/api#getme). -#[derive(Eq, PartialEq, Debug, Clone, Copy, Serialize)] -pub struct GetMe<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetMe { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, } #[async_trait::async_trait] -impl Request for GetMe<'_> { +impl Request for GetMe { type Output = Me; /// Returns basic information about the bot. @@ -28,10 +28,8 @@ impl Request for GetMe<'_> { } } -impl<'a> GetMe<'a> { - pub(crate) fn new(bot: &'a Bot) -> Self { - Self { - bot: BotWrapper(bot), - } +impl GetMe { + pub(crate) fn new(bot: Arc) -> Self { + Self { bot } } } diff --git a/src/requests/all/get_sticker_set.rs b/src/requests/all/get_sticker_set.rs index a63911f8..8b1094a5 100644 --- a/src/requests/all/get_sticker_set.rs +++ b/src/requests/all/get_sticker_set.rs @@ -1,26 +1,26 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::StickerSet, Bot, }; +use std::sync::Arc; /// Use this method to get a sticker set. /// /// [The official docs](https://core.telegram.org/bots/api#getstickerset). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetStickerSet<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetStickerSet { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, name: String, } #[async_trait::async_trait] -impl Request for GetStickerSet<'_> { +impl Request for GetStickerSet { type Output = StickerSet; async fn send(&self) -> ResponseResult { @@ -34,16 +34,13 @@ impl Request for GetStickerSet<'_> { } } -impl<'a> GetStickerSet<'a> { - pub(crate) fn new(bot: &'a Bot, name: N) -> Self +impl GetStickerSet { + pub(crate) fn new(bot: Arc, name: N) -> Self where N: Into, { let name = name.into(); - Self { - bot: BotWrapper(bot), - name, - } + Self { bot, name } } /// Name of the sticker set. diff --git a/src/requests/all/get_updates.rs b/src/requests/all/get_updates.rs index c7311591..2ef81d17 100644 --- a/src/requests/all/get_updates.rs +++ b/src/requests/all/get_updates.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{AllowedUpdate, Update}, Bot, }; +use std::sync::Arc; /// Use this method to receive incoming updates using long polling ([wiki]). /// @@ -19,10 +19,10 @@ use crate::{ /// /// [wiki]: https://en.wikipedia.org/wiki/Push_technology#Long_polling #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetUpdates<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetUpdates { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, pub(crate) offset: Option, pub(crate) limit: Option, pub(crate) timeout: Option, @@ -30,7 +30,7 @@ pub struct GetUpdates<'a> { } #[async_trait::async_trait] -impl Request for GetUpdates<'_> { +impl Request for GetUpdates { type Output = Vec; async fn send(&self) -> ResponseResult> { @@ -44,10 +44,10 @@ impl Request for GetUpdates<'_> { } } -impl<'a> GetUpdates<'a> { - pub(crate) fn new(bot: &'a Bot) -> Self { +impl GetUpdates { + pub(crate) fn new(bot: Arc) -> Self { Self { - bot: BotWrapper(bot), + bot, offset: None, limit: None, timeout: None, diff --git a/src/requests/all/get_user_profile_photos.rs b/src/requests/all/get_user_profile_photos.rs index bc9b79c3..c3939104 100644 --- a/src/requests/all/get_user_profile_photos.rs +++ b/src/requests/all/get_user_profile_photos.rs @@ -1,28 +1,28 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::UserProfilePhotos, Bot, }; +use std::sync::Arc; /// Use this method to get a list of profile pictures for a user. /// /// [The official docs](https://core.telegram.org/bots/api#getuserprofilephotos). #[serde_with_macros::skip_serializing_none] -#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetUserProfilePhotos<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetUserProfilePhotos { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, user_id: i32, offset: Option, limit: Option, } #[async_trait::async_trait] -impl Request for GetUserProfilePhotos<'_> { +impl Request for GetUserProfilePhotos { type Output = UserProfilePhotos; async fn send(&self) -> ResponseResult { @@ -36,10 +36,10 @@ impl Request for GetUserProfilePhotos<'_> { } } -impl<'a> GetUserProfilePhotos<'a> { - pub(crate) fn new(bot: &'a Bot, user_id: i32) -> Self { +impl GetUserProfilePhotos { + pub(crate) fn new(bot: Arc, user_id: i32) -> Self { Self { - bot: BotWrapper(bot), + bot, user_id, offset: None, limit: None, diff --git a/src/requests/all/get_webhook_info.rs b/src/requests/all/get_webhook_info.rs index 88fa92f5..99ece7ea 100644 --- a/src/requests/all/get_webhook_info.rs +++ b/src/requests/all/get_webhook_info.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::WebhookInfo, Bot, }; +use std::sync::Arc; /// Use this method to get current webhook status. /// @@ -16,14 +16,14 @@ use crate::{ /// [The official docs](https://core.telegram.org/bots/api#getwebhookinfo). /// /// [`Bot::get_updates`]: crate::Bot::get_updates -#[derive(Copy, Eq, PartialEq, Debug, Clone, Serialize)] -pub struct GetWebhookInfo<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct GetWebhookInfo { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, } #[async_trait::async_trait] -impl Request for GetWebhookInfo<'_> { +impl Request for GetWebhookInfo { type Output = WebhookInfo; #[allow(clippy::trivially_copy_pass_by_ref)] @@ -38,10 +38,8 @@ impl Request for GetWebhookInfo<'_> { } } -impl<'a> GetWebhookInfo<'a> { - pub(crate) fn new(bot: &'a Bot) -> Self { - Self { - bot: BotWrapper(bot), - } +impl GetWebhookInfo { + pub(crate) fn new(bot: Arc) -> Self { + Self { bot } } } diff --git a/src/requests/all/kick_chat_member.rs b/src/requests/all/kick_chat_member.rs index c766071f..fb02d384 100644 --- a/src/requests/all/kick_chat_member.rs +++ b/src/requests/all/kick_chat_member.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to kick a user from a group, a supergroup or a channel. /// @@ -19,17 +19,17 @@ use crate::{ /// /// [unbanned]: crate::Bot::unban_chat_member #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct KickChatMember<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct KickChatMember { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, user_id: i32, until_date: Option, } #[async_trait::async_trait] -impl Request for KickChatMember<'_> { +impl Request for KickChatMember { type Output = True; async fn send(&self) -> ResponseResult { @@ -43,14 +43,14 @@ impl Request for KickChatMember<'_> { } } -impl<'a> KickChatMember<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, user_id: i32) -> Self +impl KickChatMember { + pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, user_id, until_date: None, diff --git a/src/requests/all/leave_chat.rs b/src/requests/all/leave_chat.rs index a0ccd4b4..d2dc5f14 100644 --- a/src/requests/all/leave_chat.rs +++ b/src/requests/all/leave_chat.rs @@ -1,26 +1,26 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method for your bot to leave a group, supergroup or channel. /// /// [The official docs](https://core.telegram.org/bots/api#leavechat). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct LeaveChat<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct LeaveChat { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for LeaveChat<'_> { +impl Request for LeaveChat { type Output = True; async fn send(&self) -> ResponseResult { @@ -34,16 +34,13 @@ impl Request for LeaveChat<'_> { } } -impl<'a> LeaveChat<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl LeaveChat { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target diff --git a/src/requests/all/mod.rs b/src/requests/all/mod.rs index 84acc2e1..7d8e6845 100644 --- a/src/requests/all/mod.rs +++ b/src/requests/all/mod.rs @@ -130,6 +130,3 @@ pub use stop_poll::*; pub use unban_chat_member::*; pub use unpin_chat_message::*; pub use upload_sticker_file::*; - -mod bot_wrapper; -use bot_wrapper::BotWrapper; diff --git a/src/requests/all/pin_chat_message.rs b/src/requests/all/pin_chat_message.rs index 6be8c7cf..256ddef1 100644 --- a/src/requests/all/pin_chat_message.rs +++ b/src/requests/all/pin_chat_message.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to pin a message in a group, a supergroup, or a channel. /// @@ -16,17 +16,17 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#pinchatmessage). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct PinChatMessage<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct PinChatMessage { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, message_id: i32, disable_notification: Option, } #[async_trait::async_trait] -impl Request for PinChatMessage<'_> { +impl Request for PinChatMessage { type Output = True; async fn send(&self) -> ResponseResult { @@ -40,14 +40,14 @@ impl Request for PinChatMessage<'_> { } } -impl<'a> PinChatMessage<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, message_id: i32) -> Self +impl PinChatMessage { + pub(crate) fn new(bot: Arc, chat_id: C, message_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, message_id, disable_notification: None, diff --git a/src/requests/all/promote_chat_member.rs b/src/requests/all/promote_chat_member.rs index ddd46e93..32919b0f 100644 --- a/src/requests/all/promote_chat_member.rs +++ b/src/requests/all/promote_chat_member.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to promote or demote a user in a supergroup or a channel. /// @@ -16,10 +16,10 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#promotechatmember). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct PromoteChatMember<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct PromoteChatMember { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, user_id: i32, can_change_info: Option, @@ -33,7 +33,7 @@ pub struct PromoteChatMember<'a> { } #[async_trait::async_trait] -impl Request for PromoteChatMember<'_> { +impl Request for PromoteChatMember { type Output = True; async fn send(&self) -> ResponseResult { @@ -47,14 +47,14 @@ impl Request for PromoteChatMember<'_> { } } -impl<'a> PromoteChatMember<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, user_id: i32) -> Self +impl PromoteChatMember { + pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, user_id, can_change_info: None, diff --git a/src/requests/all/restrict_chat_member.rs b/src/requests/all/restrict_chat_member.rs index 918571a6..90dda304 100644 --- a/src/requests/all/restrict_chat_member.rs +++ b/src/requests/all/restrict_chat_member.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, ChatPermissions, True}, Bot, }; +use std::sync::Arc; /// Use this method to restrict a user in a supergroup. /// @@ -16,10 +16,10 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#restrictchatmember). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct RestrictChatMember<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct RestrictChatMember { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, user_id: i32, permissions: ChatPermissions, @@ -27,7 +27,7 @@ pub struct RestrictChatMember<'a> { } #[async_trait::async_trait] -impl Request for RestrictChatMember<'_> { +impl Request for RestrictChatMember { type Output = True; async fn send(&self) -> ResponseResult { @@ -41,9 +41,9 @@ impl Request for RestrictChatMember<'_> { } } -impl<'a> RestrictChatMember<'a> { +impl RestrictChatMember { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, user_id: i32, permissions: ChatPermissions, @@ -53,7 +53,7 @@ impl<'a> RestrictChatMember<'a> { { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, user_id, permissions, diff --git a/src/requests/all/send_animation.rs b/src/requests/all/send_animation.rs index 1584cc16..cbd40485 100644 --- a/src/requests/all/send_animation.rs +++ b/src/requests/all/send_animation.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video /// without sound). @@ -13,9 +13,9 @@ use crate::{ /// may be changed in the future. /// /// [The official docs](https://core.telegram.org/bots/api#sendanimation). -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendAnimation<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendAnimation { + bot: Arc, pub chat_id: ChatId, pub animation: InputFile, pub duration: Option, @@ -30,7 +30,7 @@ pub struct SendAnimation<'a> { } #[async_trait::async_trait] -impl Request for SendAnimation<'_> { +impl Request for SendAnimation { type Output = Message; async fn send(&self) -> ResponseResult { @@ -67,13 +67,17 @@ impl Request for SendAnimation<'_> { } } -impl<'a> SendAnimation<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, animation: InputFile) -> Self +impl SendAnimation { + pub(crate) fn new( + bot: Arc, + chat_id: C, + animation: InputFile, + ) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), animation, duration: None, diff --git a/src/requests/all/send_audio.rs b/src/requests/all/send_audio.rs index 9be59300..829e41f9 100644 --- a/src/requests/all/send_audio.rs +++ b/src/requests/all/send_audio.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send audio files, if you want Telegram clients to display /// them in the music player. @@ -17,9 +17,9 @@ use crate::{ /// [The official docs](https://core.telegram.org/bots/api#sendaudio). /// /// [`Bot::send_voice`]: crate::Bot::send_voice -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendAudio<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendAudio { + bot: Arc, chat_id: ChatId, audio: InputFile, caption: Option, @@ -34,7 +34,7 @@ pub struct SendAudio<'a> { } #[async_trait::async_trait] -impl Request for SendAudio<'_> { +impl Request for SendAudio { type Output = Message; async fn send(&self) -> ResponseResult { @@ -71,13 +71,13 @@ impl Request for SendAudio<'_> { } } -impl<'a> SendAudio<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, audio: InputFile) -> Self +impl SendAudio { + pub(crate) fn new(bot: Arc, chat_id: C, audio: InputFile) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), audio, caption: None, diff --git a/src/requests/all/send_chat_action.rs b/src/requests/all/send_chat_action.rs index 6718ae8f..1d7b0032 100644 --- a/src/requests/all/send_chat_action.rs +++ b/src/requests/all/send_chat_action.rs @@ -1,12 +1,12 @@ use serde::{Deserialize, Serialize}; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method when you need to tell the user that something is happening /// on the bot's side. @@ -26,10 +26,10 @@ use crate::{ /// [ImageBot]: https://t.me/imagebot /// [`Bot::send_chat_action`]: crate::Bot::send_chat_action #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SendChatAction<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendChatAction { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, action: SendChatActionKind, } @@ -37,7 +37,7 @@ pub struct SendChatAction<'a> { /// A type of action used in [`SendChatAction`]. /// /// [`SendChatAction`]: crate::requests::SendChatAction -#[derive(PartialEq, Copy, Clone, Debug, Eq, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum SendChatActionKind { /// For [text messages](crate::Bot::send_message). @@ -72,7 +72,7 @@ pub enum SendChatActionKind { } #[async_trait::async_trait] -impl Request for SendChatAction<'_> { +impl Request for SendChatAction { type Output = True; async fn send(&self) -> ResponseResult { @@ -86,9 +86,9 @@ impl Request for SendChatAction<'_> { } } -impl<'a> SendChatAction<'a> { +impl SendChatAction { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, action: SendChatActionKind, ) -> Self @@ -96,7 +96,7 @@ impl<'a> SendChatAction<'a> { C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), action, } diff --git a/src/requests/all/send_contact.rs b/src/requests/all/send_contact.rs index 97cda878..1ad6d0b6 100644 --- a/src/requests/all/send_contact.rs +++ b/src/requests/all/send_contact.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, Message, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send phone contacts. /// /// [The official docs](https://core.telegram.org/bots/api#sendcontact). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SendContact<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendContact { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, phone_number: String, first_name: String, @@ -27,7 +27,7 @@ pub struct SendContact<'a> { } #[async_trait::async_trait] -impl Request for SendContact<'_> { +impl Request for SendContact { type Output = Message; async fn send(&self) -> ResponseResult { @@ -41,9 +41,9 @@ impl Request for SendContact<'_> { } } -impl<'a> SendContact<'a> { +impl SendContact { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, phone_number: P, first_name: F, @@ -57,7 +57,7 @@ impl<'a> SendContact<'a> { let phone_number = phone_number.into(); let first_name = first_name.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, phone_number, first_name, diff --git a/src/requests/all/send_document.rs b/src/requests/all/send_document.rs index a2175156..3e2cfd46 100644 --- a/src/requests/all/send_document.rs +++ b/src/requests/all/send_document.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send general files. /// @@ -12,9 +12,9 @@ use crate::{ /// may be changed in the future. /// /// [The official docs](https://core.telegram.org/bots/api#senddocument). -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendDocument<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendDocument { + bot: Arc, chat_id: ChatId, document: InputFile, thumb: Option, @@ -26,7 +26,7 @@ pub struct SendDocument<'a> { } #[async_trait::async_trait] -impl Request for SendDocument<'_> { +impl Request for SendDocument { type Output = Message; async fn send(&self) -> ResponseResult { @@ -57,13 +57,13 @@ impl Request for SendDocument<'_> { } } -impl<'a> SendDocument<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, document: InputFile) -> Self +impl SendDocument { + pub(crate) fn new(bot: Arc, chat_id: C, document: InputFile) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), document, thumb: None, diff --git a/src/requests/all/send_game.rs b/src/requests/all/send_game.rs index bc3056aa..53555c06 100644 --- a/src/requests/all/send_game.rs +++ b/src/requests/all/send_game.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{InlineKeyboardMarkup, Message}, Bot, }; +use std::sync::Arc; /// Use this method to send a game. /// /// [The official docs](https://core.telegram.org/bots/api#sendgame). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SendGame<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendGame { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: i32, game_short_name: String, disable_notification: Option, @@ -24,7 +24,7 @@ pub struct SendGame<'a> { } #[async_trait::async_trait] -impl Request for SendGame<'_> { +impl Request for SendGame { type Output = Message; async fn send(&self) -> ResponseResult { @@ -38,14 +38,18 @@ impl Request for SendGame<'_> { } } -impl<'a> SendGame<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: i32, game_short_name: G) -> Self +impl SendGame { + pub(crate) fn new( + bot: Arc, + chat_id: i32, + game_short_name: G, + ) -> Self where G: Into, { let game_short_name = game_short_name.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, game_short_name, disable_notification: None, diff --git a/src/requests/all/send_invoice.rs b/src/requests/all/send_invoice.rs index 99fbab15..b9e710e3 100644 --- a/src/requests/all/send_invoice.rs +++ b/src/requests/all/send_invoice.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{InlineKeyboardMarkup, LabeledPrice, Message}, Bot, }; +use std::sync::Arc; /// Use this method to send invoices. /// /// [The official docs](https://core.telegram.org/bots/api#sendinvoice). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SendInvoice<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendInvoice { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: i32, title: String, description: String, @@ -42,7 +42,7 @@ pub struct SendInvoice<'a> { } #[async_trait::async_trait] -impl Request for SendInvoice<'_> { +impl Request for SendInvoice { type Output = Message; async fn send(&self) -> ResponseResult { @@ -56,10 +56,10 @@ impl Request for SendInvoice<'_> { } } -impl<'a> SendInvoice<'a> { +impl SendInvoice { #[allow(clippy::too_many_arguments)] pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: i32, title: T, description: D, @@ -86,7 +86,7 @@ impl<'a> SendInvoice<'a> { let currency = currency.into(); let prices = prices.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, title, description, diff --git a/src/requests/all/send_location.rs b/src/requests/all/send_location.rs index 6ce4060e..149d7a5c 100644 --- a/src/requests/all/send_location.rs +++ b/src/requests/all/send_location.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, Message, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send point on the map. /// /// [The official docs](https://core.telegram.org/bots/api#sendlocation). #[serde_with_macros::skip_serializing_none] -#[derive(PartialEq, Debug, Clone, Serialize)] -pub struct SendLocation<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendLocation { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, latitude: f32, longitude: f32, @@ -26,7 +26,7 @@ pub struct SendLocation<'a> { } #[async_trait::async_trait] -impl Request for SendLocation<'_> { +impl Request for SendLocation { type Output = Message; async fn send(&self) -> ResponseResult { @@ -40,9 +40,9 @@ impl Request for SendLocation<'_> { } } -impl<'a> SendLocation<'a> { +impl SendLocation { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, latitude: f32, longitude: f32, @@ -52,7 +52,7 @@ impl<'a> SendLocation<'a> { { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, latitude, longitude, diff --git a/src/requests/all/send_media_group.rs b/src/requests/all/send_media_group.rs index 6576da97..cae6604d 100644 --- a/src/requests/all/send_media_group.rs +++ b/src/requests/all/send_media_group.rs @@ -1,17 +1,17 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputMedia, Message}, Bot, }; +use std::sync::Arc; /// Use this method to send a group of photos or videos as an album. /// /// [The official docs](https://core.telegram.org/bots/api#sendmediagroup). -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendMediaGroup<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendMediaGroup { + bot: Arc, chat_id: ChatId, media: Vec, // TODO: InputMediaPhoto and InputMediaVideo disable_notification: Option, @@ -19,7 +19,7 @@ pub struct SendMediaGroup<'a> { } #[async_trait::async_trait] -impl Request for SendMediaGroup<'_> { +impl Request for SendMediaGroup { type Output = Vec; async fn send(&self) -> ResponseResult> { @@ -42,8 +42,8 @@ impl Request for SendMediaGroup<'_> { } } -impl<'a> SendMediaGroup<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, media: M) -> Self +impl SendMediaGroup { + pub(crate) fn new(bot: Arc, chat_id: C, media: M) -> Self where C: Into, M: Into>, @@ -51,7 +51,7 @@ impl<'a> SendMediaGroup<'a> { let chat_id = chat_id.into(); let media = media.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, media, disable_notification: None, diff --git a/src/requests/all/send_message.rs b/src/requests/all/send_message.rs index f19792fe..689d9671 100644 --- a/src/requests/all/send_message.rs +++ b/src/requests/all/send_message.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send text messages. /// /// [The official docs](https://core.telegram.org/bots/api#sendmessage). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SendMessage<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendMessage { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, pub chat_id: ChatId, pub text: String, pub parse_mode: Option, @@ -26,7 +26,7 @@ pub struct SendMessage<'a> { } #[async_trait::async_trait] -impl Request for SendMessage<'_> { +impl Request for SendMessage { type Output = Message; async fn send(&self) -> ResponseResult { @@ -40,14 +40,14 @@ impl Request for SendMessage<'_> { } } -impl<'a> SendMessage<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, text: T) -> Self +impl SendMessage { + pub(crate) fn new(bot: Arc, chat_id: C, text: T) -> Self where C: Into, T: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), text: text.into(), parse_mode: None, diff --git a/src/requests/all/send_photo.rs b/src/requests/all/send_photo.rs index e75580a3..ea603eca 100644 --- a/src/requests/all/send_photo.rs +++ b/src/requests/all/send_photo.rs @@ -1,17 +1,17 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send photos. /// /// [The official docs](https://core.telegram.org/bots/api#sendphoto). -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendPhoto<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendPhoto { + bot: Arc, chat_id: ChatId, photo: InputFile, caption: Option, @@ -22,7 +22,7 @@ pub struct SendPhoto<'a> { } #[async_trait::async_trait] -impl Request for SendPhoto<'_> { +impl Request for SendPhoto { type Output = Message; async fn send(&self) -> ResponseResult { @@ -51,13 +51,13 @@ impl Request for SendPhoto<'_> { } } -impl<'a> SendPhoto<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, photo: InputFile) -> Self +impl SendPhoto { + pub(crate) fn new(bot: Arc, chat_id: C, photo: InputFile) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), photo, caption: None, diff --git a/src/requests/all/send_poll.rs b/src/requests/all/send_poll.rs index 657b430a..a2fafd42 100644 --- a/src/requests/all/send_poll.rs +++ b/src/requests/all/send_poll.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, Message, PollType, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send a native poll. /// /// [The official docs](https://core.telegram.org/bots/api#sendpoll). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SendPoll<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendPoll { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, question: String, options: Vec, @@ -30,7 +30,7 @@ pub struct SendPoll<'a> { } #[async_trait::async_trait] -impl Request for SendPoll<'_> { +impl Request for SendPoll { type Output = Message; async fn send(&self) -> ResponseResult { @@ -44,9 +44,9 @@ impl Request for SendPoll<'_> { } } -impl<'a> SendPoll<'a> { +impl SendPoll { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, question: Q, options: O, @@ -60,7 +60,7 @@ impl<'a> SendPoll<'a> { let question = question.into(); let options = options.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, question, options, diff --git a/src/requests/all/send_sticker.rs b/src/requests/all/send_sticker.rs index 1cf07e23..e44dbb80 100644 --- a/src/requests/all/send_sticker.rs +++ b/src/requests/all/send_sticker.rs @@ -1,19 +1,19 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send static .WEBP or [animated] .TGS stickers. /// /// [The official docs](https://core.telegram.org/bots/api#sendsticker). /// /// [animated]: https://telegram.org/blog/animated-stickers -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendSticker<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendSticker { + bot: Arc, chat_id: ChatId, sticker: InputFile, disable_notification: Option, @@ -22,7 +22,7 @@ pub struct SendSticker<'a> { } #[async_trait::async_trait] -impl Request for SendSticker<'_> { +impl Request for SendSticker { type Output = Message; async fn send(&self) -> ResponseResult { @@ -47,13 +47,13 @@ impl Request for SendSticker<'_> { } } -impl<'a> SendSticker<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, sticker: InputFile) -> Self +impl SendSticker { + pub(crate) fn new(bot: Arc, chat_id: C, sticker: InputFile) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), sticker, disable_notification: None, diff --git a/src/requests/all/send_venue.rs b/src/requests/all/send_venue.rs index c0d06765..c049aeb2 100644 --- a/src/requests/all/send_venue.rs +++ b/src/requests/all/send_venue.rs @@ -1,21 +1,21 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, Message, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send information about a venue. /// /// [The official docs](https://core.telegram.org/bots/api#sendvenue). #[serde_with_macros::skip_serializing_none] -#[derive(PartialEq, Debug, Clone, Serialize)] -pub struct SendVenue<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SendVenue { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, latitude: f32, longitude: f32, @@ -29,7 +29,7 @@ pub struct SendVenue<'a> { } #[async_trait::async_trait] -impl Request for SendVenue<'_> { +impl Request for SendVenue { type Output = Message; async fn send(&self) -> ResponseResult { @@ -43,9 +43,9 @@ impl Request for SendVenue<'_> { } } -impl<'a> SendVenue<'a> { +impl SendVenue { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, latitude: f32, longitude: f32, @@ -61,7 +61,7 @@ impl<'a> SendVenue<'a> { let title = title.into(); let address = address.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, latitude, longitude, diff --git a/src/requests/all/send_video.rs b/src/requests/all/send_video.rs index 1671ad7c..8e89ef2e 100644 --- a/src/requests/all/send_video.rs +++ b/src/requests/all/send_video.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send video files, Telegram clients support mp4 videos /// (other formats may be sent as Document). @@ -13,9 +13,9 @@ use crate::{ /// limit may be changed in the future. /// /// [The official docs](https://core.telegram.org/bots/api#sendvideo). -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendVideo<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendVideo { + bot: Arc, chat_id: ChatId, video: InputFile, duration: Option, @@ -31,7 +31,7 @@ pub struct SendVideo<'a> { } #[async_trait::async_trait] -impl Request for SendVideo<'_> { +impl Request for SendVideo { type Output = Message; async fn send(&self) -> ResponseResult { @@ -70,13 +70,13 @@ impl Request for SendVideo<'_> { } } -impl<'a> SendVideo<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, video: InputFile) -> Self +impl SendVideo { + pub(crate) fn new(bot: Arc, chat_id: C, video: InputFile) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), video, duration: None, diff --git a/src/requests/all/send_video_note.rs b/src/requests/all/send_video_note.rs index fbed9bbb..e3099c35 100644 --- a/src/requests/all/send_video_note.rs +++ b/src/requests/all/send_video_note.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// As of [v.4.0], Telegram clients support rounded square mp4 videos of up to 1 /// minute long. Use this method to send video messages. @@ -12,9 +12,9 @@ use crate::{ /// [The official docs](https://core.telegram.org/bots/api#sendvideonote). /// /// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendVideoNote<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendVideoNote { + bot: Arc, chat_id: ChatId, video_note: InputFile, duration: Option, @@ -26,7 +26,7 @@ pub struct SendVideoNote<'a> { } #[async_trait::async_trait] -impl Request for SendVideoNote<'_> { +impl Request for SendVideoNote { type Output = Message; async fn send(&self) -> ResponseResult { @@ -57,9 +57,9 @@ impl Request for SendVideoNote<'_> { } } -impl<'a> SendVideoNote<'a> { +impl SendVideoNote { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, video_note: InputFile, ) -> Self @@ -67,7 +67,7 @@ impl<'a> SendVideoNote<'a> { C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), video_note, duration: None, diff --git a/src/requests/all/send_voice.rs b/src/requests/all/send_voice.rs index 00df1764..b5ef7b5d 100644 --- a/src/requests/all/send_voice.rs +++ b/src/requests/all/send_voice.rs @@ -1,10 +1,10 @@ -use super::BotWrapper; use crate::{ net, requests::{form_builder::FormBuilder, Request, ResponseResult}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; +use std::sync::Arc; /// Use this method to send audio files, if you want Telegram clients to display /// the file as a playable voice message. @@ -18,9 +18,9 @@ use crate::{ /// /// [`Audio`]: crate::types::Audio /// [`Document`]: crate::types::Document -#[derive(Eq, PartialEq, Debug, Clone)] -pub struct SendVoice<'a> { - bot: BotWrapper<'a>, +#[derive(Debug, Clone)] +pub struct SendVoice { + bot: Arc, chat_id: ChatId, voice: InputFile, caption: Option, @@ -32,7 +32,7 @@ pub struct SendVoice<'a> { } #[async_trait::async_trait] -impl Request for SendVoice<'_> { +impl Request for SendVoice { type Output = Message; async fn send(&self) -> ResponseResult { @@ -63,13 +63,13 @@ impl Request for SendVoice<'_> { } } -impl<'a> SendVoice<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, voice: InputFile) -> Self +impl SendVoice { + pub(crate) fn new(bot: Arc, chat_id: C, voice: InputFile) -> Self where C: Into, { Self { - bot: BotWrapper(bot), + bot, chat_id: chat_id.into(), voice, caption: None, diff --git a/src/requests/all/set_chat_administrator_custom_title.rs b/src/requests/all/set_chat_administrator_custom_title.rs index 94370bef..322f72f7 100644 --- a/src/requests/all/set_chat_administrator_custom_title.rs +++ b/src/requests/all/set_chat_administrator_custom_title.rs @@ -1,29 +1,29 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to set a custom title for an administrator in a supergroup /// promoted by the bot. /// /// [The official docs](https://core.telegram.org/bots/api#setchatadministratorcustomtitle). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetChatAdministratorCustomTitle<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetChatAdministratorCustomTitle { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, user_id: i32, custom_title: String, } #[async_trait::async_trait] -impl Request for SetChatAdministratorCustomTitle<'_> { +impl Request for SetChatAdministratorCustomTitle { type Output = True; async fn send(&self) -> ResponseResult { @@ -37,9 +37,9 @@ impl Request for SetChatAdministratorCustomTitle<'_> { } } -impl<'a> SetChatAdministratorCustomTitle<'a> { +impl SetChatAdministratorCustomTitle { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, user_id: i32, custom_title: CT, @@ -51,7 +51,7 @@ impl<'a> SetChatAdministratorCustomTitle<'a> { let chat_id = chat_id.into(); let custom_title = custom_title.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, user_id, custom_title, diff --git a/src/requests/all/set_chat_description.rs b/src/requests/all/set_chat_description.rs index 2c731483..5896584e 100644 --- a/src/requests/all/set_chat_description.rs +++ b/src/requests/all/set_chat_description.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to change the description of a group, a supergroup or a /// channel. @@ -16,16 +16,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#setchatdescription). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetChatDescription<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetChatDescription { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, description: Option, } #[async_trait::async_trait] -impl Request for SetChatDescription<'_> { +impl Request for SetChatDescription { type Output = True; async fn send(&self) -> ResponseResult { @@ -39,14 +39,14 @@ impl Request for SetChatDescription<'_> { } } -impl<'a> SetChatDescription<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl SetChatDescription { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, description: None, } diff --git a/src/requests/all/set_chat_permissions.rs b/src/requests/all/set_chat_permissions.rs index 2a16f863..4dec39f8 100644 --- a/src/requests/all/set_chat_permissions.rs +++ b/src/requests/all/set_chat_permissions.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, ChatPermissions, True}, Bot, }; +use std::sync::Arc; /// Use this method to set default chat permissions for all members. /// @@ -15,16 +15,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#setchatpermissions). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetChatPermissions<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetChatPermissions { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, permissions: ChatPermissions, } #[async_trait::async_trait] -impl Request for SetChatPermissions<'_> { +impl Request for SetChatPermissions { type Output = True; async fn send(&self) -> ResponseResult { @@ -38,9 +38,9 @@ impl Request for SetChatPermissions<'_> { } } -impl<'a> SetChatPermissions<'a> { +impl SetChatPermissions { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, permissions: ChatPermissions, ) -> Self @@ -49,7 +49,7 @@ impl<'a> SetChatPermissions<'a> { { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, permissions, } diff --git a/src/requests/all/set_chat_photo.rs b/src/requests/all/set_chat_photo.rs index 4279c7b1..0d152b4d 100644 --- a/src/requests/all/set_chat_photo.rs +++ b/src/requests/all/set_chat_photo.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, InputFile, True}, Bot, }; +use std::sync::Arc; /// Use this method to set a new profile photo for the chat. /// @@ -15,16 +15,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#setchatphoto). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetChatPhoto<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetChatPhoto { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, photo: InputFile, } #[async_trait::async_trait] -impl Request for SetChatPhoto<'_> { +impl Request for SetChatPhoto { type Output = True; async fn send(&self) -> ResponseResult { @@ -38,14 +38,14 @@ impl Request for SetChatPhoto<'_> { } } -impl<'a> SetChatPhoto<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, photo: InputFile) -> Self +impl SetChatPhoto { + pub(crate) fn new(bot: Arc, chat_id: C, photo: InputFile) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, photo, } diff --git a/src/requests/all/set_chat_sticker_set.rs b/src/requests/all/set_chat_sticker_set.rs index 1b2874e4..64d37017 100644 --- a/src/requests/all/set_chat_sticker_set.rs +++ b/src/requests/all/set_chat_sticker_set.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to set a new group sticker set for a supergroup. /// @@ -16,16 +16,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#setchatstickerset). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetChatStickerSet<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetChatStickerSet { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, sticker_set_name: String, } #[async_trait::async_trait] -impl Request for SetChatStickerSet<'_> { +impl Request for SetChatStickerSet { type Output = True; async fn send(&self) -> ResponseResult { @@ -39,9 +39,9 @@ impl Request for SetChatStickerSet<'_> { } } -impl<'a> SetChatStickerSet<'a> { +impl SetChatStickerSet { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_id: C, sticker_set_name: S, ) -> Self @@ -52,7 +52,7 @@ impl<'a> SetChatStickerSet<'a> { let chat_id = chat_id.into(); let sticker_set_name = sticker_set_name.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, sticker_set_name, } diff --git a/src/requests/all/set_chat_title.rs b/src/requests/all/set_chat_title.rs index 7b5349fa..6e05fc64 100644 --- a/src/requests/all/set_chat_title.rs +++ b/src/requests/all/set_chat_title.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to change the title of a chat. /// @@ -15,16 +15,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#setchattitle). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetChatTitle<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetChatTitle { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, title: String, } #[async_trait::async_trait] -impl Request for SetChatTitle<'_> { +impl Request for SetChatTitle { type Output = True; async fn send(&self) -> ResponseResult { @@ -38,8 +38,8 @@ impl Request for SetChatTitle<'_> { } } -impl<'a> SetChatTitle<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, title: T) -> Self +impl SetChatTitle { + pub(crate) fn new(bot: Arc, chat_id: C, title: T) -> Self where C: Into, T: Into, @@ -47,7 +47,7 @@ impl<'a> SetChatTitle<'a> { let chat_id = chat_id.into(); let title = title.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, title, } diff --git a/src/requests/all/set_game_score.rs b/src/requests/all/set_game_score.rs index e21152d6..679ca708 100644 --- a/src/requests/all/set_game_score.rs +++ b/src/requests/all/set_game_score.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, Message}, Bot, }; +use std::sync::Arc; /// Use this method to set the score of the specified user in a game. /// @@ -20,10 +20,10 @@ use crate::{ /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetGameScore<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetGameScore { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, user_id: i32, @@ -33,7 +33,7 @@ pub struct SetGameScore<'a> { } #[async_trait::async_trait] -impl Request for SetGameScore<'_> { +impl Request for SetGameScore { type Output = Message; async fn send(&self) -> ResponseResult { @@ -47,15 +47,15 @@ impl Request for SetGameScore<'_> { } } -impl<'a> SetGameScore<'a> { +impl SetGameScore { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, score: i32, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, user_id, score, diff --git a/src/requests/all/set_sticker_position_in_set.rs b/src/requests/all/set_sticker_position_in_set.rs index 11dfeceb..7bcea444 100644 --- a/src/requests/all/set_sticker_position_in_set.rs +++ b/src/requests/all/set_sticker_position_in_set.rs @@ -1,28 +1,28 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::True, Bot, }; +use std::sync::Arc; /// Use this method to move a sticker in a set created by the bot to a specific /// position. /// /// [The official docs](https://core.telegram.org/bots/api#setstickerpositioninset). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetStickerPositionInSet<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetStickerPositionInSet { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, sticker: String, position: i32, } #[async_trait::async_trait] -impl Request for SetStickerPositionInSet<'_> { +impl Request for SetStickerPositionInSet { type Output = True; async fn send(&self) -> ResponseResult { @@ -36,14 +36,14 @@ impl Request for SetStickerPositionInSet<'_> { } } -impl<'a> SetStickerPositionInSet<'a> { - pub(crate) fn new(bot: &'a Bot, sticker: S, position: i32) -> Self +impl SetStickerPositionInSet { + pub(crate) fn new(bot: Arc, sticker: S, position: i32) -> Self where S: Into, { let sticker = sticker.into(); Self { - bot: BotWrapper(bot), + bot, sticker, position, } diff --git a/src/requests/all/set_webhook.rs b/src/requests/all/set_webhook.rs index 1233e0cf..ad293b5c 100644 --- a/src/requests/all/set_webhook.rs +++ b/src/requests/all/set_webhook.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{AllowedUpdate, InputFile, True}, Bot, }; +use std::sync::Arc; /// Use this method to specify a url and receive incoming updates via an /// outgoing webhook. @@ -25,10 +25,10 @@ use crate::{ /// /// [`Update`]: crate::types::Update #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct SetWebhook<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct SetWebhook { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, url: String, certificate: Option, max_connections: Option, @@ -36,7 +36,7 @@ pub struct SetWebhook<'a> { } #[async_trait::async_trait] -impl Request for SetWebhook<'_> { +impl Request for SetWebhook { type Output = True; async fn send(&self) -> ResponseResult { @@ -50,14 +50,14 @@ impl Request for SetWebhook<'_> { } } -impl<'a> SetWebhook<'a> { - pub(crate) fn new(bot: &'a Bot, url: U) -> Self +impl SetWebhook { + pub(crate) fn new(bot: Arc, url: U) -> Self where U: Into, { let url = url.into(); Self { - bot: BotWrapper(bot), + bot, url, certificate: None, max_connections: None, diff --git a/src/requests/all/stop_message_live_location.rs b/src/requests/all/stop_message_live_location.rs index 859a3a84..2c970b2b 100644 --- a/src/requests/all/stop_message_live_location.rs +++ b/src/requests/all/stop_message_live_location.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, Bot, }; +use std::sync::Arc; /// Use this method to stop updating a live location message before /// `live_period` expires. @@ -19,17 +19,17 @@ use crate::{ /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct StopMessageLiveLocation<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct StopMessageLiveLocation { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, reply_markup: Option, } #[async_trait::async_trait] -impl Request for StopMessageLiveLocation<'_> { +impl Request for StopMessageLiveLocation { type Output = Message; async fn send(&self) -> ResponseResult { @@ -43,13 +43,13 @@ impl Request for StopMessageLiveLocation<'_> { } } -impl<'a> StopMessageLiveLocation<'a> { +impl StopMessageLiveLocation { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, chat_or_inline_message: ChatOrInlineMessage, ) -> Self { Self { - bot: BotWrapper(bot), + bot, chat_or_inline_message, reply_markup: None, } diff --git a/src/requests/all/stop_poll.rs b/src/requests/all/stop_poll.rs index 6e99b6c5..f0d97b48 100644 --- a/src/requests/all/stop_poll.rs +++ b/src/requests/all/stop_poll.rs @@ -1,28 +1,28 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, InlineKeyboardMarkup, Poll}, Bot, }; +use std::sync::Arc; /// Use this method to stop a poll which was sent by the bot. /// /// [The official docs](https://core.telegram.org/bots/api#stoppoll). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct StopPoll<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct StopPoll { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, message_id: i32, reply_markup: Option, } #[async_trait::async_trait] -impl Request for StopPoll<'_> { +impl Request for StopPoll { type Output = Poll; /// On success, the stopped [`Poll`] with the final results is returned. @@ -38,14 +38,14 @@ impl Request for StopPoll<'_> { .await } } -impl<'a> StopPoll<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, message_id: i32) -> Self +impl StopPoll { + pub(crate) fn new(bot: Arc, chat_id: C, message_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, message_id, reply_markup: None, diff --git a/src/requests/all/unban_chat_member.rs b/src/requests/all/unban_chat_member.rs index 749f31cc..eb643301 100644 --- a/src/requests/all/unban_chat_member.rs +++ b/src/requests/all/unban_chat_member.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to unban a previously kicked user in a supergroup or /// channel. The user will **not** return to the group or channel automatically, @@ -15,16 +15,16 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#unbanchatmember). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct UnbanChatMember<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct UnbanChatMember { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, user_id: i32, } #[async_trait::async_trait] -impl Request for UnbanChatMember<'_> { +impl Request for UnbanChatMember { type Output = True; async fn send(&self) -> ResponseResult { @@ -38,14 +38,14 @@ impl Request for UnbanChatMember<'_> { } } -impl<'a> UnbanChatMember<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C, user_id: i32) -> Self +impl UnbanChatMember { + pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self where C: Into, { let chat_id = chat_id.into(); Self { - bot: BotWrapper(bot), + bot, chat_id, user_id, } diff --git a/src/requests/all/unpin_chat_message.rs b/src/requests/all/unpin_chat_message.rs index b4b42921..926719b2 100644 --- a/src/requests/all/unpin_chat_message.rs +++ b/src/requests/all/unpin_chat_message.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{ChatId, True}, Bot, }; +use std::sync::Arc; /// Use this method to unpin a message in a group, a supergroup, or a channel. /// @@ -16,15 +16,15 @@ use crate::{ /// /// [The official docs](https://core.telegram.org/bots/api#unpinchatmessage). #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct UnpinChatMessage<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct UnpinChatMessage { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, chat_id: ChatId, } #[async_trait::async_trait] -impl Request for UnpinChatMessage<'_> { +impl Request for UnpinChatMessage { type Output = True; async fn send(&self) -> ResponseResult { @@ -38,16 +38,13 @@ impl Request for UnpinChatMessage<'_> { } } -impl<'a> UnpinChatMessage<'a> { - pub(crate) fn new(bot: &'a Bot, chat_id: C) -> Self +impl UnpinChatMessage { + pub(crate) fn new(bot: Arc, chat_id: C) -> Self where C: Into, { let chat_id = chat_id.into(); - Self { - bot: BotWrapper(bot), - chat_id, - } + Self { bot, chat_id } } /// Unique identifier for the target chat or username of the target channel diff --git a/src/requests/all/upload_sticker_file.rs b/src/requests/all/upload_sticker_file.rs index 6183e2de..68015c1c 100644 --- a/src/requests/all/upload_sticker_file.rs +++ b/src/requests/all/upload_sticker_file.rs @@ -1,12 +1,12 @@ use serde::Serialize; -use super::BotWrapper; use crate::{ net, requests::{Request, ResponseResult}, types::{File, InputFile}, Bot, }; +use std::sync::Arc; /// Use this method to upload a .png file with a sticker for later use in /// [`Bot::create_new_sticker_set`] and [`Bot::add_sticker_to_set`] methods (can @@ -17,15 +17,15 @@ use crate::{ /// [`Bot::create_new_sticker_set`]: crate::Bot::create_new_sticker_set /// [`Bot::add_sticker_to_set`]: crate::Bot::add_sticker_to_set #[serde_with_macros::skip_serializing_none] -#[derive(Eq, PartialEq, Debug, Clone, Serialize)] -pub struct UploadStickerFile<'a> { +#[derive(Debug, Clone, Serialize)] +pub struct UploadStickerFile { #[serde(skip_serializing)] - bot: BotWrapper<'a>, + bot: Arc, user_id: i32, png_sticker: InputFile, } #[async_trait::async_trait] -impl Request for UploadStickerFile<'_> { +impl Request for UploadStickerFile { type Output = File; async fn send(&self) -> ResponseResult { @@ -39,14 +39,14 @@ impl Request for UploadStickerFile<'_> { } } -impl<'a> UploadStickerFile<'a> { +impl UploadStickerFile { pub(crate) fn new( - bot: &'a Bot, + bot: Arc, user_id: i32, png_sticker: InputFile, ) -> Self { Self { - bot: BotWrapper(bot), + bot, user_id, png_sticker, }