diff --git a/CHANGELOG.md b/CHANGELOG.md index 6035a332..4e6c2d69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.3.0] - ??? +### Added + - `BotBuilder`, which allows setting a default `ParseMode`. + +### Deprecated + - `Bot::{from_env_with_client, new, with_client}`. + ### Changed - Now methods which can send file to Telegram returns tokio::io::Result. Early its could panic. ([issue 216](https://github.com/teloxide/teloxide/issues/216)) - Now provided description of unknown telegram error, by splitting ApiErrorKind at `ApiErrorKind` and `ApiErrorKindKnown` enums. ([issue 199](https://github.com/teloxide/teloxide/issues/199)) + - Extract `Bot` from `Arc` ([issue 216](https://github.com/teloxide/teloxide/issues/230)). + ## [0.2.0] - 2020-02-25 ### Added - The functionality to parse commands only with a correct bot's name (breaks backwards compatibility) ([Issue 168](https://github.com/teloxide/teloxide/issues/168)). diff --git a/README.md b/README.md index f506caf7..23960a3d 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ pub enum Dialogue { } ``` -The handy `up!` macro automatically generates functions that complete one state to another by appending a field. +The handy `up!` macro automatically generates functions that complete one state to another by appending a field. Here are the transition functions: ([dialogue_bot/src/transitions.rs](https://github.com/teloxide/teloxide/blob/master/examples/dialogue_bot/src/transitions.rs)) ```rust diff --git a/examples/heroku_ping_pong_bot/src/main.rs b/examples/heroku_ping_pong_bot/src/main.rs index 9df9e557..58b6fa37 100644 --- a/examples/heroku_ping_pong_bot/src/main.rs +++ b/examples/heroku_ping_pong_bot/src/main.rs @@ -3,7 +3,7 @@ use teloxide::{dispatching::update_listeners, prelude::*}; -use std::{convert::Infallible, env, net::SocketAddr, sync::Arc}; +use std::{convert::Infallible, env, net::SocketAddr}; use tokio::sync::mpsc; use warp::Filter; @@ -22,7 +22,7 @@ async fn handle_rejection( } pub async fn webhook<'a>( - bot: Arc, + bot: Bot, ) -> impl update_listeners::UpdateListener { // Heroku defines auto defines a port value let teloxide_token = env::var("TELOXIDE_TOKEN") @@ -79,7 +79,7 @@ async fn run() { let bot = Bot::from_env(); - Dispatcher::new(Arc::clone(&bot)) + Dispatcher::new(bot.clone()) .messages_handler(|rx: DispatcherHandlerRx| { rx.for_each(|message| async move { message.answer_str("pong").await.log_on_error().await; diff --git a/examples/ngrok_ping_pong_bot/src/main.rs b/examples/ngrok_ping_pong_bot/src/main.rs index 39d2b4fd..1bc2f422 100644 --- a/examples/ngrok_ping_pong_bot/src/main.rs +++ b/examples/ngrok_ping_pong_bot/src/main.rs @@ -3,7 +3,7 @@ use teloxide::{dispatching::update_listeners, prelude::*}; -use std::{convert::Infallible, net::SocketAddr, sync::Arc}; +use std::{convert::Infallible, net::SocketAddr}; use tokio::sync::mpsc; use warp::Filter; @@ -22,7 +22,7 @@ async fn handle_rejection( } pub async fn webhook<'a>( - bot: Arc, + bot: Bot, ) -> impl update_listeners::UpdateListener { // You might want to specify a self-signed certificate via .certificate // method on SetWebhook. @@ -60,7 +60,7 @@ async fn run() { let bot = Bot::from_env(); - Dispatcher::new(Arc::clone(&bot)) + Dispatcher::new(bot.clone()) .messages_handler(|rx: DispatcherHandlerRx| { rx.for_each(|message| async move { message.answer_str("pong").await.log_on_error().await; diff --git a/src/bot/api.rs b/src/bot/api.rs index a1058d49..98baa665 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -25,7 +25,7 @@ use crate::{ }, Bot, }; -use std::sync::Arc; +use std::ops::Deref; impl Bot { /// Use this method to receive incoming updates using long polling ([wiki]). @@ -38,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: &Arc) -> GetUpdates { - GetUpdates::new(Arc::clone(self)) + pub fn get_updates(&self) -> GetUpdates { + GetUpdates::new(self.clone()) } /// Use this method to specify a url and receive incoming updates via an @@ -63,11 +63,11 @@ impl Bot { /// Use an empty string to remove webhook integration. /// /// [`Update`]: crate::types::Update - pub fn set_webhook(self: &Arc, url: U) -> SetWebhook + pub fn set_webhook(&self, url: U) -> SetWebhook where U: Into, { - SetWebhook::new(Arc::clone(self), url) + SetWebhook::new(self.clone(), url) } /// Use this method to remove webhook integration if you decide to switch @@ -76,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: &Arc) -> DeleteWebhook { - DeleteWebhook::new(Arc::clone(self)) + pub fn delete_webhook(&self) -> DeleteWebhook { + DeleteWebhook::new(self.clone()) } /// Use this method to get current webhook status. @@ -88,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: &Arc) -> GetWebhookInfo { - GetWebhookInfo::new(Arc::clone(self)) + pub fn get_webhook_info(&self) -> GetWebhookInfo { + GetWebhookInfo::new(self.clone()) } /// 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: &Arc) -> GetMe { - GetMe::new(Arc::clone(self)) + pub fn get_me(&self) -> GetMe { + GetMe::new(self.clone()) } /// Use this method to send text messages. @@ -108,16 +108,22 @@ 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: &Arc, - chat_id: C, - text: T, - ) -> SendMessage + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder + pub fn send_message(&self, chat_id: C, text: T) -> SendMessage where C: Into, T: Into, { - SendMessage::new(Arc::clone(self), chat_id, text) + match self.parse_mode.deref() { + None => SendMessage::new(self.clone(), chat_id, text), + Some(parse_mode) => SendMessage::new(self.clone(), chat_id, text) + .parse_mode(*parse_mode.deref()), + } } /// Use this method to forward messages of any kind. @@ -135,7 +141,7 @@ impl Bot { /// /// [`from_chat_id`]: ForwardMessage::from_chat_id pub fn forward_message( - self: &Arc, + &self, chat_id: C, from_chat_id: F, message_id: i32, @@ -144,7 +150,7 @@ impl Bot { C: Into, F: Into, { - ForwardMessage::new(Arc::clone(self), chat_id, from_chat_id, message_id) + ForwardMessage::new(self.clone(), chat_id, from_chat_id, message_id) } /// Use this method to send photos. @@ -166,15 +172,21 @@ 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: &Arc, - chat_id: C, - photo: InputFile, - ) -> SendPhoto + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder + pub fn send_photo(&self, chat_id: C, photo: InputFile) -> SendPhoto where C: Into, { - SendPhoto::new(Arc::clone(self), chat_id, photo) + match self.parse_mode.deref() { + None => SendPhoto::new(self.clone(), chat_id, photo), + Some(parse_mode) => SendPhoto::new(self.clone(), chat_id, photo) + .parse_mode(*parse_mode.deref()), + } } /// @@ -182,15 +194,21 @@ 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: &Arc, - chat_id: C, - audio: InputFile, - ) -> SendAudio + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder + pub fn send_audio(&self, chat_id: C, audio: InputFile) -> SendAudio where C: Into, { - SendAudio::new(Arc::clone(self), chat_id, audio) + match self.parse_mode.deref() { + None => SendAudio::new(self.clone(), chat_id, audio), + Some(parse_mode) => SendAudio::new(self.clone(), chat_id, audio) + .parse_mode(*parse_mode.deref()), + } } /// Use this method to send general files. @@ -211,15 +229,27 @@ impl Bot { /// `multipart/form-data`. [More info on Sending Files »]. /// /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder pub fn send_document( - self: &Arc, + &self, chat_id: C, document: InputFile, ) -> SendDocument where C: Into, { - SendDocument::new(Arc::clone(self), chat_id, document) + match self.parse_mode.deref() { + None => SendDocument::new(self.clone(), chat_id, document), + Some(parse_mode) => { + SendDocument::new(self.clone(), chat_id, document) + .parse_mode(*parse_mode.deref()) + } + } } /// Use this method to send video files, Telegram clients support mp4 videos @@ -243,15 +273,21 @@ 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: &Arc, - chat_id: C, - video: InputFile, - ) -> SendVideo + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder + pub fn send_video(&self, chat_id: C, video: InputFile) -> SendVideo where C: Into, { - SendVideo::new(Arc::clone(self), chat_id, video) + match self.parse_mode.deref() { + None => SendVideo::new(self.clone(), chat_id, video), + Some(parse_mode) => SendVideo::new(self.clone(), chat_id, video) + .parse_mode(*parse_mode.deref()), + } } /// Use this method to send animation files (GIF or H.264/MPEG-4 AVC video @@ -266,15 +302,27 @@ impl Bot { /// - `chat_id`: Unique identifier for the target chat or username of the /// target supergroup or channel (in the format `@channelusername`). /// - `animation`: Animation to send. + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder pub fn send_animation( - self: &Arc, + &self, chat_id: C, animation: InputFile, ) -> SendAnimation where C: Into, { - SendAnimation::new(Arc::clone(self), chat_id, animation) + match self.parse_mode.deref() { + None => SendAnimation::new(self.clone(), chat_id, animation), + Some(parse_mode) => { + SendAnimation::new(self.clone(), chat_id, animation) + .parse_mode(*parse_mode.deref()) + } + } } /// Use this method to send audio files, if you want Telegram clients to @@ -304,15 +352,21 @@ 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: &Arc, - chat_id: C, - voice: InputFile, - ) -> SendVoice + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder + pub fn send_voice(&self, chat_id: C, voice: InputFile) -> SendVoice where C: Into, { - SendVoice::new(Arc::clone(self), chat_id, voice) + match self.parse_mode.deref() { + None => SendVoice::new(self.clone(), chat_id, voice), + Some(parse_mode) => SendVoice::new(self.clone(), chat_id, voice) + .parse_mode(*parse_mode.deref()), + } } /// As of [v.4.0], Telegram clients support rounded square mp4 videos of up @@ -335,15 +389,16 @@ 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_video_note( - self: &Arc, + &self, chat_id: C, video_note: InputFile, ) -> SendVideoNote where C: Into, { - SendVideoNote::new(Arc::clone(self), chat_id, video_note) + SendVideoNote::new(self.clone(), chat_id, video_note) } /// Use this method to send a group of photos or videos as an album. @@ -355,16 +410,12 @@ 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: &Arc, - chat_id: C, - media: M, - ) -> SendMediaGroup + pub fn send_media_group(&self, chat_id: C, media: M) -> SendMediaGroup where C: Into, M: Into>, { - SendMediaGroup::new(Arc::clone(self), chat_id, media) + SendMediaGroup::new(self.clone(), chat_id, media) } /// Use this method to send point on the map. @@ -377,7 +428,7 @@ impl Bot { /// - `latitude`: Latitude of the location. /// - `longitude`: Latitude of the location. pub fn send_location( - self: &Arc, + &self, chat_id: C, latitude: f32, longitude: f32, @@ -385,7 +436,7 @@ impl Bot { where C: Into, { - SendLocation::new(Arc::clone(self), chat_id, latitude, longitude) + SendLocation::new(self.clone(), chat_id, latitude, longitude) } /// Use this method to edit live location messages. @@ -404,13 +455,13 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_live_location( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, latitude: f32, longitude: f32, ) -> EditMessageLiveLocation { EditMessageLiveLocation::new( - Arc::clone(self), + self.clone(), chat_or_inline_message, latitude, longitude, @@ -428,10 +479,10 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn stop_message_live_location( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, ) -> StopMessageLiveLocation { - StopMessageLiveLocation::new(Arc::clone(self), chat_or_inline_message) + StopMessageLiveLocation::new(self.clone(), chat_or_inline_message) } /// Use this method to send information about a venue. @@ -446,7 +497,7 @@ impl Bot { /// - `title`: Name of the venue. /// - `address`: Address of the venue. pub fn send_venue( - self: &Arc, + &self, chat_id: C, latitude: f32, longitude: f32, @@ -459,7 +510,7 @@ impl Bot { A: Into, { SendVenue::new( - Arc::clone(self), + self.clone(), chat_id, latitude, longitude, @@ -479,7 +530,7 @@ impl Bot { /// - `phone_number`: Contact's phone number. /// - `first_name`: Contact's first name. pub fn send_contact( - self: &Arc, + &self, chat_id: C, phone_number: P, first_name: F, @@ -489,7 +540,7 @@ impl Bot { P: Into, F: Into, { - SendContact::new(Arc::clone(self), chat_id, phone_number, first_name) + SendContact::new(self.clone(), chat_id, phone_number, first_name) } /// Use this method to send a native poll. A native poll can't be sent to a @@ -505,7 +556,7 @@ impl Bot { /// - `options`: List of answer options, 2-10 strings 1-100 characters /// each. pub fn send_poll( - self: &Arc, + &self, chat_id: C, question: Q, options: O, @@ -515,7 +566,8 @@ impl Bot { Q: Into, O: Into>, { - SendPoll::new(Arc::clone(self), chat_id, question, options) + // FIXME: parse_mode + SendPoll::new(self.clone(), chat_id, question, options) } /// Use this method when you need to tell the user that something is @@ -541,14 +593,14 @@ impl Bot { /// [ImageBot]: https://t.me/imagebot /// [`Bot::send_chat_action`]: crate::Bot::send_chat_action pub fn send_chat_action( - self: &Arc, + &self, chat_id: C, action: SendChatActionKind, ) -> SendChatAction where C: Into, { - SendChatAction::new(Arc::clone(self), chat_id, action) + SendChatAction::new(self.clone(), chat_id, action) } /// Use this method to get a list of profile pictures for a user. @@ -558,10 +610,10 @@ impl Bot { /// # Params /// - `user_id`: Unique identifier of the target user. pub fn get_user_profile_photos( - self: &Arc, + &self, user_id: i32, ) -> GetUserProfilePhotos { - GetUserProfilePhotos::new(Arc::clone(self), user_id) + GetUserProfilePhotos::new(self.clone(), user_id) } /// Use this method to get basic info about a file and prepare it for @@ -586,11 +638,11 @@ impl Bot { /// /// [`File`]: crate::types::file /// [`GetFile`]: self::GetFile - pub fn get_file(self: &Arc, file_id: F) -> GetFile + pub fn get_file(&self, file_id: F) -> GetFile where F: Into, { - GetFile::new(Arc::clone(self), file_id) + GetFile::new(self.clone(), file_id) } /// Use this method to kick a user from a group, a supergroup or a channel. @@ -609,14 +661,14 @@ impl Bot { /// /// [unbanned]: crate::Bot::unban_chat_member pub fn kick_chat_member( - self: &Arc, + &self, chat_id: C, user_id: i32, ) -> KickChatMember where C: Into, { - KickChatMember::new(Arc::clone(self), chat_id, user_id) + KickChatMember::new(self.clone(), chat_id, user_id) } /// Use this method to unban a previously kicked user in a supergroup or @@ -631,14 +683,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: &Arc, + &self, chat_id: C, user_id: i32, ) -> UnbanChatMember where C: Into, { - UnbanChatMember::new(Arc::clone(self), chat_id, user_id) + UnbanChatMember::new(self.clone(), chat_id, user_id) } /// Use this method to restrict a user in a supergroup. @@ -655,7 +707,7 @@ impl Bot { /// - `user_id`: Unique identifier of the target user. /// - `permissions`: New user permissions. pub fn restrict_chat_member( - self: &Arc, + &self, chat_id: C, user_id: i32, permissions: ChatPermissions, @@ -663,7 +715,7 @@ impl Bot { where C: Into, { - RestrictChatMember::new(Arc::clone(self), chat_id, user_id, permissions) + RestrictChatMember::new(self.clone(), chat_id, user_id, permissions) } /// Use this method to promote or demote a user in a supergroup or a @@ -680,14 +732,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: &Arc, + &self, chat_id: C, user_id: i32, ) -> PromoteChatMember where C: Into, { - PromoteChatMember::new(Arc::clone(self), chat_id, user_id) + PromoteChatMember::new(self.clone(), chat_id, user_id) } /// Use this method to set default chat permissions for all members. @@ -702,14 +754,14 @@ impl Bot { /// target supergroup or channel (in the format `@channelusername`). /// - `permissions`: New default chat permissions. pub fn set_chat_permissions( - self: &Arc, + &self, chat_id: C, permissions: ChatPermissions, ) -> SetChatPermissions where C: Into, { - SetChatPermissions::new(Arc::clone(self), chat_id, permissions) + SetChatPermissions::new(self.clone(), chat_id, permissions) } /// Use this method to generate a new invite link for a chat; any previously @@ -735,14 +787,11 @@ 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: &Arc, - chat_id: C, - ) -> ExportChatInviteLink + pub fn export_chat_invite_link(&self, chat_id: C) -> ExportChatInviteLink where C: Into, { - ExportChatInviteLink::new(Arc::clone(self), chat_id) + ExportChatInviteLink::new(self.clone(), chat_id) } /// Use this method to set a new profile photo for the chat. @@ -758,14 +807,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: &Arc, + &self, chat_id: C, photo: InputFile, ) -> SetChatPhoto where C: Into, { - SetChatPhoto::new(Arc::clone(self), chat_id, photo) + SetChatPhoto::new(self.clone(), chat_id, photo) } /// Use this method to delete a chat photo. Photos can't be changed for @@ -777,11 +826,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: &Arc, chat_id: C) -> DeleteChatPhoto + pub fn delete_chat_photo(&self, chat_id: C) -> DeleteChatPhoto where C: Into, { - DeleteChatPhoto::new(Arc::clone(self), chat_id) + DeleteChatPhoto::new(self.clone(), chat_id) } /// Use this method to change the title of a chat. @@ -796,16 +845,12 @@ 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: &Arc, - chat_id: C, - title: T, - ) -> SetChatTitle + pub fn set_chat_title(&self, chat_id: C, title: T) -> SetChatTitle where C: Into, T: Into, { - SetChatTitle::new(Arc::clone(self), chat_id, title) + SetChatTitle::new(self.clone(), chat_id, title) } /// Use this method to change the description of a group, a supergroup or a @@ -819,14 +864,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 set_chat_description( - self: &Arc, - chat_id: C, - ) -> SetChatDescription + pub fn set_chat_description(&self, chat_id: C) -> SetChatDescription where C: Into, { - SetChatDescription::new(Arc::clone(self), chat_id) + SetChatDescription::new(self.clone(), chat_id) } /// Use this method to pin a message in a group, a supergroup, or a channel. @@ -842,14 +884,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: &Arc, + &self, chat_id: C, message_id: i32, ) -> PinChatMessage where C: Into, { - PinChatMessage::new(Arc::clone(self), chat_id, message_id) + PinChatMessage::new(self.clone(), chat_id, message_id) } /// Use this method to unpin a message in a group, a supergroup, or a @@ -864,14 +906,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 unpin_chat_message( - self: &Arc, - chat_id: C, - ) -> UnpinChatMessage + pub fn unpin_chat_message(&self, chat_id: C) -> UnpinChatMessage where C: Into, { - UnpinChatMessage::new(Arc::clone(self), chat_id) + UnpinChatMessage::new(self.clone(), chat_id) } /// Use this method for your bot to leave a group, supergroup or channel. @@ -881,11 +920,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: &Arc, chat_id: C) -> LeaveChat + pub fn leave_chat(&self, chat_id: C) -> LeaveChat where C: Into, { - LeaveChat::new(Arc::clone(self), chat_id) + LeaveChat::new(self.clone(), chat_id) } /// Use this method to get up to date information about the chat (current @@ -897,11 +936,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: &Arc, chat_id: C) -> GetChat + pub fn get_chat(&self, chat_id: C) -> GetChat where C: Into, { - GetChat::new(Arc::clone(self), chat_id) + GetChat::new(self.clone(), chat_id) } /// Use this method to get a list of administrators in a chat. @@ -915,13 +954,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: &Arc, + &self, chat_id: C, ) -> GetChatAdministrators where C: Into, { - GetChatAdministrators::new(Arc::clone(self), chat_id) + GetChatAdministrators::new(self.clone(), chat_id) } /// Use this method to get the number of members in a chat. @@ -931,14 +970,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_members_count( - self: &Arc, - chat_id: C, - ) -> GetChatMembersCount + pub fn get_chat_members_count(&self, chat_id: C) -> GetChatMembersCount where C: Into, { - GetChatMembersCount::new(Arc::clone(self), chat_id) + GetChatMembersCount::new(self.clone(), chat_id) } /// Use this method to get information about a member of a chat. @@ -949,15 +985,11 @@ 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: &Arc, - chat_id: C, - user_id: i32, - ) -> GetChatMember + pub fn get_chat_member(&self, chat_id: C, user_id: i32) -> GetChatMember where C: Into, { - GetChatMember::new(Arc::clone(self), chat_id, user_id) + GetChatMember::new(self.clone(), chat_id, user_id) } /// Use this method to set a new group sticker set for a supergroup. @@ -975,7 +1007,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: &Arc, + &self, chat_id: C, sticker_set_name: S, ) -> SetChatStickerSet @@ -983,7 +1015,7 @@ impl Bot { C: Into, S: Into, { - SetChatStickerSet::new(Arc::clone(self), chat_id, sticker_set_name) + SetChatStickerSet::new(self.clone(), chat_id, sticker_set_name) } /// Use this method to delete a group sticker set from a supergroup. @@ -1000,14 +1032,11 @@ impl Bot { /// target supergroup (in the format `@supergroupusername`). /// /// [`Bot::get_chat`]: crate::Bot::get_chat - pub fn delete_chat_sticker_set( - self: &Arc, - chat_id: C, - ) -> DeleteChatStickerSet + pub fn delete_chat_sticker_set(&self, chat_id: C) -> DeleteChatStickerSet where C: Into, { - DeleteChatStickerSet::new(Arc::clone(self), chat_id) + DeleteChatStickerSet::new(self.clone(), chat_id) } /// Use this method to send answers to callback queries sent from [inline @@ -1023,13 +1052,13 @@ impl Bot { /// /// [inline keyboards]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating pub fn answer_callback_query( - self: &Arc, + &self, callback_query_id: C, ) -> AnswerCallbackQuery where C: Into, { - AnswerCallbackQuery::new(Arc::clone(self), callback_query_id) + AnswerCallbackQuery::new(self.clone(), callback_query_id) } /// Use this method to edit text and game messages. @@ -1044,15 +1073,29 @@ impl Bot { /// /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder pub fn edit_message_text( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, text: T, ) -> EditMessageText where T: Into, { - EditMessageText::new(Arc::clone(self), chat_or_inline_message, text) + match self.parse_mode.deref() { + None => { + EditMessageText::new(self.clone(), chat_or_inline_message, text) + } + Some(parse_mode) => { + EditMessageText::new(self.clone(), chat_or_inline_message, text) + .parse_mode(*parse_mode.deref()) + } + } } /// Use this method to edit captions of messages. @@ -1064,11 +1107,25 @@ impl Bot { /// /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True + /// + /// # Notes + /// Uses [a default parse mode] if specified in [`BotBuilder`]. + /// + /// [a default parse mode]: crate::BotBuilder::parse_mode + /// [`BotBuilder`]: crate::BotBuilder pub fn edit_message_caption( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, ) -> EditMessageCaption { - EditMessageCaption::new(Arc::clone(self), chat_or_inline_message) + match self.parse_mode.deref() { + None => { + EditMessageCaption::new(self.clone(), chat_or_inline_message) + } + Some(parse_mode) => { + EditMessageCaption::new(self.clone(), chat_or_inline_message) + .parse_mode(*parse_mode.deref()) + } + } } /// Use this method to edit animation, audio, document, photo, or video @@ -1086,11 +1143,11 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_media( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, media: InputMedia, ) -> EditMessageMedia { - EditMessageMedia::new(Arc::clone(self), chat_or_inline_message, media) + EditMessageMedia::new(self.clone(), chat_or_inline_message, media) } /// Use this method to edit only the reply markup of messages. @@ -1103,10 +1160,10 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn edit_message_reply_markup( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, ) -> EditMessageReplyMarkup { - EditMessageReplyMarkup::new(Arc::clone(self), chat_or_inline_message) + EditMessageReplyMarkup::new(self.clone(), chat_or_inline_message) } /// Use this method to stop a poll which was sent by the bot. @@ -1118,15 +1175,11 @@ 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: &Arc, - chat_id: C, - message_id: i32, - ) -> StopPoll + pub fn stop_poll(&self, chat_id: C, message_id: i32) -> StopPoll where C: Into, { - StopPoll::new(Arc::clone(self), chat_id, message_id) + StopPoll::new(self.clone(), chat_id, message_id) } /// Use this method to delete a message, including service messages. @@ -1150,14 +1203,14 @@ impl Bot { /// target channel (in the format `@channelusername`). /// - `message_id`: Identifier of the message to delete. pub fn delete_message( - self: &Arc, + &self, chat_id: C, message_id: i32, ) -> DeleteMessage where C: Into, { - DeleteMessage::new(Arc::clone(self), chat_id, message_id) + DeleteMessage::new(self.clone(), chat_id, message_id) } /// Use this method to send static .WEBP or [animated] .TGS stickers. @@ -1179,15 +1232,11 @@ 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: &Arc, - chat_id: C, - sticker: InputFile, - ) -> SendSticker + pub fn send_sticker(&self, chat_id: C, sticker: InputFile) -> SendSticker where C: Into, { - SendSticker::new(Arc::clone(self), chat_id, sticker) + SendSticker::new(self.clone(), chat_id, sticker) } /// Use this method to get a sticker set. @@ -1196,11 +1245,11 @@ impl Bot { /// /// # Params /// - `name`: Name of the sticker set. - pub fn get_sticker_set(self: &Arc, name: N) -> GetStickerSet + pub fn get_sticker_set(&self, name: N) -> GetStickerSet where N: Into, { - GetStickerSet::new(Arc::clone(self), name) + GetStickerSet::new(self.clone(), name) } /// Use this method to upload a .png file with a sticker for later use in @@ -1220,11 +1269,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: &Arc, + &self, user_id: i32, png_sticker: InputFile, ) -> UploadStickerFile { - UploadStickerFile::new(Arc::clone(self), user_id, png_sticker) + UploadStickerFile::new(self.clone(), user_id, png_sticker) } /// Use this method to create new sticker set owned by a user. The bot will @@ -1256,7 +1305,7 @@ impl Bot { /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId pub fn create_new_sticker_set( - self: &Arc, + &self, user_id: i32, name: N, title: T, @@ -1269,7 +1318,7 @@ impl Bot { E: Into, { CreateNewStickerSet::new( - Arc::clone(self), + self.clone(), user_id, name, title, @@ -1299,7 +1348,7 @@ impl Bot { /// [`InputFile::Url`]: crate::types::InputFile::Url /// [`InputFile::FileId`]: crate::types::InputFile::FileId pub fn add_sticker_to_set( - self: &Arc, + &self, user_id: i32, name: N, png_sticker: InputFile, @@ -1309,13 +1358,7 @@ impl Bot { N: Into, E: Into, { - AddStickerToSet::new( - Arc::clone(self), - user_id, - name, - png_sticker, - emojis, - ) + AddStickerToSet::new(self.clone(), user_id, name, png_sticker, emojis) } /// Use this method to move a sticker in a set created by the bot to a @@ -1327,14 +1370,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: &Arc, + &self, sticker: S, position: i32, ) -> SetStickerPositionInSet where S: Into, { - SetStickerPositionInSet::new(Arc::clone(self), sticker, position) + SetStickerPositionInSet::new(self.clone(), sticker, position) } /// Use this method to delete a sticker from a set created by the bot. @@ -1343,14 +1386,11 @@ impl Bot { /// /// # Params /// - `sticker`: File identifier of the sticker. - pub fn delete_sticker_from_set( - self: &Arc, - sticker: S, - ) -> DeleteStickerFromSet + pub fn delete_sticker_from_set(&self, sticker: S) -> DeleteStickerFromSet where S: Into, { - DeleteStickerFromSet::new(Arc::clone(self), sticker) + DeleteStickerFromSet::new(self.clone(), sticker) } /// Use this method to send answers to an inline query. @@ -1363,7 +1403,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: &Arc, + &self, inline_query_id: I, results: R, ) -> AnswerInlineQuery @@ -1371,7 +1411,7 @@ impl Bot { I: Into, R: Into>, { - AnswerInlineQuery::new(Arc::clone(self), inline_query_id, results) + AnswerInlineQuery::new(self.clone(), inline_query_id, results) } /// Use this method to send invoices. @@ -1397,7 +1437,7 @@ impl Bot { /// [@Botfather]: https://t.me/botfather #[allow(clippy::too_many_arguments)] pub fn send_invoice( - self: &Arc, + &self, chat_id: i32, title: T, description: D, @@ -1417,7 +1457,7 @@ impl Bot { Pr: Into>, { SendInvoice::new( - Arc::clone(self), + self.clone(), chat_id, title, description, @@ -1445,14 +1485,14 @@ impl Bot { /// /// [`Update`]: crate::types::Update pub fn answer_shipping_query( - self: &Arc, + &self, shipping_query_id: S, ok: bool, ) -> AnswerShippingQuery where S: Into, { - AnswerShippingQuery::new(Arc::clone(self), shipping_query_id, ok) + AnswerShippingQuery::new(self.clone(), shipping_query_id, ok) } /// Once the user has confirmed their payment and shipping details, the Bot @@ -1472,14 +1512,14 @@ impl Bot { /// /// [`Update`]: crate::types::Update pub fn answer_pre_checkout_query

( - self: &Arc, + &self, pre_checkout_query_id: P, ok: bool, ) -> AnswerPreCheckoutQuery where P: Into, { - AnswerPreCheckoutQuery::new(Arc::clone(self), pre_checkout_query_id, ok) + AnswerPreCheckoutQuery::new(self.clone(), pre_checkout_query_id, ok) } /// Use this method to send a game. @@ -1492,15 +1532,11 @@ impl Bot { /// identifier for the game. Set up your games via [@Botfather]. /// /// [@Botfather]: https://t.me/botfather - pub fn send_game( - self: &Arc, - chat_id: i32, - game_short_name: G, - ) -> SendGame + pub fn send_game(&self, chat_id: i32, game_short_name: G) -> SendGame where G: Into, { - SendGame::new(Arc::clone(self), chat_id, game_short_name) + SendGame::new(self.clone(), chat_id, game_short_name) } /// Use this method to set the score of the specified user in a game. @@ -1519,17 +1555,12 @@ impl Bot { /// [`Message`]: crate::types::Message /// [`True`]: crate::types::True pub fn set_game_score( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, score: i32, ) -> SetGameScore { - SetGameScore::new( - Arc::clone(self), - chat_or_inline_message, - user_id, - score, - ) + SetGameScore::new(self.clone(), chat_or_inline_message, user_id, score) } /// Use this method to get data for high score tables. @@ -1548,15 +1579,11 @@ impl Bot { /// # Params /// - `user_id`: Target user id. pub fn get_game_high_scores( - self: &Arc, + &self, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, ) -> GetGameHighScores { - GetGameHighScores::new( - Arc::clone(self), - chat_or_inline_message, - user_id, - ) + GetGameHighScores::new(self.clone(), chat_or_inline_message, user_id) } /// Use this method to set a custom title for an administrator in a @@ -1571,7 +1598,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: &Arc, + &self, chat_id: C, user_id: i32, custom_title: CT, @@ -1581,7 +1608,7 @@ impl Bot { CT: Into, { SetChatAdministratorCustomTitle::new( - Arc::clone(self), + self.clone(), chat_id, user_id, custom_title, diff --git a/src/bot/mod.rs b/src/bot/mod.rs index b9af4d19..8cbb7655 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -3,15 +3,19 @@ use reqwest::{ Client, ClientBuilder, }; use std::{sync::Arc, time::Duration}; +use crate::types::ParseMode; mod api; mod download; /// A Telegram bot used to send requests. +/// +/// No need to put `Bot` into `Arc`, because it's already in. #[derive(Debug, Clone)] pub struct Bot { - token: String, + token: Arc, client: Client, + parse_mode: Arc>, } impl Bot { @@ -22,8 +26,9 @@ impl Bot { /// If cannot get the `TELOXIDE_TOKEN` environmental variable. /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html - pub fn from_env() -> Arc { - Self::from_env_with_client(sound_bot()) + #[allow(deprecated)] + pub fn from_env() -> Self { + Self::from_env_with_client(Client::new()) } /// Creates a new `Bot` with the `TELOXIDE_TOKEN` environmental variable (a @@ -33,7 +38,9 @@ impl Bot { /// If cannot get the `TELOXIDE_TOKEN` environmental variable. /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html - pub fn from_env_with_client(client: Client) -> Arc { + #[deprecated] + #[allow(deprecated)] + pub fn from_env_with_client(client: Client) -> Self { Self::with_client( &std::env::var("TELOXIDE_TOKEN") .expect("Cannot get the TELOXIDE_TOKEN env variable"), @@ -45,7 +52,9 @@ impl Bot { /// [`reqwest::Client`]. /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html - pub fn new(token: S) -> Arc + #[deprecated] + #[allow(deprecated)] + pub fn new(token: S) -> Self where S: Into, { @@ -56,11 +65,17 @@ impl Bot { /// [`reqwest::Client`]. /// /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html - pub fn with_client(token: S, client: Client) -> Arc + #[deprecated] + #[allow(deprecated)] + pub fn with_client(token: S, client: Client) -> Self where S: Into, { - Arc::new(Self { token: token.into(), client }) + Self { + token: Into::>::into(Into::::into(token)), + client, + parse_mode: Arc::new(None), + } } } @@ -92,3 +107,89 @@ impl Bot { &self.client } } + +#[derive(Debug, Default)] +pub struct BotBuilder { + token: Option, + client: Option, + parse_mode: Option, +} + +impl BotBuilder { + #[must_use] + pub fn new() -> Self { + Self::default() + } + + /// Specifies a custom HTTPS client. Otherwise, the default will be used. + #[must_use] + pub fn client(mut self, client: Client) -> Self { + self.client = Some(client); + self + } + + /// Specified a custom token. + /// + /// Otherwise, a token will be extracted from the `TELOXIDE_TOKEN` + /// environmental variable. + #[must_use] + pub fn token(mut self, token: S) -> Self + where + S: Into, + { + self.token = Some(token.into()); + self + } + + /// Specifies [`ParseMode`], which will be used during all calls to: + /// + /// - [`send_message`] + /// - [`send_photo`] + /// - [`send_video`] + /// - [`send_audio`] + /// - [`send_document`] + /// - [`send_animation`] + /// - [`send_voice`] + /// - [`send_poll`] + /// - [`edit_message_text`] + /// - [`edit_message_caption`] + /// + /// [`send_message`]: crate::Bot::send_message + /// [`send_photo`]: crate::Bot::send_photo + /// [`send_video`]: crate::Bot::send_video + /// [`send_audio`]: crate::Bot::send_audio + /// [`send_document`]: crate::Bot::send_document + /// [`send_animation`]: crate::Bot::send_animation + /// [`send_voice`]: crate::Bot::send_voice + /// [`send_poll`]: crate::Bot::send_poll + /// [`edit_message_text`]: crate::Bot::edit_message_text + /// [`edit_message_caption`]: crate::Bot::edit_message_caption + #[must_use] + pub fn parse_mode(mut self, parse_mode: ParseMode) -> Self { + self.parse_mode = Some(parse_mode); + self + } + + /// Builds [`Bot`]. + /// + /// # Panics + /// If cannot get the `TELOXIDE_TOKEN` environmental variable. + /// + /// [`reqwest::Client`]: https://docs.rs/reqwest/0.10.1/reqwest/struct.Client.html + /// + /// [`Bot`]: crate::Bot + #[must_use] + pub fn build(self) -> Bot { + Bot { + client: self.client.unwrap_or_default(), + token: self + .token + .unwrap_or_else(|| { + std::env::var("TELOXIDE_TOKEN") + .expect("Cannot get the TELOXIDE_TOKEN env variable") + }) + .into(), + parse_mode: Arc::new(self.parse_mode), + } + } +} diff --git a/src/dispatching/dialogue/dialogue_dispatcher.rs b/src/dispatching/dialogue/dialogue_dispatcher.rs index 385545c2..6df9377b 100644 --- a/src/dispatching/dialogue/dialogue_dispatcher.rs +++ b/src/dispatching/dialogue/dialogue_dispatcher.rs @@ -188,6 +188,7 @@ mod tests { }; #[tokio::test] + #[allow(deprecated)] async fn updates_from_same_chat_executed_sequentially() { #[derive(Debug)] struct MyUpdate { diff --git a/src/dispatching/dispatcher.rs b/src/dispatching/dispatcher.rs index 1a7fdad4..505ecb3e 100644 --- a/src/dispatching/dispatcher.rs +++ b/src/dispatching/dispatcher.rs @@ -27,7 +27,7 @@ mod macros { } fn send<'a, Upd>( - bot: &'a Arc, + bot: &'a Bot, tx: &'a Tx, update: Upd, variant: &'static str, @@ -35,9 +35,7 @@ fn send<'a, Upd>( Upd: Debug, { if let Some(tx) = tx { - if let Err(error) = - tx.send(UpdateWithCx { bot: Arc::clone(&bot), update }) - { + if let Err(error) = tx.send(UpdateWithCx { bot: bot.clone(), update }) { log::error!( "The RX part of the {} channel is closed, but an update is \ received.\nError:{}\n", @@ -53,7 +51,7 @@ fn send<'a, Upd>( /// See [the module-level documentation for the design /// overview](crate::dispatching). pub struct Dispatcher { - bot: Arc, + bot: Bot, messages_queue: Tx, edited_messages_queue: Tx, @@ -71,7 +69,7 @@ pub struct Dispatcher { impl Dispatcher { /// Constructs a new dispatcher with the specified `bot`. #[must_use] - pub fn new(bot: Arc) -> Self { + pub fn new(bot: Bot) -> Self { Self { bot, messages_queue: None, @@ -207,7 +205,7 @@ impl Dispatcher { /// errors produced by this listener). pub async fn dispatch(&self) { self.dispatch_with_listener( - update_listeners::polling_default(Arc::clone(&self.bot)), + update_listeners::polling_default(self.bot.clone()), LoggingErrorHandler::with_custom_text( "An error from the update listener", ), diff --git a/src/dispatching/update_listeners.rs b/src/dispatching/update_listeners.rs index 66c72b67..7b073afb 100644 --- a/src/dispatching/update_listeners.rs +++ b/src/dispatching/update_listeners.rs @@ -112,7 +112,7 @@ use crate::{ RequestError, }; -use std::{convert::TryInto, sync::Arc, time::Duration}; +use std::{convert::TryInto, time::Duration}; /// A generic update listener. pub trait UpdateListener: Stream> { @@ -140,7 +140,7 @@ pub fn polling_default(bot: Arc) -> impl UpdateListener { /// /// [`GetUpdates`]: crate::requests::GetUpdates pub fn polling( - bot: Arc, + bot: Bot, timeout: Option, limit: Option, allowed_updates: Option>, diff --git a/src/dispatching/update_with_cx.rs b/src/dispatching/update_with_cx.rs index 2292d4d9..7d7182aa 100644 --- a/src/dispatching/update_with_cx.rs +++ b/src/dispatching/update_with_cx.rs @@ -9,7 +9,6 @@ use crate::{ types::{ChatId, ChatOrInlineMessage, InputFile, InputMedia, Message}, Bot, }; -use std::sync::Arc; /// A [`Dispatcher`]'s handler's context of a bot and an update. /// @@ -19,7 +18,7 @@ use std::sync::Arc; /// [`Dispatcher`]: crate::dispatching::Dispatcher #[derive(Debug)] pub struct UpdateWithCx { - pub bot: Arc, + pub bot: Bot, pub update: Upd, } diff --git a/src/lib.rs b/src/lib.rs index 65d62808..b6efd543 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,9 @@ html_favicon_url = "https://github.com/teloxide/teloxide/raw/master/ICON.png" )] #![allow(clippy::match_bool)] +#![forbid(unsafe_code)] -pub use bot::Bot; +pub use bot::{Bot, BotBuilder}; pub use errors::{ApiErrorKind, DownloadError, RequestError}; mod errors; diff --git a/src/requests/all/add_sticker_to_set.rs b/src/requests/all/add_sticker_to_set.rs index 23facb90..3ba68759 100644 --- a/src/requests/all/add_sticker_to_set.rs +++ b/src/requests/all/add_sticker_to_set.rs @@ -6,14 +6,13 @@ use crate::{ }; use crate::requests::{RequestWithFile, 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(Debug, Clone)] pub struct AddStickerToSet { - bot: Arc, + bot: Bot, user_id: i32, name: String, png_sticker: InputFile, @@ -45,7 +44,7 @@ impl RequestWithFile for AddStickerToSet { impl AddStickerToSet { pub(crate) fn new( - bot: Arc, + bot: Bot, user_id: i32, name: N, png_sticker: InputFile, diff --git a/src/requests/all/answer_callback_query.rs b/src/requests/all/answer_callback_query.rs index a636e314..447b50d2 100644 --- a/src/requests/all/answer_callback_query.rs +++ b/src/requests/all/answer_callback_query.rs @@ -6,7 +6,6 @@ use crate::{ types::True, Bot, }; -use std::sync::Arc; /// Use this method to send answers to callback queries sent from [inline /// keyboards]. @@ -21,7 +20,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct AnswerCallbackQuery { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, callback_query_id: String, text: Option, show_alert: Option, @@ -45,7 +44,7 @@ impl Request for AnswerCallbackQuery { } impl AnswerCallbackQuery { - pub(crate) fn new(bot: Arc, callback_query_id: C) -> Self + pub(crate) fn new(bot: Bot, callback_query_id: C) -> Self where C: Into, { diff --git a/src/requests/all/answer_inline_query.rs b/src/requests/all/answer_inline_query.rs index ad75ea06..0382af65 100644 --- a/src/requests/all/answer_inline_query.rs +++ b/src/requests/all/answer_inline_query.rs @@ -6,7 +6,6 @@ use crate::{ types::{InlineQueryResult, True}, Bot, }; -use std::sync::Arc; /// Use this method to send answers to an inline query. /// @@ -17,7 +16,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct AnswerInlineQuery { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, inline_query_id: String, results: Vec, cache_time: Option, @@ -43,11 +42,7 @@ impl Request for AnswerInlineQuery { } impl AnswerInlineQuery { - pub(crate) fn new( - bot: Arc, - inline_query_id: I, - results: R, - ) -> Self + pub(crate) fn new(bot: Bot, inline_query_id: I, results: R) -> Self where I: Into, R: Into>, diff --git a/src/requests/all/answer_pre_checkout_query.rs b/src/requests/all/answer_pre_checkout_query.rs index 92919708..d1d67da1 100644 --- a/src/requests/all/answer_pre_checkout_query.rs +++ b/src/requests/all/answer_pre_checkout_query.rs @@ -6,7 +6,6 @@ use crate::{ 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 @@ -21,7 +20,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct AnswerPreCheckoutQuery { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, pre_checkout_query_id: String, ok: bool, error_message: Option, @@ -43,11 +42,7 @@ impl Request for AnswerPreCheckoutQuery { } impl AnswerPreCheckoutQuery { - pub(crate) fn new

( - bot: Arc, - pre_checkout_query_id: P, - ok: bool, - ) -> Self + pub(crate) fn new

(bot: Bot, pre_checkout_query_id: P, ok: bool) -> Self where P: Into, { diff --git a/src/requests/all/answer_shipping_query.rs b/src/requests/all/answer_shipping_query.rs index 452c93ed..b3c177e1 100644 --- a/src/requests/all/answer_shipping_query.rs +++ b/src/requests/all/answer_shipping_query.rs @@ -6,7 +6,6 @@ use crate::{ 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 @@ -20,7 +19,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct AnswerShippingQuery { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, shipping_query_id: String, ok: bool, shipping_options: Option>, @@ -43,7 +42,7 @@ impl Request for AnswerShippingQuery { } impl AnswerShippingQuery { - pub(crate) fn new(bot: Arc, shipping_query_id: S, ok: bool) -> Self + pub(crate) fn new(bot: Bot, shipping_query_id: S, ok: bool) -> Self where S: Into, { diff --git a/src/requests/all/create_new_sticker_set.rs b/src/requests/all/create_new_sticker_set.rs index 7c80840b..a74e66c8 100644 --- a/src/requests/all/create_new_sticker_set.rs +++ b/src/requests/all/create_new_sticker_set.rs @@ -4,7 +4,6 @@ use crate::{ 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. @@ -12,7 +11,7 @@ use std::sync::Arc; /// [The official docs](https://core.telegram.org/bots/api#createnewstickerset). #[derive(Debug, Clone)] pub struct CreateNewStickerSet { - bot: Arc, + bot: Bot, user_id: i32, name: String, title: String, @@ -48,7 +47,7 @@ impl RequestWithFile for CreateNewStickerSet { impl CreateNewStickerSet { pub(crate) fn new( - bot: Arc, + bot: Bot, user_id: i32, name: N, title: T, diff --git a/src/requests/all/delete_chat_photo.rs b/src/requests/all/delete_chat_photo.rs index d9ab17e1..b54a6a4c 100644 --- a/src/requests/all/delete_chat_photo.rs +++ b/src/requests/all/delete_chat_photo.rs @@ -6,7 +6,6 @@ use crate::{ 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 @@ -17,7 +16,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct DeleteChatPhoto { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -37,7 +36,7 @@ impl Request for DeleteChatPhoto { } impl DeleteChatPhoto { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/delete_chat_sticker_set.rs b/src/requests/all/delete_chat_sticker_set.rs index 0ad7ead9..d4ca16d4 100644 --- a/src/requests/all/delete_chat_sticker_set.rs +++ b/src/requests/all/delete_chat_sticker_set.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to delete a group sticker set from a supergroup. /// @@ -22,7 +21,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct DeleteChatStickerSet { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -42,7 +41,7 @@ impl Request for DeleteChatStickerSet { } impl DeleteChatStickerSet { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/delete_message.rs b/src/requests/all/delete_message.rs index 16d31dac..efcfa270 100644 --- a/src/requests/all/delete_message.rs +++ b/src/requests/all/delete_message.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to delete a message, including service messages. /// @@ -27,7 +26,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct DeleteMessage { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, message_id: i32, } @@ -48,7 +47,7 @@ impl Request for DeleteMessage { } impl DeleteMessage { - pub(crate) fn new(bot: Arc, chat_id: C, message_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, message_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/delete_sticker_from_set.rs b/src/requests/all/delete_sticker_from_set.rs index 41f41f80..09846d2e 100644 --- a/src/requests/all/delete_sticker_from_set.rs +++ b/src/requests/all/delete_sticker_from_set.rs @@ -6,7 +6,6 @@ use crate::{ types::True, Bot, }; -use std::sync::Arc; /// Use this method to delete a sticker from a set created by the bot. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct DeleteStickerFromSet { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, sticker: String, } @@ -35,7 +34,7 @@ impl Request for DeleteStickerFromSet { } impl DeleteStickerFromSet { - pub(crate) fn new(bot: Arc, sticker: S) -> Self + pub(crate) fn new(bot: Bot, sticker: S) -> Self where S: Into, { diff --git a/src/requests/all/delete_webhook.rs b/src/requests/all/delete_webhook.rs index dbfcda20..5ab071ab 100644 --- a/src/requests/all/delete_webhook.rs +++ b/src/requests/all/delete_webhook.rs @@ -6,7 +6,6 @@ use crate::{ types::True, Bot, }; -use std::sync::Arc; /// Use this method to remove webhook integration if you decide to switch back /// to [Bot::get_updates]. @@ -18,7 +17,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct DeleteWebhook { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, } #[async_trait::async_trait] @@ -38,7 +37,7 @@ impl Request for DeleteWebhook { } impl DeleteWebhook { - pub(crate) fn new(bot: Arc) -> Self { + pub(crate) fn new(bot: Bot) -> Self { Self { bot } } } diff --git a/src/requests/all/edit_message_caption.rs b/src/requests/all/edit_message_caption.rs index 6a5d0e1d..4b56a909 100644 --- a/src/requests/all/edit_message_caption.rs +++ b/src/requests/all/edit_message_caption.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode}, Bot, }; -use std::sync::Arc; /// Use this method to edit captions of messages. /// @@ -21,7 +20,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct EditMessageCaption { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, caption: Option, @@ -46,7 +45,7 @@ impl Request for EditMessageCaption { impl EditMessageCaption { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, ) -> Self { Self { diff --git a/src/requests/all/edit_message_live_location.rs b/src/requests/all/edit_message_live_location.rs index 1e6bf9b1..dda18546 100644 --- a/src/requests/all/edit_message_live_location.rs +++ b/src/requests/all/edit_message_live_location.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, Bot, }; -use std::sync::Arc; /// Use this method to edit live location messages. /// @@ -23,7 +22,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct EditMessageLiveLocation { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, latitude: f32, @@ -48,7 +47,7 @@ impl Request for EditMessageLiveLocation { impl EditMessageLiveLocation { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, latitude: f32, longitude: f32, diff --git a/src/requests/all/edit_message_media.rs b/src/requests/all/edit_message_media.rs index 27cb1dd0..4e498abb 100644 --- a/src/requests/all/edit_message_media.rs +++ b/src/requests/all/edit_message_media.rs @@ -4,7 +4,6 @@ use crate::{ types::{ChatOrInlineMessage, InlineKeyboardMarkup, InputMedia, Message}, Bot, }; -use std::sync::Arc; /// Use this method to edit animation, audio, document, photo, or video /// messages. @@ -22,7 +21,7 @@ use std::sync::Arc; /// [`True`]: crate::types::True #[derive(Debug, Clone)] pub struct EditMessageMedia { - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, media: InputMedia, reply_markup: Option, @@ -62,7 +61,7 @@ impl Request for EditMessageMedia { impl EditMessageMedia { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, media: InputMedia, ) -> Self { diff --git a/src/requests/all/edit_message_reply_markup.rs b/src/requests/all/edit_message_reply_markup.rs index 6d65d9eb..cef2eec8 100644 --- a/src/requests/all/edit_message_reply_markup.rs +++ b/src/requests/all/edit_message_reply_markup.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, Bot, }; -use std::sync::Arc; /// Use this method to edit only the reply markup of messages. /// @@ -21,7 +20,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct EditMessageReplyMarkup { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, reply_markup: Option, @@ -44,7 +43,7 @@ impl Request for EditMessageReplyMarkup { impl EditMessageReplyMarkup { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, ) -> Self { Self { 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 d517db38..8d87f86e 100644 --- a/src/requests/all/edit_message_text.rs +++ b/src/requests/all/edit_message_text.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message, ParseMode}, Bot, }; -use std::sync::Arc; /// Use this method to edit text and game messages. /// @@ -21,7 +20,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct EditMessageText { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, text: String, @@ -47,7 +46,7 @@ impl Request for EditMessageText { impl EditMessageText { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, text: T, ) -> Self diff --git a/src/requests/all/export_chat_invite_link.rs b/src/requests/all/export_chat_invite_link.rs index 7e31cf96..622099d4 100644 --- a/src/requests/all/export_chat_invite_link.rs +++ b/src/requests/all/export_chat_invite_link.rs @@ -6,7 +6,6 @@ use crate::{ 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. @@ -31,7 +30,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct ExportChatInviteLink { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -52,7 +51,7 @@ impl Request for ExportChatInviteLink { } impl ExportChatInviteLink { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/forward_message.rs b/src/requests/all/forward_message.rs index c37b71c6..ad921401 100644 --- a/src/requests/all/forward_message.rs +++ b/src/requests/all/forward_message.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, Message}, Bot, }; -use std::sync::Arc; /// Use this method to forward messages of any kind. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct ForwardMessage { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, from_chat_id: ChatId, disable_notification: Option, @@ -39,7 +38,7 @@ impl Request for ForwardMessage { impl ForwardMessage { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, from_chat_id: F, message_id: i32, diff --git a/src/requests/all/get_chat.rs b/src/requests/all/get_chat.rs index c726908e..9a884ec6 100644 --- a/src/requests/all/get_chat.rs +++ b/src/requests/all/get_chat.rs @@ -6,7 +6,6 @@ use crate::{ 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 @@ -17,7 +16,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetChat { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -32,7 +31,7 @@ impl Request for GetChat { } impl GetChat { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/get_chat_administrators.rs b/src/requests/all/get_chat_administrators.rs index cc575a27..d3c55a31 100644 --- a/src/requests/all/get_chat_administrators.rs +++ b/src/requests/all/get_chat_administrators.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, ChatMember}, Bot, }; -use std::sync::Arc; /// Use this method to get a list of administrators in a chat. /// @@ -18,7 +17,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetChatAdministrators { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -40,7 +39,7 @@ impl Request for GetChatAdministrators { } impl GetChatAdministrators { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/get_chat_member.rs b/src/requests/all/get_chat_member.rs index e6730cf9..a6c54002 100644 --- a/src/requests/all/get_chat_member.rs +++ b/src/requests/all/get_chat_member.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, ChatMember}, Bot, }; -use std::sync::Arc; /// Use this method to get information about a member of a chat. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetChatMember { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, user_id: i32, } @@ -36,7 +35,7 @@ impl Request for GetChatMember { } impl GetChatMember { - pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, user_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/get_chat_members_count.rs b/src/requests/all/get_chat_members_count.rs index 89deea55..a7062d57 100644 --- a/src/requests/all/get_chat_members_count.rs +++ b/src/requests/all/get_chat_members_count.rs @@ -6,7 +6,6 @@ use crate::{ types::ChatId, Bot, }; -use std::sync::Arc; /// Use this method to get the number of members in a chat. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetChatMembersCount { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -35,7 +34,7 @@ impl Request for GetChatMembersCount { } impl GetChatMembersCount { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/get_file.rs b/src/requests/all/get_file.rs index 1e3743f9..00d0a37e 100644 --- a/src/requests/all/get_file.rs +++ b/src/requests/all/get_file.rs @@ -6,7 +6,6 @@ use crate::{ types::File, Bot, }; -use std::sync::Arc; /// Use this method to get basic info about a file and prepare it for /// downloading. @@ -31,7 +30,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetFile { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, file_id: String, } @@ -46,7 +45,7 @@ impl Request for GetFile { } impl GetFile { - pub(crate) fn new(bot: Arc, file_id: F) -> Self + pub(crate) fn new(bot: Bot, file_id: F) -> Self where F: Into, { diff --git a/src/requests/all/get_game_high_scores.rs b/src/requests/all/get_game_high_scores.rs index 6ed6d17d..eb52517a 100644 --- a/src/requests/all/get_game_high_scores.rs +++ b/src/requests/all/get_game_high_scores.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, GameHighScore}, Bot, }; -use std::sync::Arc; /// Use this method to get data for high score tables. /// @@ -24,7 +23,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetGameHighScores { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, user_id: i32, @@ -47,7 +46,7 @@ impl Request for GetGameHighScores { impl GetGameHighScores { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, ) -> Self { diff --git a/src/requests/all/get_me.rs b/src/requests/all/get_me.rs index 857c8a6b..83168769 100644 --- a/src/requests/all/get_me.rs +++ b/src/requests/all/get_me.rs @@ -5,7 +5,6 @@ use crate::{ Bot, }; use serde::Serialize; -use std::sync::Arc; /// A simple method for testing your bot's auth token. Requires no parameters. /// @@ -13,7 +12,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetMe { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, } #[async_trait::async_trait] @@ -29,7 +28,7 @@ impl Request for GetMe { } impl GetMe { - pub(crate) fn new(bot: Arc) -> Self { + pub(crate) fn new(bot: Bot) -> Self { Self { bot } } } diff --git a/src/requests/all/get_sticker_set.rs b/src/requests/all/get_sticker_set.rs index 8b1094a5..0186b9a0 100644 --- a/src/requests/all/get_sticker_set.rs +++ b/src/requests/all/get_sticker_set.rs @@ -6,7 +6,6 @@ use crate::{ types::StickerSet, Bot, }; -use std::sync::Arc; /// Use this method to get a sticker set. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetStickerSet { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, name: String, } @@ -35,7 +34,7 @@ impl Request for GetStickerSet { } impl GetStickerSet { - pub(crate) fn new(bot: Arc, name: N) -> Self + pub(crate) fn new(bot: Bot, name: N) -> Self where N: Into, { diff --git a/src/requests/all/get_updates.rs b/src/requests/all/get_updates.rs index 150c3cbb..d331c677 100644 --- a/src/requests/all/get_updates.rs +++ b/src/requests/all/get_updates.rs @@ -7,7 +7,6 @@ use crate::{ Bot, RequestError, }; use serde_json::Value; -use std::sync::Arc; /// Use this method to receive incoming updates using long polling ([wiki]). /// @@ -23,7 +22,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetUpdates { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, pub(crate) offset: Option, pub(crate) limit: Option, pub(crate) timeout: Option, @@ -64,7 +63,7 @@ impl Request for GetUpdates { } impl GetUpdates { - pub(crate) fn new(bot: Arc) -> Self { + pub(crate) fn new(bot: Bot) -> Self { Self { bot, offset: None, diff --git a/src/requests/all/get_user_profile_photos.rs b/src/requests/all/get_user_profile_photos.rs index 1bc2fba0..f1dd1a26 100644 --- a/src/requests/all/get_user_profile_photos.rs +++ b/src/requests/all/get_user_profile_photos.rs @@ -6,7 +6,6 @@ use crate::{ types::UserProfilePhotos, Bot, }; -use std::sync::Arc; /// Use this method to get a list of profile pictures for a user. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetUserProfilePhotos { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, user_id: i32, offset: Option, limit: Option, @@ -37,7 +36,7 @@ impl Request for GetUserProfilePhotos { } impl GetUserProfilePhotos { - pub(crate) fn new(bot: Arc, user_id: i32) -> Self { + pub(crate) fn new(bot: Bot, user_id: i32) -> Self { Self { 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 99ece7ea..18e6b0fe 100644 --- a/src/requests/all/get_webhook_info.rs +++ b/src/requests/all/get_webhook_info.rs @@ -6,7 +6,6 @@ use crate::{ types::WebhookInfo, Bot, }; -use std::sync::Arc; /// Use this method to get current webhook status. /// @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct GetWebhookInfo { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, } #[async_trait::async_trait] @@ -39,7 +38,7 @@ impl Request for GetWebhookInfo { } impl GetWebhookInfo { - pub(crate) fn new(bot: Arc) -> Self { + pub(crate) fn new(bot: Bot) -> Self { Self { bot } } } diff --git a/src/requests/all/kick_chat_member.rs b/src/requests/all/kick_chat_member.rs index 20941b87..85e09946 100644 --- a/src/requests/all/kick_chat_member.rs +++ b/src/requests/all/kick_chat_member.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to kick a user from a group, a supergroup or a channel. /// @@ -22,7 +21,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct KickChatMember { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, user_id: i32, until_date: Option, @@ -44,7 +43,7 @@ impl Request for KickChatMember { } impl KickChatMember { - pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, user_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/leave_chat.rs b/src/requests/all/leave_chat.rs index d2dc5f14..3bcf7c3d 100644 --- a/src/requests/all/leave_chat.rs +++ b/src/requests/all/leave_chat.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method for your bot to leave a group, supergroup or channel. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct LeaveChat { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -35,7 +34,7 @@ impl Request for LeaveChat { } impl LeaveChat { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/pin_chat_message.rs b/src/requests/all/pin_chat_message.rs index 58d9b402..2fb906da 100644 --- a/src/requests/all/pin_chat_message.rs +++ b/src/requests/all/pin_chat_message.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to pin a message in a group, a supergroup, or a channel. /// @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct PinChatMessage { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, message_id: i32, disable_notification: Option, @@ -41,7 +40,7 @@ impl Request for PinChatMessage { } impl PinChatMessage { - pub(crate) fn new(bot: Arc, chat_id: C, message_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, message_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/promote_chat_member.rs b/src/requests/all/promote_chat_member.rs index 32919b0f..fa9ad1a0 100644 --- a/src/requests/all/promote_chat_member.rs +++ b/src/requests/all/promote_chat_member.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to promote or demote a user in a supergroup or a channel. /// @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct PromoteChatMember { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, user_id: i32, can_change_info: Option, @@ -48,7 +47,7 @@ impl Request for PromoteChatMember { } impl PromoteChatMember { - pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, user_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/restrict_chat_member.rs b/src/requests/all/restrict_chat_member.rs index 9b51be5e..d019d837 100644 --- a/src/requests/all/restrict_chat_member.rs +++ b/src/requests/all/restrict_chat_member.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, ChatPermissions, True}, Bot, }; -use std::sync::Arc; /// Use this method to restrict a user in a supergroup. /// @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct RestrictChatMember { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, user_id: i32, permissions: ChatPermissions, @@ -43,7 +42,7 @@ impl Request for RestrictChatMember { impl RestrictChatMember { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, user_id: i32, permissions: ChatPermissions, diff --git a/src/requests/all/send_animation.rs b/src/requests/all/send_animation.rs index ee5f2d39..287ebd93 100644 --- a/src/requests/all/send_animation.rs +++ b/src/requests/all/send_animation.rs @@ -4,7 +4,6 @@ use crate::{ 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). @@ -15,7 +14,7 @@ use std::sync::Arc; /// [The official docs](https://core.telegram.org/bots/api#sendanimation). #[derive(Debug, Clone)] pub struct SendAnimation { - bot: Arc, + bot: Bot, pub chat_id: ChatId, pub animation: InputFile, pub duration: Option, @@ -60,11 +59,7 @@ impl RequestWithFile for SendAnimation { } impl SendAnimation { - pub(crate) fn new( - bot: Arc, - chat_id: C, - animation: InputFile, - ) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, animation: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_audio.rs b/src/requests/all/send_audio.rs index f7f45f27..f2ed209f 100644 --- a/src/requests/all/send_audio.rs +++ b/src/requests/all/send_audio.rs @@ -4,7 +4,6 @@ use crate::{ 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. @@ -19,7 +18,7 @@ use std::sync::Arc; /// [`Bot::send_voice`]: crate::Bot::send_voice #[derive(Debug, Clone)] pub struct SendAudio { - bot: Arc, + bot: Bot, chat_id: ChatId, audio: InputFile, caption: Option, @@ -64,7 +63,7 @@ impl RequestWithFile for SendAudio { } impl SendAudio { - pub(crate) fn new(bot: Arc, chat_id: C, audio: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, audio: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_chat_action.rs b/src/requests/all/send_chat_action.rs index 8a6e4f7a..299bcb12 100644 --- a/src/requests/all/send_chat_action.rs +++ b/src/requests/all/send_chat_action.rs @@ -6,7 +6,6 @@ use crate::{ 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. @@ -29,7 +28,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendChatAction { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, action: SendChatActionKind, } @@ -88,7 +87,7 @@ impl Request for SendChatAction { impl SendChatAction { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, action: SendChatActionKind, ) -> Self diff --git a/src/requests/all/send_contact.rs b/src/requests/all/send_contact.rs index 1ad6d0b6..4b8e0aa9 100644 --- a/src/requests/all/send_contact.rs +++ b/src/requests/all/send_contact.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, Message, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send phone contacts. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendContact { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, phone_number: String, first_name: String, @@ -43,7 +42,7 @@ impl Request for SendContact { impl SendContact { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, phone_number: P, first_name: F, diff --git a/src/requests/all/send_document.rs b/src/requests/all/send_document.rs index bd97fb91..a3b6ff6f 100644 --- a/src/requests/all/send_document.rs +++ b/src/requests/all/send_document.rs @@ -4,7 +4,6 @@ use crate::{ types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send general files. /// @@ -14,7 +13,7 @@ use std::sync::Arc; /// [The official docs](https://core.telegram.org/bots/api#senddocument). #[derive(Debug, Clone)] pub struct SendDocument { - bot: Arc, + bot: Bot, chat_id: ChatId, document: InputFile, thumb: Option, @@ -53,7 +52,7 @@ impl RequestWithFile for SendDocument { } impl SendDocument { - pub(crate) fn new(bot: Arc, chat_id: C, document: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, document: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_game.rs b/src/requests/all/send_game.rs index 53555c06..da42e2f6 100644 --- a/src/requests/all/send_game.rs +++ b/src/requests/all/send_game.rs @@ -6,7 +6,6 @@ use crate::{ types::{InlineKeyboardMarkup, Message}, Bot, }; -use std::sync::Arc; /// Use this method to send a game. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendGame { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: i32, game_short_name: String, disable_notification: Option, @@ -39,11 +38,7 @@ impl Request for SendGame { } impl SendGame { - pub(crate) fn new( - bot: Arc, - chat_id: i32, - game_short_name: G, - ) -> Self + pub(crate) fn new(bot: Bot, chat_id: i32, game_short_name: G) -> Self where G: Into, { diff --git a/src/requests/all/send_invoice.rs b/src/requests/all/send_invoice.rs index b9e710e3..f00b0dc7 100644 --- a/src/requests/all/send_invoice.rs +++ b/src/requests/all/send_invoice.rs @@ -6,7 +6,6 @@ use crate::{ types::{InlineKeyboardMarkup, LabeledPrice, Message}, Bot, }; -use std::sync::Arc; /// Use this method to send invoices. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendInvoice { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: i32, title: String, description: String, @@ -59,7 +58,7 @@ impl Request for SendInvoice { impl SendInvoice { #[allow(clippy::too_many_arguments)] pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: i32, title: T, description: D, diff --git a/src/requests/all/send_location.rs b/src/requests/all/send_location.rs index 149d7a5c..b91c4531 100644 --- a/src/requests/all/send_location.rs +++ b/src/requests/all/send_location.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, Message, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send point on the map. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendLocation { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, latitude: f32, longitude: f32, @@ -42,7 +41,7 @@ impl Request for SendLocation { impl SendLocation { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, latitude: f32, longitude: f32, diff --git a/src/requests/all/send_media_group.rs b/src/requests/all/send_media_group.rs index b6f2d9c3..5dfad7e0 100644 --- a/src/requests/all/send_media_group.rs +++ b/src/requests/all/send_media_group.rs @@ -4,14 +4,13 @@ use crate::{ 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(Debug, Clone)] pub struct SendMediaGroup { - bot: Arc, + bot: Bot, chat_id: ChatId, media: Vec, // TODO: InputMediaPhoto and InputMediaVideo disable_notification: Option, @@ -39,7 +38,7 @@ impl Request for SendMediaGroup { } impl SendMediaGroup { - pub(crate) fn new(bot: Arc, chat_id: C, media: M) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, media: M) -> Self where C: Into, M: Into>, diff --git a/src/requests/all/send_message.rs b/src/requests/all/send_message.rs index 689d9671..2020fed7 100644 --- a/src/requests/all/send_message.rs +++ b/src/requests/all/send_message.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, Message, ParseMode, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send text messages. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendMessage { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, pub chat_id: ChatId, pub text: String, pub parse_mode: Option, @@ -41,7 +40,7 @@ impl Request for SendMessage { } impl SendMessage { - pub(crate) fn new(bot: Arc, chat_id: C, text: T) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, text: T) -> Self where C: Into, T: Into, diff --git a/src/requests/all/send_photo.rs b/src/requests/all/send_photo.rs index 247257b1..4027f000 100644 --- a/src/requests/all/send_photo.rs +++ b/src/requests/all/send_photo.rs @@ -4,14 +4,13 @@ use crate::{ 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(Debug, Clone)] pub struct SendPhoto { - bot: Arc, + bot: Bot, chat_id: ChatId, photo: InputFile, caption: Option, @@ -46,7 +45,7 @@ impl RequestWithFile for SendPhoto { } impl SendPhoto { - pub(crate) fn new(bot: Arc, chat_id: C, photo: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, photo: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_poll.rs b/src/requests/all/send_poll.rs index a2fafd42..0e736f75 100644 --- a/src/requests/all/send_poll.rs +++ b/src/requests/all/send_poll.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, Message, PollType, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send a native poll. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendPoll { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, question: String, options: Vec, @@ -46,7 +45,7 @@ impl Request for SendPoll { impl SendPoll { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, question: Q, options: O, diff --git a/src/requests/all/send_sticker.rs b/src/requests/all/send_sticker.rs index 37ca4769..5e019e19 100644 --- a/src/requests/all/send_sticker.rs +++ b/src/requests/all/send_sticker.rs @@ -4,7 +4,6 @@ use crate::{ types::{ChatId, InputFile, Message, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send static .WEBP or [animated] .TGS stickers. /// @@ -13,7 +12,7 @@ use std::sync::Arc; /// [animated]: https://telegram.org/blog/animated-stickers #[derive(Debug, Clone)] pub struct SendSticker { - bot: Arc, + bot: Bot, chat_id: ChatId, sticker: InputFile, disable_notification: Option, @@ -44,7 +43,7 @@ impl RequestWithFile for SendSticker { } impl SendSticker { - pub(crate) fn new(bot: Arc, chat_id: C, sticker: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, sticker: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_venue.rs b/src/requests/all/send_venue.rs index c049aeb2..0567ba67 100644 --- a/src/requests/all/send_venue.rs +++ b/src/requests/all/send_venue.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, Message, ReplyMarkup}, Bot, }; -use std::sync::Arc; /// Use this method to send information about a venue. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SendVenue { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, latitude: f32, longitude: f32, @@ -45,7 +44,7 @@ impl Request for SendVenue { impl SendVenue { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, latitude: f32, longitude: f32, diff --git a/src/requests/all/send_video.rs b/src/requests/all/send_video.rs index b908fa5e..30ab6a45 100644 --- a/src/requests/all/send_video.rs +++ b/src/requests/all/send_video.rs @@ -4,7 +4,6 @@ use crate::{ 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). @@ -15,7 +14,7 @@ use std::sync::Arc; /// [The official docs](https://core.telegram.org/bots/api#sendvideo). #[derive(Debug, Clone)] pub struct SendVideo { - bot: Arc, + bot: Bot, chat_id: ChatId, video: InputFile, duration: Option, @@ -62,7 +61,7 @@ impl RequestWithFile for SendVideo { } impl SendVideo { - pub(crate) fn new(bot: Arc, chat_id: C, video: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, video: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_video_note.rs b/src/requests/all/send_video_note.rs index e06f804b..2ac653be 100644 --- a/src/requests/all/send_video_note.rs +++ b/src/requests/all/send_video_note.rs @@ -4,7 +4,6 @@ use crate::{ 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. @@ -14,7 +13,7 @@ use std::sync::Arc; /// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope #[derive(Debug, Clone)] pub struct SendVideoNote { - bot: Arc, + bot: Bot, chat_id: ChatId, video_note: InputFile, duration: Option, @@ -53,11 +52,7 @@ impl RequestWithFile for SendVideoNote { } impl SendVideoNote { - pub(crate) fn new( - bot: Arc, - chat_id: C, - video_note: InputFile, - ) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, video_note: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/send_voice.rs b/src/requests/all/send_voice.rs index 44f69fc7..1e50bbed 100644 --- a/src/requests/all/send_voice.rs +++ b/src/requests/all/send_voice.rs @@ -4,7 +4,6 @@ use crate::{ 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. @@ -20,7 +19,7 @@ use std::sync::Arc; /// [`Document`]: crate::types::Document #[derive(Debug, Clone)] pub struct SendVoice { - bot: Arc, + bot: Bot, chat_id: ChatId, voice: InputFile, caption: Option, @@ -57,7 +56,7 @@ impl RequestWithFile for SendVoice { } impl SendVoice { - pub(crate) fn new(bot: Arc, chat_id: C, voice: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, voice: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/set_chat_administrator_custom_title.rs b/src/requests/all/set_chat_administrator_custom_title.rs index 3ab9662f..2d85ad06 100644 --- a/src/requests/all/set_chat_administrator_custom_title.rs +++ b/src/requests/all/set_chat_administrator_custom_title.rs @@ -6,7 +6,6 @@ use crate::{ 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. @@ -16,7 +15,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetChatAdministratorCustomTitle { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, user_id: i32, custom_title: String, @@ -39,7 +38,7 @@ impl Request for SetChatAdministratorCustomTitle { impl SetChatAdministratorCustomTitle { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, user_id: i32, custom_title: CT, diff --git a/src/requests/all/set_chat_description.rs b/src/requests/all/set_chat_description.rs index 36501464..006325d0 100644 --- a/src/requests/all/set_chat_description.rs +++ b/src/requests/all/set_chat_description.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to change the description of a group, a supergroup or a /// channel. @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetChatDescription { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, description: Option, } @@ -40,7 +39,7 @@ impl Request for SetChatDescription { } impl SetChatDescription { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/set_chat_permissions.rs b/src/requests/all/set_chat_permissions.rs index 8ee647b4..754cd565 100644 --- a/src/requests/all/set_chat_permissions.rs +++ b/src/requests/all/set_chat_permissions.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, ChatPermissions, True}, Bot, }; -use std::sync::Arc; /// Use this method to set default chat permissions for all members. /// @@ -18,7 +17,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetChatPermissions { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, permissions: ChatPermissions, } @@ -40,7 +39,7 @@ impl Request for SetChatPermissions { impl SetChatPermissions { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_id: C, permissions: ChatPermissions, ) -> Self diff --git a/src/requests/all/set_chat_photo.rs b/src/requests/all/set_chat_photo.rs index ba9d8960..f49ec12a 100644 --- a/src/requests/all/set_chat_photo.rs +++ b/src/requests/all/set_chat_photo.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, InputFile, True}, Bot, }; -use std::sync::Arc; /// Use this method to set a new profile photo for the chat. /// @@ -18,7 +17,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetChatPhoto { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, photo: InputFile, } @@ -39,7 +38,7 @@ impl Request for SetChatPhoto { } impl SetChatPhoto { - pub(crate) fn new(bot: Arc, chat_id: C, photo: InputFile) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, photo: InputFile) -> Self where C: Into, { diff --git a/src/requests/all/set_chat_sticker_set.rs b/src/requests/all/set_chat_sticker_set.rs index b4c60c4e..2d59199e 100644 --- a/src/requests/all/set_chat_sticker_set.rs +++ b/src/requests/all/set_chat_sticker_set.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to set a new group sticker set for a supergroup. /// @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetChatStickerSet { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, sticker_set_name: String, } @@ -40,11 +39,7 @@ impl Request for SetChatStickerSet { } impl SetChatStickerSet { - pub(crate) fn new( - bot: Arc, - chat_id: C, - sticker_set_name: S, - ) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, sticker_set_name: S) -> Self where C: Into, S: Into, diff --git a/src/requests/all/set_chat_title.rs b/src/requests/all/set_chat_title.rs index 1a69cb79..447d7eef 100644 --- a/src/requests/all/set_chat_title.rs +++ b/src/requests/all/set_chat_title.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to change the title of a chat. /// @@ -18,7 +17,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetChatTitle { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, title: String, } @@ -39,7 +38,7 @@ impl Request for SetChatTitle { } impl SetChatTitle { - pub(crate) fn new(bot: Arc, chat_id: C, title: T) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, title: T) -> Self where C: Into, T: Into, diff --git a/src/requests/all/set_game_score.rs b/src/requests/all/set_game_score.rs index 679ca708..c7ea8853 100644 --- a/src/requests/all/set_game_score.rs +++ b/src/requests/all/set_game_score.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, Message}, Bot, }; -use std::sync::Arc; /// Use this method to set the score of the specified user in a game. /// @@ -23,7 +22,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetGameScore { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, user_id: i32, @@ -49,7 +48,7 @@ impl Request for SetGameScore { impl SetGameScore { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, user_id: i32, score: i32, diff --git a/src/requests/all/set_sticker_position_in_set.rs b/src/requests/all/set_sticker_position_in_set.rs index 263cce75..325efbb7 100644 --- a/src/requests/all/set_sticker_position_in_set.rs +++ b/src/requests/all/set_sticker_position_in_set.rs @@ -6,7 +6,6 @@ use crate::{ 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. @@ -16,7 +15,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetStickerPositionInSet { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, sticker: String, position: i32, } @@ -37,7 +36,7 @@ impl Request for SetStickerPositionInSet { } impl SetStickerPositionInSet { - pub(crate) fn new(bot: Arc, sticker: S, position: i32) -> Self + pub(crate) fn new(bot: Bot, sticker: S, position: i32) -> Self where S: Into, { diff --git a/src/requests/all/set_webhook.rs b/src/requests/all/set_webhook.rs index ad293b5c..45ef9fd6 100644 --- a/src/requests/all/set_webhook.rs +++ b/src/requests/all/set_webhook.rs @@ -6,7 +6,6 @@ use crate::{ types::{AllowedUpdate, InputFile, True}, Bot, }; -use std::sync::Arc; /// Use this method to specify a url and receive incoming updates via an /// outgoing webhook. @@ -28,7 +27,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct SetWebhook { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, url: String, certificate: Option, max_connections: Option, @@ -51,7 +50,7 @@ impl Request for SetWebhook { } impl SetWebhook { - pub(crate) fn new(bot: Arc, url: U) -> Self + pub(crate) fn new(bot: Bot, url: U) -> Self where U: Into, { diff --git a/src/requests/all/stop_message_live_location.rs b/src/requests/all/stop_message_live_location.rs index a93badcc..08c625a9 100644 --- a/src/requests/all/stop_message_live_location.rs +++ b/src/requests/all/stop_message_live_location.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatOrInlineMessage, InlineKeyboardMarkup, Message}, Bot, }; -use std::sync::Arc; /// Use this method to stop updating a live location message before /// `live_period` expires. @@ -22,7 +21,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct StopMessageLiveLocation { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, #[serde(flatten)] chat_or_inline_message: ChatOrInlineMessage, reply_markup: Option, @@ -45,7 +44,7 @@ impl Request for StopMessageLiveLocation { impl StopMessageLiveLocation { pub(crate) fn new( - bot: Arc, + bot: Bot, chat_or_inline_message: ChatOrInlineMessage, ) -> Self { Self { 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 88057d8e..b513bd86 100644 --- a/src/requests/all/stop_poll.rs +++ b/src/requests/all/stop_poll.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, InlineKeyboardMarkup, Poll}, Bot, }; -use std::sync::Arc; /// Use this method to stop a poll which was sent by the bot. /// @@ -15,7 +14,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct StopPoll { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, message_id: i32, reply_markup: Option, @@ -39,7 +38,7 @@ impl Request for StopPoll { } } impl StopPoll { - pub(crate) fn new(bot: Arc, chat_id: C, message_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, message_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/unban_chat_member.rs b/src/requests/all/unban_chat_member.rs index 43b2c3f3..955c5ba9 100644 --- a/src/requests/all/unban_chat_member.rs +++ b/src/requests/all/unban_chat_member.rs @@ -6,7 +6,6 @@ use crate::{ 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, @@ -18,7 +17,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct UnbanChatMember { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, user_id: i32, } @@ -39,7 +38,7 @@ impl Request for UnbanChatMember { } impl UnbanChatMember { - pub(crate) fn new(bot: Arc, chat_id: C, user_id: i32) -> Self + pub(crate) fn new(bot: Bot, chat_id: C, user_id: i32) -> Self where C: Into, { diff --git a/src/requests/all/unpin_chat_message.rs b/src/requests/all/unpin_chat_message.rs index 926719b2..4d4a0775 100644 --- a/src/requests/all/unpin_chat_message.rs +++ b/src/requests/all/unpin_chat_message.rs @@ -6,7 +6,6 @@ use crate::{ types::{ChatId, True}, Bot, }; -use std::sync::Arc; /// Use this method to unpin a message in a group, a supergroup, or a channel. /// @@ -19,7 +18,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct UnpinChatMessage { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, chat_id: ChatId, } @@ -39,7 +38,7 @@ impl Request for UnpinChatMessage { } impl UnpinChatMessage { - pub(crate) fn new(bot: Arc, chat_id: C) -> Self + pub(crate) fn new(bot: Bot, chat_id: C) -> Self where C: Into, { diff --git a/src/requests/all/upload_sticker_file.rs b/src/requests/all/upload_sticker_file.rs index 2266c5f9..3e8b0ea4 100644 --- a/src/requests/all/upload_sticker_file.rs +++ b/src/requests/all/upload_sticker_file.rs @@ -6,7 +6,6 @@ use crate::{ 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 @@ -20,7 +19,7 @@ use std::sync::Arc; #[derive(Debug, Clone, Serialize)] pub struct UploadStickerFile { #[serde(skip_serializing)] - bot: Arc, + bot: Bot, user_id: i32, png_sticker: InputFile, } @@ -40,11 +39,7 @@ impl Request for UploadStickerFile { } impl UploadStickerFile { - pub(crate) fn new( - bot: Arc, - user_id: i32, - png_sticker: InputFile, - ) -> Self { + pub(crate) fn new(bot: Bot, user_id: i32, png_sticker: InputFile) -> Self { Self { bot, user_id, png_sticker } } diff --git a/tests/command.rs b/tests/command.rs index 47b3555f..fd474c2a 100644 --- a/tests/command.rs +++ b/tests/command.rs @@ -135,11 +135,13 @@ fn parse_custom_parser() { )) } }; - left.parse::().map(|res| (res, right.to_string())).map_err(|_| { - ParseError::Custom( - "First argument must be a integer!".to_owned().into(), - ) - }) + left.parse::().map(|res| (res, (*right).to_string())).map_err( + |_| { + ParseError::Custom( + "First argument must be a integer!".to_owned().into(), + ) + }, + ) } #[command(rename = "lowercase")]