From 3d69d9618249b3c9d38f368c098d4ea1a715b955 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 22 Mar 2022 22:08:47 +0400 Subject: [PATCH 01/15] Fix chat unmark --- src/types/chat_id.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index c996c7f3..8a5b88a9 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -23,18 +23,21 @@ impl ChatId { pub(crate) fn unmark(&self) -> Option { use UnmarkedChatId::*; - const MAX_CHANNEL_ID: i64 = -(10i64.pow(12)); - const MIN_CHANNEL_ID: i64 = MAX_CHANNEL_ID - (i32::MAX as i64); - const MAX_USER_ID: i64 = i32::MAX as _; - const MIN_CHAT_ID: i64 = -MAX_USER_ID; + // https://github.com/mtcute/mtcute/blob/6933ecc3f82dd2e9100f52b0afec128af564713b/packages/core/src/utils/peer-utils.ts#L4 + const MIN_MARKED_CHANNEL_ID: i64 = -1997852516352; + const MAX_MARKED_CHANNEL_ID: i64 = -1000000000000; + const MIN_MARKED_CHAT_ID: i64 = MAX_MARKED_CHANNEL_ID + 1; + const MAX_MARKED_CHAT_ID: i64 = MIN_USER_ID - 1; + const MIN_USER_ID: i64 = 0; + const MAX_USER_ID: i64 = (1 << 40) - 1; let res = match self { - &Self::Id(id @ MIN_CHAT_ID..=-1) => Chat(-id as _), - &Self::Id(id @ MIN_CHANNEL_ID..=MAX_CHANNEL_ID) => Channel((MAX_CHANNEL_ID - id) as _), - &Self::Id(id) => { - debug_assert!(0 < id && id < MAX_USER_ID, "malformed chat id: {}", id); - User(id as _) + &Self::Id(id @ MIN_MARKED_CHAT_ID..=MAX_MARKED_CHAT_ID) => Chat(-id as _), + &Self::Id(id @ MIN_MARKED_CHANNEL_ID..=MAX_MARKED_CHANNEL_ID) => { + Channel((MAX_MARKED_CHANNEL_ID - id) as _) } + &Self::Id(id @ MIN_USER_ID..=MAX_USER_ID) => User(id as _), + &Self::Id(id) => panic!("malformed chat id: {}", id), Self::ChannelUsername(_) => return None, }; @@ -43,9 +46,9 @@ impl ChatId { } pub(crate) enum UnmarkedChatId { - User(u32), - Chat(u32), - Channel(u32), + User(u64), + Chat(u64), + Channel(u64), } #[cfg(test)] @@ -68,4 +71,12 @@ mod tests { assert_eq!(expected_json, actual_json) } + + #[test] + fn user_id_unmark() { + assert!(matches!( + ChatId::Id(5298363099).unmark(), + Some(UnmarkedChatId::User(5298363099)) + )); + } } From ecf90c8c0535e2a0123bfcce40066613b49977ec Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Thu, 24 Mar 2022 17:51:34 +0400 Subject: [PATCH 02/15] Fix a typo in documentation --- src/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.rs b/src/types.rs index 751b1842..2d7e80c8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,4 +1,4 @@ -//! Telergam API types. +//! Telegram API types. pub use allowed_update::*; pub use animation::*; From 22cfffc704b93d12053ca402f498155337b18369 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 21:32:01 +0400 Subject: [PATCH 03/15] Fix some more typos --- src/adaptors/throttle.rs | 18 +++++++++--------- src/lib.rs | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/adaptors/throttle.rs b/src/adaptors/throttle.rs index 3e8ef88b..60848b22 100644 --- a/src/adaptors/throttle.rs +++ b/src/adaptors/throttle.rs @@ -108,7 +108,7 @@ impl Throttle { /// /// [`RequesterExt::throttle`]: crate::requests::RequesterExt::throttle pub fn new_spawn(bot: B, limits: Limits) -> Self { - // new/with_settings copypasted here to avoid [rust-lang/#76882] + // new/with_settings copy-pasted here to avoid [rust-lang/#76882] // // [rust-lang/#76882]: https://github.com/rust-lang/rust/issues/76882 @@ -132,7 +132,7 @@ impl Throttle { /// Creates new [`Throttle`] spawning the worker with `tokio::spawn` pub fn spawn_with_settings(bot: B, settings: Settings) -> Self { - // with_settings copypasted here to avoid [rust-lang/#76882] + // with_settings copy-pasted here to avoid [rust-lang/#76882] // // [rust-lang/#76882]: https://github.com/rust-lang/rust/issues/76882 @@ -174,7 +174,7 @@ impl Throttle { /// Sets new limits. /// - /// Note: changes may not be applied imidiately. + /// Note: changes may not be applied immediately. pub async fn set_limits(&self, new: Limits) { let (tx, rx) = oneshot::channel(); @@ -286,7 +286,7 @@ const SECOND: Duration = Duration::from_secs(1); // want to change this. const DELAY: Duration = Duration::from_millis(250); -/// Minimal time beetween calls to queue_full function +/// Minimal time between calls to queue_full function const QUEUE_FULL_DELAY: Duration = Duration::from_secs(4); #[derive(Debug)] @@ -375,12 +375,12 @@ async fn worker( while !rx_is_closed || !queue.is_empty() { // FIXME(waffle): // 1. If the `queue` is empty, `read_from_rx` call down below will 'block' - // execution untill a request is sent. While the execution is 'blocked' no + // execution until a request is sent. While the execution is 'blocked' no // `InfoMessage`s could be answered. // - // 2. If limits are descreased, ideally we want to shrink queue. + // 2. If limits are decreased, ideally we want to shrink queue. // - // *blocked in asyncronous way + // *blocked in asynchronous way answer_info(&mut info_rx, &mut limits); read_from_rx(&mut rx, &mut queue, &mut rx_is_closed).await; @@ -428,7 +428,7 @@ async fn worker( let min_back = now - MINUTE; let sec_back = now - SECOND; - // make history and hchats up-to-date + // make history and requests_sent up-to-date while let Some((_, time)) = history.front() { // history is sorted, we found first up-to-date thing if time >= &min_back { @@ -529,7 +529,7 @@ async fn read_from_rx(rx: &mut mpsc::Receiver, queue: &mut Vec, rx_is_c } } - // Don't grow queue bigger than the capacity to limit DOS posibility + // Don't grow queue bigger than the capacity to limit DOS possibility while queue.len() < queue.capacity() { // FIXME(waffle): https://github.com/tokio-rs/tokio/issues/3350 match tokio::task::unconstrained(rx.recv()).now_or_never() { diff --git a/src/lib.rs b/src/lib.rs index 1f222b6b..4fa831d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ //! //! This library provides tools for making requests to the [Telegram Bot API] //! (Currently, version `5.3` is supported) with ease. The library is fully -//! asynchronouns and built using [`tokio`]. +//! asynchronous and built using [`tokio`]. //! //!```toml //! teloxide_core = "0.4" @@ -51,8 +51,8 @@ //! - `erased` — enables [`ErasedRequester`] bot adaptor //! - `throttle` — enables [`Throttle`] bot adaptor //! - `cache_me` — enables [`CacheMe`] bot adaptor -//! - `full` — enables all features except `nigthly` and tls-related -//! - `nightly` — enables nigthly-only features, currently: +//! - `full` — enables all features except `nightly` and tls-related +//! - `nightly` — enables nightly-only features, currently: //! - Removes some future boxing using `#![feature(type_alias_impl_trait)]` //! - Used to built docs (`#![feature(doc_cfg, doc_notable_trait)]`) //! From 35e5bac766e80207adc28be6d1243b33b54f49a1 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 21:40:00 +0400 Subject: [PATCH 04/15] Pin nightly compiler version in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16523ee9..9cbd2f16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,14 +35,14 @@ jobs: rust: - stable - beta - - nightly + - nightly-2022-01-17 include: - rust: stable features: "--features full" - rust: beta features: "--features full" - - rust: nightly + - rust: nightly-2022-01-17 features: "--all-features" steps: From ad56195e52cbea8d14c2973f06affa4b67660b35 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 25 Mar 2022 13:12:26 +0400 Subject: [PATCH 05/15] Fix name of the nightly CI job --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cbd2f16..b1569708 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,14 +35,17 @@ jobs: rust: - stable - beta - - nightly-2022-01-17 + - nightly include: - rust: stable + toolchain: stable features: "--features full" - rust: beta + toolchain: beta features: "--features full" - - rust: nightly-2022-01-17 + - rust: nightly + toolchain: nightly-2022-01-17 features: "--all-features" steps: @@ -51,7 +54,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: ${{ matrix.toolchain }} override: true - name: build From 0a1d73c223017737c559e1d65e0c911180fca432 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 17:23:11 +0400 Subject: [PATCH 06/15] Rename `ChatId` => `Recipient` Reason: it isn't _really_ a chat id, it can also be a channel username. --- src/adaptors/cache_me.rs | 2 +- src/adaptors/erased.rs | 255 +++++++++--------- src/adaptors/parse_mode.rs | 4 +- src/adaptors/throttle.rs | 10 +- src/bot/api.rs | 122 ++++----- src/local_macros.rs | 118 ++++---- src/payloads/approve_chat_join_request.rs | 4 +- src/payloads/ban_chat_member.rs | 4 +- src/payloads/ban_chat_sender_chat.rs | 4 +- src/payloads/copy_message.rs | 6 +- src/payloads/create_chat_invite_link.rs | 4 +- src/payloads/decline_chat_join_request.rs | 4 +- src/payloads/delete_chat_photo.rs | 4 +- src/payloads/delete_chat_sticker_set.rs | 4 +- src/payloads/delete_message.rs | 4 +- src/payloads/edit_chat_invite_link.rs | 4 +- src/payloads/edit_message_caption.rs | 4 +- src/payloads/edit_message_live_location.rs | 4 +- src/payloads/edit_message_media.rs | 4 +- src/payloads/edit_message_reply_markup.rs | 4 +- src/payloads/edit_message_text.rs | 4 +- src/payloads/export_chat_invite_link.rs | 4 +- src/payloads/forward_message.rs | 6 +- src/payloads/get_chat.rs | 4 +- src/payloads/get_chat_administrators.rs | 4 +- src/payloads/get_chat_member.rs | 4 +- src/payloads/get_chat_member_count.rs | 4 +- src/payloads/get_chat_members_count.rs | 4 +- src/payloads/kick_chat_member.rs | 4 +- src/payloads/leave_chat.rs | 4 +- src/payloads/pin_chat_message.rs | 4 +- src/payloads/promote_chat_member.rs | 4 +- src/payloads/restrict_chat_member.rs | 4 +- src/payloads/revoke_chat_invite_link.rs | 4 +- src/payloads/send_animation.rs | 4 +- src/payloads/send_audio.rs | 4 +- src/payloads/send_chat_action.rs | 4 +- src/payloads/send_contact.rs | 4 +- src/payloads/send_dice.rs | 4 +- src/payloads/send_document.rs | 4 +- src/payloads/send_invoice.rs | 4 +- src/payloads/send_location.rs | 4 +- src/payloads/send_media_group.rs | 4 +- src/payloads/send_message.rs | 4 +- src/payloads/send_photo.rs | 4 +- src/payloads/send_poll.rs | 4 +- src/payloads/send_sticker.rs | 4 +- src/payloads/send_venue.rs | 4 +- src/payloads/send_video.rs | 4 +- src/payloads/send_video_note.rs | 4 +- src/payloads/send_voice.rs | 4 +- .../set_chat_administrator_custom_title.rs | 4 +- src/payloads/set_chat_description.rs | 4 +- src/payloads/set_chat_permissions.rs | 4 +- src/payloads/set_chat_photo.rs | 4 +- src/payloads/set_chat_sticker_set.rs | 4 +- src/payloads/set_chat_title.rs | 4 +- src/payloads/stop_message_live_location.rs | 4 +- src/payloads/stop_poll.rs | 4 +- src/payloads/unban_chat_member.rs | 4 +- src/payloads/unban_chat_sender_chat.rs | 4 +- src/payloads/unpin_all_chat_messages.rs | 4 +- src/payloads/unpin_chat_message.rs | 4 +- src/requests/requester.rs | 122 ++++----- src/types.rs | 6 +- src/types/bot_command_scope.rs | 12 +- src/types/chat_id.rs | 81 ------ src/types/recipient.rs | 82 ++++++ src/types/target_message.rs | 4 +- 69 files changed, 532 insertions(+), 518 deletions(-) create mode 100644 src/types/recipient.rs diff --git a/src/adaptors/cache_me.rs b/src/adaptors/cache_me.rs index 65fd207e..04a3c902 100644 --- a/src/adaptors/cache_me.rs +++ b/src/adaptors/cache_me.rs @@ -12,7 +12,7 @@ use url::Url; use crate::{ payloads::GetMe, requests::{HasPayload, Request, Requester}, - types::{ChatId, Me, *}, + types::{Me, Recipient, *}, }; /// `get_me` cache. diff --git a/src/adaptors/erased.rs b/src/adaptors/erased.rs index 65f89f2f..3199c734 100644 --- a/src/adaptors/erased.rs +++ b/src/adaptors/erased.rs @@ -7,8 +7,8 @@ use crate::{ payloads::*, requests::{HasPayload, Output, Payload, Request, Requester}, types::{ - BotCommand, ChatAction, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, PassportElementError, TargetMessage, + BotCommand, ChatAction, ChatPermissions, InlineQueryResult, InputFile, InputMedia, + InputSticker, LabeledPrice, PassportElementError, Recipient, TargetMessage, }, }; @@ -207,82 +207,82 @@ trait ErasableRequester<'a> { fn send_message( &self, - chat_id: ChatId, + chat_id: Recipient, text: String, ) -> ErasedRequest<'a, SendMessage, Self::Err>; fn forward_message( &self, - chat_id: ChatId, - from_chat_id: ChatId, + chat_id: Recipient, + from_chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, ForwardMessage, Self::Err>; fn copy_message( &self, - chat_id: ChatId, - from_chat_id: ChatId, + chat_id: Recipient, + from_chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, CopyMessage, Self::Err>; fn send_photo( &self, - chat_id: ChatId, + chat_id: Recipient, photo: InputFile, ) -> ErasedRequest<'a, SendPhoto, Self::Err>; fn send_audio( &self, - chat_id: ChatId, + chat_id: Recipient, audio: InputFile, ) -> ErasedRequest<'a, SendAudio, Self::Err>; fn send_document( &self, - chat_id: ChatId, + chat_id: Recipient, document: InputFile, ) -> ErasedRequest<'a, SendDocument, Self::Err>; fn send_video( &self, - chat_id: ChatId, + chat_id: Recipient, video: InputFile, ) -> ErasedRequest<'a, SendVideo, Self::Err>; fn send_animation( &self, - chat_id: ChatId, + chat_id: Recipient, animation: InputFile, ) -> ErasedRequest<'a, SendAnimation, Self::Err>; fn send_voice( &self, - chat_id: ChatId, + chat_id: Recipient, voice: InputFile, ) -> ErasedRequest<'a, SendVoice, Self::Err>; fn send_video_note( &self, - chat_id: ChatId, + chat_id: Recipient, video_note: InputFile, ) -> ErasedRequest<'a, SendVideoNote, Self::Err>; fn send_media_group( &self, - chat_id: ChatId, + chat_id: Recipient, media: Vec, ) -> ErasedRequest<'a, SendMediaGroup, Self::Err>; fn send_location( &self, - chat_id: ChatId, + chat_id: Recipient, latitude: f64, longitude: f64, ) -> ErasedRequest<'a, SendLocation, Self::Err>; fn edit_message_live_location( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, latitude: f64, longitude: f64, @@ -297,7 +297,7 @@ trait ErasableRequester<'a> { fn stop_message_live_location( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, latitude: f64, longitude: f64, @@ -312,7 +312,7 @@ trait ErasableRequester<'a> { fn send_venue( &self, - chat_id: ChatId, + chat_id: Recipient, latitude: f64, longitude: f64, title: String, @@ -321,23 +321,23 @@ trait ErasableRequester<'a> { fn send_contact( &self, - chat_id: ChatId, + chat_id: Recipient, phone_number: String, first_name: String, ) -> ErasedRequest<'a, SendContact, Self::Err>; fn send_poll( &self, - chat_id: ChatId, + chat_id: Recipient, question: String, options: Vec, ) -> ErasedRequest<'a, SendPoll, Self::Err>; - fn send_dice(&self, chat_id: ChatId) -> ErasedRequest<'a, SendDice, Self::Err>; + fn send_dice(&self, chat_id: Recipient) -> ErasedRequest<'a, SendDice, Self::Err>; fn send_chat_action( &self, - chat_id: ChatId, + chat_id: Recipient, action: ChatAction, ) -> ErasedRequest<'a, SendChatAction, Self::Err>; @@ -350,163 +350,168 @@ trait ErasableRequester<'a> { fn ban_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, BanChatMember, Self::Err>; fn kick_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, KickChatMember, Self::Err>; fn unban_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, UnbanChatMember, Self::Err>; fn restrict_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, permissions: ChatPermissions, ) -> ErasedRequest<'a, RestrictChatMember, Self::Err>; fn promote_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, PromoteChatMember, Self::Err>; fn set_chat_administrator_custom_title( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, custom_title: String, ) -> ErasedRequest<'a, SetChatAdministratorCustomTitle, Self::Err>; fn ban_chat_sender_chat( &self, - chat_id: ChatId, + chat_id: Recipient, sender_chat_id: i64, ) -> ErasedRequest<'a, BanChatSenderChat, Self::Err>; fn unban_chat_sender_chat( &self, - chat_id: ChatId, + chat_id: Recipient, sender_chat_id: i64, ) -> ErasedRequest<'a, UnbanChatSenderChat, Self::Err>; fn set_chat_permissions( &self, - chat_id: ChatId, + chat_id: Recipient, permissions: ChatPermissions, ) -> ErasedRequest<'a, SetChatPermissions, Self::Err>; fn export_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, ExportChatInviteLink, Self::Err>; fn create_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, CreateChatInviteLink, Self::Err>; fn edit_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, invite_link: String, ) -> ErasedRequest<'a, EditChatInviteLink, Self::Err>; fn revoke_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, invite_link: String, ) -> ErasedRequest<'a, RevokeChatInviteLink, Self::Err>; /// For Telegram documentation see [`ApproveChatJoinRequest`]. fn approve_chat_join_request( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, ApproveChatJoinRequest, Self::Err>; /// For Telegram documentation see [`DeclineChatJoinRequest`]. fn decline_chat_join_request( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, DeclineChatJoinRequest, Self::Err>; fn set_chat_photo( &self, - chat_id: ChatId, + chat_id: Recipient, photo: InputFile, ) -> ErasedRequest<'a, SetChatPhoto, Self::Err>; - fn delete_chat_photo(&self, chat_id: ChatId) -> ErasedRequest<'a, DeleteChatPhoto, Self::Err>; + fn delete_chat_photo( + &self, + chat_id: Recipient, + ) -> ErasedRequest<'a, DeleteChatPhoto, Self::Err>; fn set_chat_title( &self, - chat_id: ChatId, + chat_id: Recipient, title: String, ) -> ErasedRequest<'a, SetChatTitle, Self::Err>; fn set_chat_description( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, SetChatDescription, Self::Err>; fn pin_chat_message( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, PinChatMessage, Self::Err>; - fn unpin_chat_message(&self, chat_id: ChatId) - -> ErasedRequest<'a, UnpinChatMessage, Self::Err>; + fn unpin_chat_message( + &self, + chat_id: Recipient, + ) -> ErasedRequest<'a, UnpinChatMessage, Self::Err>; fn unpin_all_chat_messages( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, UnpinAllChatMessages, Self::Err>; - fn leave_chat(&self, chat_id: ChatId) -> ErasedRequest<'a, LeaveChat, Self::Err>; + fn leave_chat(&self, chat_id: Recipient) -> ErasedRequest<'a, LeaveChat, Self::Err>; - fn get_chat(&self, chat_id: ChatId) -> ErasedRequest<'a, GetChat, Self::Err>; + fn get_chat(&self, chat_id: Recipient) -> ErasedRequest<'a, GetChat, Self::Err>; fn get_chat_administrators( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, GetChatAdministrators, Self::Err>; fn get_chat_member_count( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, GetChatMemberCount, Self::Err>; fn get_chat_members_count( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, GetChatMembersCount, Self::Err>; fn get_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, GetChatMember, Self::Err>; fn set_chat_sticker_set( &self, - chat_id: ChatId, + chat_id: Recipient, sticker_set_name: String, ) -> ErasedRequest<'a, SetChatStickerSet, Self::Err>; fn delete_chat_sticker_set( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, DeleteChatStickerSet, Self::Err>; fn answer_callback_query( @@ -531,7 +536,7 @@ trait ErasableRequester<'a> { fn edit_message_text( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, text: String, ) -> ErasedRequest<'a, EditMessageText, Self::Err>; @@ -544,7 +549,7 @@ trait ErasableRequester<'a> { fn edit_message_caption( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, EditMessageCaption, Self::Err>; @@ -555,7 +560,7 @@ trait ErasableRequester<'a> { fn edit_message_media( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, media: InputMedia, ) -> ErasedRequest<'a, EditMessageMedia, Self::Err>; @@ -568,7 +573,7 @@ trait ErasableRequester<'a> { fn edit_message_reply_markup( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, EditMessageReplyMarkup, Self::Err>; @@ -577,18 +582,21 @@ trait ErasableRequester<'a> { inline_message_id: String, ) -> ErasedRequest<'a, EditMessageReplyMarkupInline, Self::Err>; - fn stop_poll(&self, chat_id: ChatId, message_id: i32) - -> ErasedRequest<'a, StopPoll, Self::Err>; + fn stop_poll( + &self, + chat_id: Recipient, + message_id: i32, + ) -> ErasedRequest<'a, StopPoll, Self::Err>; fn delete_message( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, DeleteMessage, Self::Err>; fn send_sticker( &self, - chat_id: ChatId, + chat_id: Recipient, sticker: InputFile, ) -> ErasedRequest<'a, SendSticker, Self::Err>; @@ -638,7 +646,7 @@ trait ErasableRequester<'a> { #[allow(clippy::too_many_arguments)] fn send_invoice( &self, - chat_id: ChatId, + chat_id: Recipient, title: String, description: String, payload: String, @@ -729,7 +737,7 @@ where fn send_message( &self, - chat_id: ChatId, + chat_id: Recipient, text: String, ) -> ErasedRequest<'a, SendMessage, Self::Err> { Requester::send_message(self, chat_id, text).erase() @@ -737,8 +745,8 @@ where fn forward_message( &self, - chat_id: ChatId, - from_chat_id: ChatId, + chat_id: Recipient, + from_chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, ForwardMessage, Self::Err> { Requester::forward_message(self, chat_id, from_chat_id, message_id).erase() @@ -746,8 +754,8 @@ where fn copy_message( &self, - chat_id: ChatId, - from_chat_id: ChatId, + chat_id: Recipient, + from_chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, CopyMessage, Self::Err> { Requester::copy_message(self, chat_id, from_chat_id, message_id).erase() @@ -755,7 +763,7 @@ where fn send_photo( &self, - chat_id: ChatId, + chat_id: Recipient, photo: InputFile, ) -> ErasedRequest<'a, SendPhoto, Self::Err> { Requester::send_photo(self, chat_id, photo).erase() @@ -763,7 +771,7 @@ where fn send_audio( &self, - chat_id: ChatId, + chat_id: Recipient, audio: InputFile, ) -> ErasedRequest<'a, SendAudio, Self::Err> { Requester::send_audio(self, chat_id, audio).erase() @@ -771,7 +779,7 @@ where fn send_document( &self, - chat_id: ChatId, + chat_id: Recipient, document: InputFile, ) -> ErasedRequest<'a, SendDocument, Self::Err> { Requester::send_document(self, chat_id, document).erase() @@ -779,7 +787,7 @@ where fn send_video( &self, - chat_id: ChatId, + chat_id: Recipient, video: InputFile, ) -> ErasedRequest<'a, SendVideo, Self::Err> { Requester::send_video(self, chat_id, video).erase() @@ -787,7 +795,7 @@ where fn send_animation( &self, - chat_id: ChatId, + chat_id: Recipient, animation: InputFile, ) -> ErasedRequest<'a, SendAnimation, Self::Err> { Requester::send_animation(self, chat_id, animation).erase() @@ -795,7 +803,7 @@ where fn send_voice( &self, - chat_id: ChatId, + chat_id: Recipient, voice: InputFile, ) -> ErasedRequest<'a, SendVoice, Self::Err> { Requester::send_voice(self, chat_id, voice).erase() @@ -803,7 +811,7 @@ where fn send_video_note( &self, - chat_id: ChatId, + chat_id: Recipient, video_note: InputFile, ) -> ErasedRequest<'a, SendVideoNote, Self::Err> { Requester::send_video_note(self, chat_id, video_note).erase() @@ -811,7 +819,7 @@ where fn send_media_group( &self, - chat_id: ChatId, + chat_id: Recipient, media: Vec, ) -> ErasedRequest<'a, SendMediaGroup, Self::Err> { Requester::send_media_group(self, chat_id, media).erase() @@ -819,7 +827,7 @@ where fn send_location( &self, - chat_id: ChatId, + chat_id: Recipient, latitude: f64, longitude: f64, ) -> ErasedRequest<'a, SendLocation, Self::Err> { @@ -828,7 +836,7 @@ where fn edit_message_live_location( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, latitude: f64, longitude: f64, @@ -849,7 +857,7 @@ where fn stop_message_live_location( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, latitude: f64, longitude: f64, @@ -870,7 +878,7 @@ where fn send_venue( &self, - chat_id: ChatId, + chat_id: Recipient, latitude: f64, longitude: f64, title: String, @@ -881,7 +889,7 @@ where fn send_contact( &self, - chat_id: ChatId, + chat_id: Recipient, phone_number: String, first_name: String, ) -> ErasedRequest<'a, SendContact, Self::Err> { @@ -890,20 +898,20 @@ where fn send_poll( &self, - chat_id: ChatId, + chat_id: Recipient, question: String, options: Vec, ) -> ErasedRequest<'a, SendPoll, Self::Err> { Requester::send_poll(self, chat_id, question, options).erase() } - fn send_dice(&self, chat_id: ChatId) -> ErasedRequest<'a, SendDice, Self::Err> { + fn send_dice(&self, chat_id: Recipient) -> ErasedRequest<'a, SendDice, Self::Err> { Requester::send_dice(self, chat_id).erase() } fn send_chat_action( &self, - chat_id: ChatId, + chat_id: Recipient, action: ChatAction, ) -> ErasedRequest<'a, SendChatAction, Self::Err> { Requester::send_chat_action(self, chat_id, action).erase() @@ -922,7 +930,7 @@ where fn ban_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, BanChatMember, Self::Err> { Requester::ban_chat_member(self, chat_id, user_id).erase() @@ -930,7 +938,7 @@ where fn kick_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, KickChatMember, Self::Err> { Requester::kick_chat_member(self, chat_id, user_id).erase() @@ -938,7 +946,7 @@ where fn unban_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, UnbanChatMember, Self::Err> { Requester::unban_chat_member(self, chat_id, user_id).erase() @@ -946,7 +954,7 @@ where fn restrict_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, permissions: ChatPermissions, ) -> ErasedRequest<'a, RestrictChatMember, Self::Err> { @@ -955,7 +963,7 @@ where fn promote_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, PromoteChatMember, Self::Err> { Requester::promote_chat_member(self, chat_id, user_id).erase() @@ -963,7 +971,7 @@ where fn set_chat_administrator_custom_title( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, custom_title: String, ) -> ErasedRequest<'a, SetChatAdministratorCustomTitle, Self::Err> { @@ -972,7 +980,7 @@ where fn ban_chat_sender_chat( &self, - chat_id: ChatId, + chat_id: Recipient, sender_chat_id: i64, ) -> ErasedRequest<'a, BanChatSenderChat, Self::Err> { Requester::ban_chat_sender_chat(self, chat_id, sender_chat_id).erase() @@ -980,7 +988,7 @@ where fn unban_chat_sender_chat( &self, - chat_id: ChatId, + chat_id: Recipient, sender_chat_id: i64, ) -> ErasedRequest<'a, UnbanChatSenderChat, Self::Err> { Requester::unban_chat_sender_chat(self, chat_id, sender_chat_id).erase() @@ -988,7 +996,7 @@ where fn set_chat_permissions( &self, - chat_id: ChatId, + chat_id: Recipient, permissions: ChatPermissions, ) -> ErasedRequest<'a, SetChatPermissions, Self::Err> { Requester::set_chat_permissions(self, chat_id, permissions).erase() @@ -996,21 +1004,21 @@ where fn export_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, ExportChatInviteLink, Self::Err> { Requester::export_chat_invite_link(self, chat_id).erase() } fn create_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, CreateChatInviteLink, Self::Err> { Requester::create_chat_invite_link(self, chat_id).erase() } fn edit_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, invite_link: String, ) -> ErasedRequest<'a, EditChatInviteLink, Self::Err> { Requester::edit_chat_invite_link(self, chat_id, invite_link).erase() @@ -1018,7 +1026,7 @@ where fn revoke_chat_invite_link( &self, - chat_id: ChatId, + chat_id: Recipient, invite_link: String, ) -> ErasedRequest<'a, RevokeChatInviteLink, Self::Err> { Requester::revoke_chat_invite_link(self, chat_id, invite_link).erase() @@ -1027,7 +1035,7 @@ where /// For Telegram documentation see [`ApproveChatJoinRequest`]. fn approve_chat_join_request( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, ApproveChatJoinRequest, Self::Err> { Requester::approve_chat_join_request(self, chat_id, user_id).erase() @@ -1036,7 +1044,7 @@ where /// For Telegram documentation see [`DeclineChatJoinRequest`]. fn decline_chat_join_request( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, DeclineChatJoinRequest, Self::Err> { Requester::decline_chat_join_request(self, chat_id, user_id).erase() @@ -1044,19 +1052,22 @@ where fn set_chat_photo( &self, - chat_id: ChatId, + chat_id: Recipient, photo: InputFile, ) -> ErasedRequest<'a, SetChatPhoto, Self::Err> { Requester::set_chat_photo(self, chat_id, photo).erase() } - fn delete_chat_photo(&self, chat_id: ChatId) -> ErasedRequest<'a, DeleteChatPhoto, Self::Err> { + fn delete_chat_photo( + &self, + chat_id: Recipient, + ) -> ErasedRequest<'a, DeleteChatPhoto, Self::Err> { Requester::delete_chat_photo(self, chat_id).erase() } fn set_chat_title( &self, - chat_id: ChatId, + chat_id: Recipient, title: String, ) -> ErasedRequest<'a, SetChatTitle, Self::Err> { Requester::set_chat_title(self, chat_id, title).erase() @@ -1064,14 +1075,14 @@ where fn set_chat_description( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, SetChatDescription, Self::Err> { Requester::set_chat_description(self, chat_id).erase() } fn pin_chat_message( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, PinChatMessage, Self::Err> { Requester::pin_chat_message(self, chat_id, message_id).erase() @@ -1079,50 +1090,50 @@ where fn unpin_chat_message( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, UnpinChatMessage, Self::Err> { Requester::unpin_chat_message(self, chat_id).erase() } fn unpin_all_chat_messages( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, UnpinAllChatMessages, Self::Err> { Requester::unpin_all_chat_messages(self, chat_id).erase() } - fn leave_chat(&self, chat_id: ChatId) -> ErasedRequest<'a, LeaveChat, Self::Err> { + fn leave_chat(&self, chat_id: Recipient) -> ErasedRequest<'a, LeaveChat, Self::Err> { Requester::leave_chat(self, chat_id).erase() } - fn get_chat(&self, chat_id: ChatId) -> ErasedRequest<'a, GetChat, Self::Err> { + fn get_chat(&self, chat_id: Recipient) -> ErasedRequest<'a, GetChat, Self::Err> { Requester::get_chat(self, chat_id).erase() } fn get_chat_administrators( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, GetChatAdministrators, Self::Err> { Requester::get_chat_administrators(self, chat_id).erase() } fn get_chat_member_count( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, GetChatMemberCount, Self::Err> { Requester::get_chat_member_count(self, chat_id).erase() } fn get_chat_members_count( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, GetChatMembersCount, Self::Err> { Requester::get_chat_members_count(self, chat_id).erase() } fn get_chat_member( &self, - chat_id: ChatId, + chat_id: Recipient, user_id: i64, ) -> ErasedRequest<'a, GetChatMember, Self::Err> { Requester::get_chat_member(self, chat_id, user_id).erase() @@ -1130,7 +1141,7 @@ where fn set_chat_sticker_set( &self, - chat_id: ChatId, + chat_id: Recipient, sticker_set_name: String, ) -> ErasedRequest<'a, SetChatStickerSet, Self::Err> { Requester::set_chat_sticker_set(self, chat_id, sticker_set_name).erase() @@ -1138,7 +1149,7 @@ where fn delete_chat_sticker_set( &self, - chat_id: ChatId, + chat_id: Recipient, ) -> ErasedRequest<'a, DeleteChatStickerSet, Self::Err> { Requester::delete_chat_sticker_set(self, chat_id).erase() } @@ -1175,7 +1186,7 @@ where fn edit_message_text( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, text: String, ) -> ErasedRequest<'a, EditMessageText, Self::Err> { @@ -1192,7 +1203,7 @@ where fn edit_message_caption( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, EditMessageCaption, Self::Err> { Requester::edit_message_caption(self, chat_id, message_id).erase() @@ -1207,7 +1218,7 @@ where fn edit_message_media( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, media: InputMedia, ) -> ErasedRequest<'a, EditMessageMedia, Self::Err> { @@ -1224,7 +1235,7 @@ where fn edit_message_reply_markup( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, EditMessageReplyMarkup, Self::Err> { Requester::edit_message_reply_markup(self, chat_id, message_id).erase() @@ -1239,7 +1250,7 @@ where fn stop_poll( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, StopPoll, Self::Err> { Requester::stop_poll(self, chat_id, message_id).erase() @@ -1247,7 +1258,7 @@ where fn delete_message( &self, - chat_id: ChatId, + chat_id: Recipient, message_id: i32, ) -> ErasedRequest<'a, DeleteMessage, Self::Err> { Requester::delete_message(self, chat_id, message_id).erase() @@ -1255,7 +1266,7 @@ where fn send_sticker( &self, - chat_id: ChatId, + chat_id: Recipient, sticker: InputFile, ) -> ErasedRequest<'a, SendSticker, Self::Err> { Requester::send_sticker(self, chat_id, sticker).erase() @@ -1319,7 +1330,7 @@ where fn send_invoice( &self, - chat_id: ChatId, + chat_id: Recipient, title: String, description: String, payload: String, diff --git a/src/adaptors/parse_mode.rs b/src/adaptors/parse_mode.rs index 2433765e..62649ce5 100644 --- a/src/adaptors/parse_mode.rs +++ b/src/adaptors/parse_mode.rs @@ -3,7 +3,7 @@ use url::Url; use crate::{ prelude::Requester, requests::HasPayload, - types::{ChatId, InputFile, ParseMode, *}, + types::{InputFile, ParseMode, Recipient, *}, }; /// Default parse mode adaptor, see @@ -86,7 +86,7 @@ impl Requester for DefaultParseMode { fn send_poll(&self, chat_id: C, question: Q, options: O) -> Self::SendPoll where - C: Into, + C: Into, Q: Into, O: IntoIterator, { diff --git a/src/adaptors/throttle.rs b/src/adaptors/throttle.rs index 3e8ef88b..8c03535f 100644 --- a/src/adaptors/throttle.rs +++ b/src/adaptors/throttle.rs @@ -645,17 +645,17 @@ enum ChatIdHash { impl ChatIdHash { fn is_channel(&self) -> bool { match self { - &Self::Id(id) => ChatId::Id(id).is_channel(), + &Self::Id(id) => Recipient::Id(id).is_channel(), Self::ChannelUsernameHash(_) => true, } } } -impl From<&ChatId> for ChatIdHash { - fn from(value: &ChatId) -> Self { +impl From<&Recipient> for ChatIdHash { + fn from(value: &Recipient) -> Self { match value { - ChatId::Id(id) => ChatIdHash::Id(*id), - ChatId::ChannelUsername(username) => { + Recipient::Id(id) => ChatIdHash::Id(*id), + Recipient::ChannelUsername(username) => { let mut hasher = std::collections::hash_map::DefaultHasher::new(); username.hash(&mut hasher); let hash = hasher.finish(); diff --git a/src/bot/api.rs b/src/bot/api.rs index 580fc0db..d9462f01 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -5,8 +5,8 @@ use crate::{ prelude::Requester, requests::{JsonRequest, MultipartRequest}, types::{ - BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, + BotCommand, ChatPermissions, InlineQueryResult, InputFile, InputMedia, InputSticker, + LabeledPrice, Recipient, }, Bot, }; @@ -48,7 +48,7 @@ impl Requester for Bot { fn send_message(&self, chat_id: C, text: T) -> Self::SendMessage where - C: Into, + C: Into, T: Into, { Self::SendMessage::new(self.clone(), payloads::SendMessage::new(chat_id, text)) @@ -63,8 +63,8 @@ impl Requester for Bot { message_id: i32, ) -> Self::ForwardMessage where - C: Into, - F: Into, + C: Into, + F: Into, { Self::ForwardMessage::new( self.clone(), @@ -76,7 +76,7 @@ impl Requester for Bot { fn send_photo(&self, chat_id: C, photo: InputFile) -> Self::SendPhoto where - C: Into, + C: Into, { Self::SendPhoto::new(self.clone(), payloads::SendPhoto::new(chat_id, photo)) } @@ -85,7 +85,7 @@ impl Requester for Bot { fn send_audio(&self, chat_id: C, audio: InputFile) -> Self::SendAudio where - C: Into, + C: Into, { Self::SendAudio::new(self.clone(), payloads::SendAudio::new(chat_id, audio)) } @@ -94,7 +94,7 @@ impl Requester for Bot { fn send_document(&self, chat_id: C, document: InputFile) -> Self::SendDocument where - C: Into, + C: Into, { Self::SendDocument::new(self.clone(), payloads::SendDocument::new(chat_id, document)) } @@ -103,7 +103,7 @@ impl Requester for Bot { fn send_video(&self, chat_id: C, video: InputFile) -> Self::SendVideo where - C: Into, + C: Into, { Self::SendVideo::new(self.clone(), payloads::SendVideo::new(chat_id, video)) } @@ -112,7 +112,7 @@ impl Requester for Bot { fn send_animation(&self, chat_id: C, animation: InputFile) -> Self::SendAnimation where - C: Into, + C: Into, { Self::SendAnimation::new( self.clone(), @@ -124,7 +124,7 @@ impl Requester for Bot { fn send_voice(&self, chat_id: C, voice: InputFile) -> Self::SendVoice where - C: Into, + C: Into, { Self::SendVoice::new(self.clone(), payloads::SendVoice::new(chat_id, voice)) } @@ -133,7 +133,7 @@ impl Requester for Bot { fn send_video_note(&self, chat_id: C, video_note: InputFile) -> Self::SendVideoNote where - C: Into, + C: Into, { Self::SendVideoNote::new( self.clone(), @@ -145,7 +145,7 @@ impl Requester for Bot { fn send_media_group(&self, chat_id: C, media: M) -> Self::SendMediaGroup where - C: Into, + C: Into, M: IntoIterator, { Self::SendMediaGroup::new(self.clone(), payloads::SendMediaGroup::new(chat_id, media)) @@ -155,7 +155,7 @@ impl Requester for Bot { fn send_location(&self, chat_id: C, latitude: f64, longitude: f64) -> Self::SendLocation where - C: Into, + C: Into, { Self::SendLocation::new( self.clone(), @@ -173,7 +173,7 @@ impl Requester for Bot { longitude: f64, ) -> Self::EditMessageLiveLocation where - C: Into, + C: Into, { Self::EditMessageLiveLocation::new( self.clone(), @@ -208,7 +208,7 @@ impl Requester for Bot { longitude: f64, ) -> Self::StopMessageLiveLocation where - C: Into, + C: Into, { Self::StopMessageLiveLocation::new( self.clone(), @@ -244,7 +244,7 @@ impl Requester for Bot { address: A, ) -> Self::SendVenue where - C: Into, + C: Into, T: Into, A: Into, { @@ -258,7 +258,7 @@ impl Requester for Bot { fn send_contact(&self, chat_id: C, phone_number: P, first_name: F) -> Self::SendContact where - C: Into, + C: Into, P: Into, F: Into, { @@ -272,7 +272,7 @@ impl Requester for Bot { fn send_poll(&self, chat_id: C, question: Q, options: O) -> Self::SendPoll where - C: Into, + C: Into, Q: Into, O: IntoIterator, { @@ -286,7 +286,7 @@ impl Requester for Bot { fn send_dice(&self, chat_id: C) -> Self::SendDice where - C: Into, + C: Into, { Self::SendDice::new(self.clone(), payloads::SendDice::new(chat_id)) } @@ -299,7 +299,7 @@ impl Requester for Bot { action: crate::types::ChatAction, ) -> Self::SendChatAction where - C: Into, + C: Into, { Self::SendChatAction::new(self.clone(), payloads::SendChatAction::new(chat_id, action)) } @@ -323,7 +323,7 @@ impl Requester for Bot { fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember where - C: Into, + C: Into, { Self::KickChatMember::new( self.clone(), @@ -335,7 +335,7 @@ impl Requester for Bot { fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember where - C: Into, + C: Into, { Self::BanChatMember::new(self.clone(), payloads::BanChatMember::new(chat_id, user_id)) } @@ -344,7 +344,7 @@ impl Requester for Bot { fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember where - C: Into, + C: Into, { Self::UnbanChatMember::new( self.clone(), @@ -361,7 +361,7 @@ impl Requester for Bot { permissions: ChatPermissions, ) -> Self::RestrictChatMember where - C: Into, + C: Into, { Self::RestrictChatMember::new( self.clone(), @@ -373,7 +373,7 @@ impl Requester for Bot { fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember where - C: Into, + C: Into, { Self::PromoteChatMember::new( self.clone(), @@ -390,7 +390,7 @@ impl Requester for Bot { custom_title: Cu, ) -> Self::SetChatAdministratorCustomTitle where - Ch: Into, + Ch: Into, Cu: Into, { Self::SetChatAdministratorCustomTitle::new( @@ -403,7 +403,7 @@ impl Requester for Bot { fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat where - C: Into, + C: Into, { Self::BanChatSenderChat::new( self.clone(), @@ -419,7 +419,7 @@ impl Requester for Bot { sender_chat_id: i64, ) -> Self::UnbanChatSenderChat where - C: Into, + C: Into, { Self::UnbanChatSenderChat::new( self.clone(), @@ -435,7 +435,7 @@ impl Requester for Bot { permissions: ChatPermissions, ) -> Self::SetChatPermissions where - C: Into, + C: Into, { Self::SetChatPermissions::new( self.clone(), @@ -447,7 +447,7 @@ impl Requester for Bot { fn export_chat_invite_link(&self, chat_id: C) -> Self::ExportChatInviteLink where - C: Into, + C: Into, { Self::ExportChatInviteLink::new(self.clone(), payloads::ExportChatInviteLink::new(chat_id)) } @@ -456,7 +456,7 @@ impl Requester for Bot { fn create_chat_invite_link(&self, chat_id: C) -> Self::CreateChatInviteLink where - C: Into, + C: Into, { Self::CreateChatInviteLink::new(self.clone(), payloads::CreateChatInviteLink::new(chat_id)) } @@ -465,7 +465,7 @@ impl Requester for Bot { fn edit_chat_invite_link(&self, chat_id: C, invite_link: I) -> Self::EditChatInviteLink where - C: Into, + C: Into, I: Into, { Self::EditChatInviteLink::new( @@ -482,7 +482,7 @@ impl Requester for Bot { invite_link: I, ) -> Self::RevokeChatInviteLink where - C: Into, + C: Into, I: Into, { Self::RevokeChatInviteLink::new( @@ -495,7 +495,7 @@ impl Requester for Bot { fn approve_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::ApproveChatJoinRequest where - C: Into, + C: Into, { Self::ApproveChatJoinRequest::new( self.clone(), @@ -507,7 +507,7 @@ impl Requester for Bot { fn decline_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::DeclineChatJoinRequest where - C: Into, + C: Into, { Self::DeclineChatJoinRequest::new( self.clone(), @@ -519,7 +519,7 @@ impl Requester for Bot { fn set_chat_photo(&self, chat_id: C, photo: InputFile) -> Self::SetChatPhoto where - C: Into, + C: Into, { Self::SetChatPhoto::new(self.clone(), payloads::SetChatPhoto::new(chat_id, photo)) } @@ -528,7 +528,7 @@ impl Requester for Bot { fn delete_chat_photo(&self, chat_id: C) -> Self::DeleteChatPhoto where - C: Into, + C: Into, { Self::DeleteChatPhoto::new(self.clone(), payloads::DeleteChatPhoto::new(chat_id)) } @@ -537,7 +537,7 @@ impl Requester for Bot { fn set_chat_title(&self, chat_id: C, title: T) -> Self::SetChatTitle where - C: Into, + C: Into, T: Into, { Self::SetChatTitle::new(self.clone(), payloads::SetChatTitle::new(chat_id, title)) @@ -547,7 +547,7 @@ impl Requester for Bot { fn set_chat_description(&self, chat_id: C) -> Self::SetChatDescription where - C: Into, + C: Into, { Self::SetChatDescription::new(self.clone(), payloads::SetChatDescription::new(chat_id)) } @@ -556,7 +556,7 @@ impl Requester for Bot { fn pin_chat_message(&self, chat_id: C, message_id: i32) -> Self::PinChatMessage where - C: Into, + C: Into, { Self::PinChatMessage::new( self.clone(), @@ -568,7 +568,7 @@ impl Requester for Bot { fn unpin_chat_message(&self, chat_id: C) -> Self::UnpinChatMessage where - C: Into, + C: Into, { Self::UnpinChatMessage::new(self.clone(), payloads::UnpinChatMessage::new(chat_id)) } @@ -577,7 +577,7 @@ impl Requester for Bot { fn leave_chat(&self, chat_id: C) -> Self::LeaveChat where - C: Into, + C: Into, { Self::LeaveChat::new(self.clone(), payloads::LeaveChat::new(chat_id)) } @@ -586,7 +586,7 @@ impl Requester for Bot { fn get_chat(&self, chat_id: C) -> Self::GetChat where - C: Into, + C: Into, { Self::GetChat::new(self.clone(), payloads::GetChat::new(chat_id)) } @@ -595,7 +595,7 @@ impl Requester for Bot { fn get_chat_administrators(&self, chat_id: C) -> Self::GetChatAdministrators where - C: Into, + C: Into, { Self::GetChatAdministrators::new( self.clone(), @@ -607,7 +607,7 @@ impl Requester for Bot { fn get_chat_members_count(&self, chat_id: C) -> Self::GetChatMembersCount where - C: Into, + C: Into, { Self::GetChatMembersCount::new(self.clone(), payloads::GetChatMembersCount::new(chat_id)) } @@ -616,7 +616,7 @@ impl Requester for Bot { fn get_chat_member_count(&self, chat_id: C) -> Self::GetChatMemberCount where - C: Into, + C: Into, { Self::GetChatMemberCount::new(self.clone(), payloads::GetChatMemberCount::new(chat_id)) } @@ -625,7 +625,7 @@ impl Requester for Bot { fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember where - C: Into, + C: Into, { Self::GetChatMember::new(self.clone(), payloads::GetChatMember::new(chat_id, user_id)) } @@ -634,7 +634,7 @@ impl Requester for Bot { fn set_chat_sticker_set(&self, chat_id: C, sticker_set_name: S) -> Self::SetChatStickerSet where - C: Into, + C: Into, S: Into, { Self::SetChatStickerSet::new( @@ -647,7 +647,7 @@ impl Requester for Bot { fn delete_chat_sticker_set(&self, chat_id: C) -> Self::DeleteChatStickerSet where - C: Into, + C: Into, { Self::DeleteChatStickerSet::new(self.clone(), payloads::DeleteChatStickerSet::new(chat_id)) } @@ -702,7 +702,7 @@ impl Requester for Bot { fn edit_message_text(&self, chat_id: C, message_id: i32, text: T) -> Self::EditMessageText where - C: Into, + C: Into, T: Into, { Self::EditMessageText::new( @@ -732,7 +732,7 @@ impl Requester for Bot { fn edit_message_caption(&self, chat_id: C, message_id: i32) -> Self::EditMessageCaption where - C: Into, + C: Into, { Self::EditMessageCaption::new( self.clone(), @@ -761,7 +761,7 @@ impl Requester for Bot { media: InputMedia, ) -> Self::EditMessageMedia where - C: Into, + C: Into, { Self::EditMessageMedia::new( self.clone(), @@ -793,7 +793,7 @@ impl Requester for Bot { message_id: i32, ) -> Self::EditMessageReplyMarkup where - C: Into, + C: Into, { Self::EditMessageReplyMarkup::new( self.clone(), @@ -820,7 +820,7 @@ impl Requester for Bot { fn stop_poll(&self, chat_id: C, message_id: i32) -> Self::StopPoll where - C: Into, + C: Into, { Self::StopPoll::new(self.clone(), payloads::StopPoll::new(chat_id, message_id)) } @@ -829,7 +829,7 @@ impl Requester for Bot { fn delete_message(&self, chat_id: C, message_id: i32) -> Self::DeleteMessage where - C: Into, + C: Into, { Self::DeleteMessage::new( self.clone(), @@ -841,7 +841,7 @@ impl Requester for Bot { fn send_sticker(&self, chat_id: C, sticker: InputFile) -> Self::SendSticker where - C: Into, + C: Into, { Self::SendSticker::new(self.clone(), payloads::SendSticker::new(chat_id, sticker)) } @@ -955,7 +955,7 @@ impl Requester for Bot { prices: Pri, ) -> Self::SendInvoice where - Ch: Into, + Ch: Into, T: Into, D: Into, Pa: Into, @@ -1089,8 +1089,8 @@ impl Requester for Bot { fn copy_message(&self, chat_id: C, from_chat_id: F, message_id: i32) -> Self::CopyMessage where - C: Into, - F: Into, + C: Into, + F: Into, { Self::CopyMessage::new( self.clone(), @@ -1102,7 +1102,7 @@ impl Requester for Bot { fn unpin_all_chat_messages(&self, chat_id: C) -> Self::UnpinAllChatMessages where - C: Into, + C: Into, { Self::UnpinAllChatMessages::new(self.clone(), payloads::UnpinAllChatMessages::new(chat_id)) } diff --git a/src/local_macros.rs b/src/local_macros.rs index ee2f4916..f7289c51 100644 --- a/src/local_macros.rs +++ b/src/local_macros.rs @@ -481,7 +481,7 @@ macro_rules! requester_forward { (@method send_message $body:ident $ty:ident) => { type SendMessage = $ty![SendMessage]; - fn send_message(&self, chat_id: C, text: T) -> Self::SendMessage where C: Into, + fn send_message(&self, chat_id: C, text: T) -> Self::SendMessage where C: Into, T: Into { let this = self; $body!(send_message this (chat_id: C, text: T)) @@ -490,8 +490,8 @@ macro_rules! requester_forward { (@method forward_message $body:ident $ty:ident) => { type ForwardMessage = $ty![ForwardMessage]; - fn forward_message(&self, chat_id: C, from_chat_id: F, message_id: i32) -> Self::ForwardMessage where C: Into, - F: Into { + fn forward_message(&self, chat_id: C, from_chat_id: F, message_id: i32) -> Self::ForwardMessage where C: Into, + F: Into { let this = self; $body!(forward_message this (chat_id: C, from_chat_id: F, message_id: i32)) } @@ -499,8 +499,8 @@ macro_rules! requester_forward { (@method copy_message $body:ident $ty:ident) => { type CopyMessage = $ty![CopyMessage]; - fn copy_message(&self, chat_id: C, from_chat_id: F, message_id: i32) -> Self::CopyMessage where C: Into, - F: Into { + fn copy_message(&self, chat_id: C, from_chat_id: F, message_id: i32) -> Self::CopyMessage where C: Into, + F: Into { let this = self; $body!(copy_message this (chat_id: C, from_chat_id: F, message_id: i32)) } @@ -508,7 +508,7 @@ macro_rules! requester_forward { (@method send_photo $body:ident $ty:ident) => { type SendPhoto = $ty![SendPhoto]; - fn send_photo(&self, chat_id: C, photo: InputFile) -> Self::SendPhoto where C: Into { + fn send_photo(&self, chat_id: C, photo: InputFile) -> Self::SendPhoto where C: Into { let this = self; $body!(send_photo this (chat_id: C, photo: InputFile)) } @@ -516,7 +516,7 @@ macro_rules! requester_forward { (@method send_audio $body:ident $ty:ident) => { type SendAudio = $ty![SendAudio]; - fn send_audio(&self, chat_id: C, audio: InputFile) -> Self::SendAudio where C: Into { + fn send_audio(&self, chat_id: C, audio: InputFile) -> Self::SendAudio where C: Into { let this = self; $body!(send_audio this (chat_id: C, audio: InputFile)) } @@ -524,7 +524,7 @@ macro_rules! requester_forward { (@method send_document $body:ident $ty:ident) => { type SendDocument = $ty![SendDocument]; - fn send_document(&self, chat_id: C, document: InputFile) -> Self::SendDocument where C: Into { + fn send_document(&self, chat_id: C, document: InputFile) -> Self::SendDocument where C: Into { let this = self; $body!(send_document this (chat_id: C, document: InputFile)) } @@ -532,7 +532,7 @@ macro_rules! requester_forward { (@method send_video $body:ident $ty:ident) => { type SendVideo = $ty![SendVideo]; - fn send_video(&self, chat_id: C, video: InputFile) -> Self::SendVideo where C: Into { + fn send_video(&self, chat_id: C, video: InputFile) -> Self::SendVideo where C: Into { let this = self; $body!(send_video this (chat_id: C, video: InputFile)) } @@ -540,7 +540,7 @@ macro_rules! requester_forward { (@method send_animation $body:ident $ty:ident) => { type SendAnimation = $ty![SendAnimation]; - fn send_animation(&self, chat_id: C, animation: InputFile) -> Self::SendAnimation where C: Into { + fn send_animation(&self, chat_id: C, animation: InputFile) -> Self::SendAnimation where C: Into { let this = self; $body!(send_animation this (chat_id: C, animation: InputFile)) } @@ -548,7 +548,7 @@ macro_rules! requester_forward { (@method send_voice $body:ident $ty:ident) => { type SendVoice = $ty![SendVoice]; - fn send_voice(&self, chat_id: C, voice: InputFile) -> Self::SendVoice where C: Into { + fn send_voice(&self, chat_id: C, voice: InputFile) -> Self::SendVoice where C: Into { let this = self; $body!(send_voice this (chat_id: C, voice: InputFile)) } @@ -556,7 +556,7 @@ macro_rules! requester_forward { (@method send_video_note $body:ident $ty:ident) => { type SendVideoNote = $ty![SendVideoNote]; - fn send_video_note(&self, chat_id: C, video_note: InputFile) -> Self::SendVideoNote where C: Into { + fn send_video_note(&self, chat_id: C, video_note: InputFile) -> Self::SendVideoNote where C: Into { let this = self; $body!(send_video_note this (chat_id: C, video_note: InputFile)) } @@ -564,7 +564,7 @@ macro_rules! requester_forward { (@method send_media_group $body:ident $ty:ident) => { type SendMediaGroup = $ty![SendMediaGroup]; - fn send_media_group(&self, chat_id: C, media: M) -> Self::SendMediaGroup where C: Into, + fn send_media_group(&self, chat_id: C, media: M) -> Self::SendMediaGroup where C: Into, M: IntoIterator { let this = self; $body!(send_media_group this (chat_id: C, media: M)) @@ -573,7 +573,7 @@ macro_rules! requester_forward { (@method send_location $body:ident $ty:ident) => { type SendLocation = $ty![SendLocation]; - fn send_location(&self, chat_id: C, latitude: f64, longitude: f64) -> Self::SendLocation where C: Into { + fn send_location(&self, chat_id: C, latitude: f64, longitude: f64) -> Self::SendLocation where C: Into { let this = self; $body!(send_location this (chat_id: C, latitude: f64, longitude: f64)) } @@ -581,7 +581,7 @@ macro_rules! requester_forward { (@method edit_message_live_location $body:ident $ty:ident) => { type EditMessageLiveLocation = $ty![EditMessageLiveLocation]; - fn edit_message_live_location(&self, chat_id: C, message_id: i32, latitude: f64, longitude: f64) -> Self::EditMessageLiveLocation where C: Into { + fn edit_message_live_location(&self, chat_id: C, message_id: i32, latitude: f64, longitude: f64) -> Self::EditMessageLiveLocation where C: Into { let this = self; $body!(edit_message_live_location this (chat_id: C, message_id: i32, latitude: f64, longitude: f64)) } @@ -597,7 +597,7 @@ macro_rules! requester_forward { (@method stop_message_live_location $body:ident $ty:ident) => { type StopMessageLiveLocation = $ty![StopMessageLiveLocation]; - fn stop_message_live_location(&self, chat_id: C, message_id: i32, latitude: f64, longitude: f64) -> Self::StopMessageLiveLocation where C: Into { + fn stop_message_live_location(&self, chat_id: C, message_id: i32, latitude: f64, longitude: f64) -> Self::StopMessageLiveLocation where C: Into { let this = self; $body!(stop_message_live_location this (chat_id: C, message_id: i32, latitude: f64, longitude: f64)) } @@ -613,7 +613,7 @@ macro_rules! requester_forward { (@method send_venue $body:ident $ty:ident) => { type SendVenue = $ty![SendVenue]; - fn send_venue(&self, chat_id: C, latitude: f64, longitude: f64, title: T, address: A) -> Self::SendVenue where C: Into, + fn send_venue(&self, chat_id: C, latitude: f64, longitude: f64, title: T, address: A) -> Self::SendVenue where C: Into, T: Into, A: Into { let this = self; @@ -623,7 +623,7 @@ macro_rules! requester_forward { (@method send_contact $body:ident $ty:ident) => { type SendContact = $ty![SendContact]; - fn send_contact(&self, chat_id: C, phone_number: P, first_name: F) -> Self::SendContact where C: Into, + fn send_contact(&self, chat_id: C, phone_number: P, first_name: F) -> Self::SendContact where C: Into, P: Into, F: Into { let this = self; @@ -633,7 +633,7 @@ macro_rules! requester_forward { (@method send_poll $body:ident $ty:ident) => { type SendPoll = $ty![SendPoll]; - fn send_poll(&self, chat_id: C, question: Q, options: O) -> Self::SendPoll where C: Into, + fn send_poll(&self, chat_id: C, question: Q, options: O) -> Self::SendPoll where C: Into, Q: Into, O: IntoIterator { let this = self; @@ -643,7 +643,7 @@ macro_rules! requester_forward { (@method send_dice $body:ident $ty:ident) => { type SendDice = $ty![SendDice]; - fn send_dice(&self, chat_id: C) -> Self::SendDice where C: Into { + fn send_dice(&self, chat_id: C) -> Self::SendDice where C: Into { let this = self; $body!(send_dice this (chat_id: C)) } @@ -651,7 +651,7 @@ macro_rules! requester_forward { (@method send_chat_action $body:ident $ty:ident) => { type SendChatAction = $ty![SendChatAction]; - fn send_chat_action(&self, chat_id: C, action: ChatAction) -> Self::SendChatAction where C: Into { + fn send_chat_action(&self, chat_id: C, action: ChatAction) -> Self::SendChatAction where C: Into { let this = self; $body!(send_chat_action this (chat_id: C, action: ChatAction)) } @@ -675,7 +675,7 @@ macro_rules! requester_forward { (@method ban_chat_member $body:ident $ty:ident) => { type BanChatMember = $ty![BanChatMember]; - fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember where C: Into { + fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember where C: Into { let this = self; $body!(ban_chat_member this (chat_id: C, user_id: i64)) } @@ -683,7 +683,7 @@ macro_rules! requester_forward { (@method kick_chat_member $body:ident $ty:ident) => { type KickChatMember = $ty![KickChatMember]; - fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember where C: Into { + fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember where C: Into { let this = self; $body!(kick_chat_member this (chat_id: C, user_id: i64)) } @@ -691,7 +691,7 @@ macro_rules! requester_forward { (@method unban_chat_member $body:ident $ty:ident) => { type UnbanChatMember = $ty![UnbanChatMember]; - fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember where C: Into { + fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember where C: Into { let this = self; $body!(unban_chat_member this (chat_id: C, user_id: i64)) } @@ -699,7 +699,7 @@ macro_rules! requester_forward { (@method restrict_chat_member $body:ident $ty:ident) => { type RestrictChatMember = $ty![RestrictChatMember]; - fn restrict_chat_member(&self, chat_id: C, user_id: i64, permissions: ChatPermissions) -> Self::RestrictChatMember where C: Into { + fn restrict_chat_member(&self, chat_id: C, user_id: i64, permissions: ChatPermissions) -> Self::RestrictChatMember where C: Into { let this = self; $body!(restrict_chat_member this (chat_id: C, user_id: i64, permissions: ChatPermissions)) } @@ -707,7 +707,7 @@ macro_rules! requester_forward { (@method promote_chat_member $body:ident $ty:ident) => { type PromoteChatMember = $ty![PromoteChatMember]; - fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember where C: Into { + fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember where C: Into { let this = self; $body!(promote_chat_member this (chat_id: C, user_id: i64)) } @@ -715,7 +715,7 @@ macro_rules! requester_forward { (@method set_chat_administrator_custom_title $body:ident $ty:ident) => { type SetChatAdministratorCustomTitle = $ty![SetChatAdministratorCustomTitle]; - fn set_chat_administrator_custom_title(&self, chat_id: Ch, user_id: i64, custom_title: Cu) -> Self::SetChatAdministratorCustomTitle where Ch: Into, + fn set_chat_administrator_custom_title(&self, chat_id: Ch, user_id: i64, custom_title: Cu) -> Self::SetChatAdministratorCustomTitle where Ch: Into, Cu: Into { let this = self; $body!(set_chat_administrator_custom_title this (chat_id: Ch, user_id: i64, custom_title: Cu)) @@ -724,7 +724,7 @@ macro_rules! requester_forward { (@method ban_chat_sender_chat $body:ident $ty:ident) => { type BanChatSenderChat = $ty![BanChatSenderChat]; - fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat where C: Into { + fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat where C: Into { let this = self; $body!(ban_chat_sender_chat this (chat_id: C, sender_chat_id: i64)) } @@ -732,7 +732,7 @@ macro_rules! requester_forward { (@method unban_chat_sender_chat $body:ident $ty:ident) => { type UnbanChatSenderChat = $ty![UnbanChatSenderChat]; - fn unban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::UnbanChatSenderChat where C: Into { + fn unban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::UnbanChatSenderChat where C: Into { let this = self; $body!(unban_chat_sender_chat this (chat_id: C, sender_chat_id: i64)) } @@ -740,7 +740,7 @@ macro_rules! requester_forward { (@method set_chat_permissions $body:ident $ty:ident) => { type SetChatPermissions = $ty![SetChatPermissions]; - fn set_chat_permissions(&self, chat_id: C, permissions: ChatPermissions) -> Self::SetChatPermissions where C: Into { + fn set_chat_permissions(&self, chat_id: C, permissions: ChatPermissions) -> Self::SetChatPermissions where C: Into { let this = self; $body!(set_chat_permissions this (chat_id: C, permissions: ChatPermissions)) } @@ -748,7 +748,7 @@ macro_rules! requester_forward { (@method export_chat_invite_link $body:ident $ty:ident) => { type ExportChatInviteLink = $ty![ExportChatInviteLink]; - fn export_chat_invite_link(&self, chat_id: C) -> Self::ExportChatInviteLink where C: Into { + fn export_chat_invite_link(&self, chat_id: C) -> Self::ExportChatInviteLink where C: Into { let this = self; $body!(export_chat_invite_link this (chat_id: C)) } @@ -756,7 +756,7 @@ macro_rules! requester_forward { (@method create_chat_invite_link $body:ident $ty:ident) => { type CreateChatInviteLink = $ty![CreateChatInviteLink]; - fn create_chat_invite_link(&self, chat_id: C) -> Self::CreateChatInviteLink where C: Into { + fn create_chat_invite_link(&self, chat_id: C) -> Self::CreateChatInviteLink where C: Into { let this = self; $body!(create_chat_invite_link this (chat_id: C)) } @@ -764,7 +764,7 @@ macro_rules! requester_forward { (@method edit_chat_invite_link $body:ident $ty:ident) => { type EditChatInviteLink = $ty![EditChatInviteLink]; - fn edit_chat_invite_link(&self, chat_id: C, invite_link: I) -> Self::EditChatInviteLink where C: Into, + fn edit_chat_invite_link(&self, chat_id: C, invite_link: I) -> Self::EditChatInviteLink where C: Into, I: Into { let this = self; $body!(edit_chat_invite_link this (chat_id: C, invite_link: I)) @@ -773,7 +773,7 @@ macro_rules! requester_forward { (@method revoke_chat_invite_link $body:ident $ty:ident) => { type RevokeChatInviteLink = $ty![RevokeChatInviteLink]; - fn revoke_chat_invite_link(&self, chat_id: C, invite_link: I) -> Self::RevokeChatInviteLink where C: Into, + fn revoke_chat_invite_link(&self, chat_id: C, invite_link: I) -> Self::RevokeChatInviteLink where C: Into, I: Into { let this = self; $body!(revoke_chat_invite_link this (chat_id: C, invite_link: I)) @@ -782,7 +782,7 @@ macro_rules! requester_forward { (@method approve_chat_join_request $body:ident $ty:ident) => { type ApproveChatJoinRequest = $ty![ApproveChatJoinRequest]; - fn approve_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::ApproveChatJoinRequest where C: Into { + fn approve_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::ApproveChatJoinRequest where C: Into { let this = self; $body!(approve_chat_join_request this (chat_id: C, user_id: i64)) } @@ -790,7 +790,7 @@ macro_rules! requester_forward { (@method decline_chat_join_request $body:ident $ty:ident) => { type DeclineChatJoinRequest = $ty![DeclineChatJoinRequest]; - fn decline_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::DeclineChatJoinRequest where C: Into { + fn decline_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::DeclineChatJoinRequest where C: Into { let this = self; $body!(decline_chat_join_request this (chat_id: C, user_id: i64)) } @@ -798,7 +798,7 @@ macro_rules! requester_forward { (@method set_chat_photo $body:ident $ty:ident) => { type SetChatPhoto = $ty![SetChatPhoto]; - fn set_chat_photo(&self, chat_id: C, photo: InputFile) -> Self::SetChatPhoto where C: Into { + fn set_chat_photo(&self, chat_id: C, photo: InputFile) -> Self::SetChatPhoto where C: Into { let this = self; $body!(set_chat_photo this (chat_id: C, photo: InputFile)) } @@ -806,7 +806,7 @@ macro_rules! requester_forward { (@method delete_chat_photo $body:ident $ty:ident) => { type DeleteChatPhoto = $ty![DeleteChatPhoto]; - fn delete_chat_photo(&self, chat_id: C) -> Self::DeleteChatPhoto where C: Into { + fn delete_chat_photo(&self, chat_id: C) -> Self::DeleteChatPhoto where C: Into { let this = self; $body!(delete_chat_photo this (chat_id: C)) } @@ -814,7 +814,7 @@ macro_rules! requester_forward { (@method set_chat_title $body:ident $ty:ident) => { type SetChatTitle = $ty![SetChatTitle]; - fn set_chat_title(&self, chat_id: C, title: T) -> Self::SetChatTitle where C: Into, + fn set_chat_title(&self, chat_id: C, title: T) -> Self::SetChatTitle where C: Into, T: Into { let this = self; $body!(set_chat_title this (chat_id: C, title: T)) @@ -823,7 +823,7 @@ macro_rules! requester_forward { (@method set_chat_description $body:ident $ty:ident) => { type SetChatDescription = $ty![SetChatDescription]; - fn set_chat_description(&self, chat_id: C) -> Self::SetChatDescription where C: Into { + fn set_chat_description(&self, chat_id: C) -> Self::SetChatDescription where C: Into { let this = self; $body!(set_chat_description this (chat_id: C)) } @@ -831,7 +831,7 @@ macro_rules! requester_forward { (@method pin_chat_message $body:ident $ty:ident) => { type PinChatMessage = $ty![PinChatMessage]; - fn pin_chat_message(&self, chat_id: C, message_id: i32) -> Self::PinChatMessage where C: Into { + fn pin_chat_message(&self, chat_id: C, message_id: i32) -> Self::PinChatMessage where C: Into { let this = self; $body!(pin_chat_message this (chat_id: C, message_id: i32)) } @@ -839,7 +839,7 @@ macro_rules! requester_forward { (@method unpin_chat_message $body:ident $ty:ident) => { type UnpinChatMessage = $ty![UnpinChatMessage]; - fn unpin_chat_message(&self, chat_id: C) -> Self::UnpinChatMessage where C: Into { + fn unpin_chat_message(&self, chat_id: C) -> Self::UnpinChatMessage where C: Into { let this = self; $body!(unpin_chat_message this (chat_id: C)) } @@ -847,7 +847,7 @@ macro_rules! requester_forward { (@method unpin_all_chat_messages $body:ident $ty:ident) => { type UnpinAllChatMessages = $ty![UnpinAllChatMessages]; - fn unpin_all_chat_messages(&self, chat_id: C) -> Self::UnpinAllChatMessages where C: Into { + fn unpin_all_chat_messages(&self, chat_id: C) -> Self::UnpinAllChatMessages where C: Into { let this = self; $body!(unpin_all_chat_messages this (chat_id: C)) } @@ -855,7 +855,7 @@ macro_rules! requester_forward { (@method leave_chat $body:ident $ty:ident) => { type LeaveChat = $ty![LeaveChat]; - fn leave_chat(&self, chat_id: C) -> Self::LeaveChat where C: Into { + fn leave_chat(&self, chat_id: C) -> Self::LeaveChat where C: Into { let this = self; $body!(leave_chat this (chat_id: C)) } @@ -863,7 +863,7 @@ macro_rules! requester_forward { (@method get_chat $body:ident $ty:ident) => { type GetChat = $ty![GetChat]; - fn get_chat(&self, chat_id: C) -> Self::GetChat where C: Into { + fn get_chat(&self, chat_id: C) -> Self::GetChat where C: Into { let this = self; $body!(get_chat this (chat_id: C)) } @@ -871,7 +871,7 @@ macro_rules! requester_forward { (@method get_chat_administrators $body:ident $ty:ident) => { type GetChatAdministrators = $ty![GetChatAdministrators]; - fn get_chat_administrators(&self, chat_id: C) -> Self::GetChatAdministrators where C: Into { + fn get_chat_administrators(&self, chat_id: C) -> Self::GetChatAdministrators where C: Into { let this = self; $body!(get_chat_administrators this (chat_id: C)) } @@ -879,7 +879,7 @@ macro_rules! requester_forward { (@method get_chat_member_count $body:ident $ty:ident) => { type GetChatMemberCount = $ty![GetChatMemberCount]; - fn get_chat_member_count(&self, chat_id: C) -> Self::GetChatMemberCount where C: Into { + fn get_chat_member_count(&self, chat_id: C) -> Self::GetChatMemberCount where C: Into { let this = self; $body!(get_chat_member_count this (chat_id: C)) } @@ -887,7 +887,7 @@ macro_rules! requester_forward { (@method get_chat_members_count $body:ident $ty:ident) => { type GetChatMembersCount = $ty![GetChatMembersCount]; - fn get_chat_members_count(&self, chat_id: C) -> Self::GetChatMembersCount where C: Into { + fn get_chat_members_count(&self, chat_id: C) -> Self::GetChatMembersCount where C: Into { let this = self; $body!(get_chat_members_count this (chat_id: C)) } @@ -895,7 +895,7 @@ macro_rules! requester_forward { (@method get_chat_member $body:ident $ty:ident) => { type GetChatMember = $ty![GetChatMember]; - fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember where C: Into { + fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember where C: Into { let this = self; $body!(get_chat_member this (chat_id: C, user_id: i64)) } @@ -903,7 +903,7 @@ macro_rules! requester_forward { (@method set_chat_sticker_set $body:ident $ty:ident) => { type SetChatStickerSet = $ty![SetChatStickerSet]; - fn set_chat_sticker_set(&self, chat_id: C, sticker_set_name: S) -> Self::SetChatStickerSet where C: Into, + fn set_chat_sticker_set(&self, chat_id: C, sticker_set_name: S) -> Self::SetChatStickerSet where C: Into, S: Into { let this = self; $body!(set_chat_sticker_set this (chat_id: C, sticker_set_name: S)) @@ -912,7 +912,7 @@ macro_rules! requester_forward { (@method delete_chat_sticker_set $body:ident $ty:ident) => { type DeleteChatStickerSet = $ty![DeleteChatStickerSet]; - fn delete_chat_sticker_set(&self, chat_id: C) -> Self::DeleteChatStickerSet where C: Into { + fn delete_chat_sticker_set(&self, chat_id: C) -> Self::DeleteChatStickerSet where C: Into { let this = self; $body!(delete_chat_sticker_set this (chat_id: C)) } @@ -961,7 +961,7 @@ macro_rules! requester_forward { (@method edit_message_text $body:ident $ty:ident) => { type EditMessageText = $ty![EditMessageText]; - fn edit_message_text(&self, chat_id: C, message_id: i32, text: T) -> Self::EditMessageText where C: Into, + fn edit_message_text(&self, chat_id: C, message_id: i32, text: T) -> Self::EditMessageText where C: Into, T: Into { let this = self; $body!(edit_message_text this (chat_id: C, message_id: i32, text: T)) @@ -979,7 +979,7 @@ macro_rules! requester_forward { (@method edit_message_caption $body:ident $ty:ident) => { type EditMessageCaption = $ty![EditMessageCaption]; - fn edit_message_caption(&self, chat_id: C, message_id: i32) -> Self::EditMessageCaption where C: Into { + fn edit_message_caption(&self, chat_id: C, message_id: i32) -> Self::EditMessageCaption where C: Into { let this = self; $body!(edit_message_caption this (chat_id: C, message_id: i32)) } @@ -995,7 +995,7 @@ macro_rules! requester_forward { (@method edit_message_media $body:ident $ty:ident) => { type EditMessageMedia = $ty![EditMessageMedia]; - fn edit_message_media(&self, chat_id: C, message_id: i32, media: InputMedia) -> Self::EditMessageMedia where C: Into { + fn edit_message_media(&self, chat_id: C, message_id: i32, media: InputMedia) -> Self::EditMessageMedia where C: Into { let this = self; $body!(edit_message_media this (chat_id: C, message_id: i32, media: InputMedia)) } @@ -1011,7 +1011,7 @@ macro_rules! requester_forward { (@method edit_message_reply_markup $body:ident $ty:ident) => { type EditMessageReplyMarkup = $ty![EditMessageReplyMarkup]; - fn edit_message_reply_markup(&self, chat_id: C, message_id: i32) -> Self::EditMessageReplyMarkup where C: Into { + fn edit_message_reply_markup(&self, chat_id: C, message_id: i32) -> Self::EditMessageReplyMarkup where C: Into { let this = self; $body!(edit_message_reply_markup this (chat_id: C, message_id: i32)) } @@ -1027,7 +1027,7 @@ macro_rules! requester_forward { (@method stop_poll $body:ident $ty:ident) => { type StopPoll = $ty![StopPoll]; - fn stop_poll(&self, chat_id: C, message_id: i32) -> Self::StopPoll where C: Into { + fn stop_poll(&self, chat_id: C, message_id: i32) -> Self::StopPoll where C: Into { let this = self; $body!(stop_poll this (chat_id: C, message_id: i32)) } @@ -1035,7 +1035,7 @@ macro_rules! requester_forward { (@method delete_message $body:ident $ty:ident) => { type DeleteMessage = $ty![DeleteMessage]; - fn delete_message(&self, chat_id: C, message_id: i32) -> Self::DeleteMessage where C: Into { + fn delete_message(&self, chat_id: C, message_id: i32) -> Self::DeleteMessage where C: Into { let this = self; $body!(delete_message this (chat_id: C, message_id: i32)) } @@ -1043,7 +1043,7 @@ macro_rules! requester_forward { (@method send_sticker $body:ident $ty:ident) => { type SendSticker = $ty![SendSticker]; - fn send_sticker(&self, chat_id: C, sticker: InputFile) -> Self::SendSticker where C: Into { + fn send_sticker(&self, chat_id: C, sticker: InputFile) -> Self::SendSticker where C: Into { let this = self; $body!(send_sticker this (chat_id: C, sticker: InputFile)) } @@ -1110,7 +1110,7 @@ macro_rules! requester_forward { (@method send_invoice $body:ident $ty:ident) => { type SendInvoice = $ty![SendInvoice]; - fn send_invoice(&self, chat_id: Ch, title: T, description: D, payload: Pa, provider_token: P, currency: C, prices: Pri) -> Self::SendInvoice where Ch: Into, + fn send_invoice(&self, chat_id: Ch, title: T, description: D, payload: Pa, provider_token: P, currency: C, prices: Pri) -> Self::SendInvoice where Ch: Into, T: Into, D: Into, Pa: Into, diff --git a/src/payloads/approve_chat_join_request.rs b/src/payloads/approve_chat_join_request.rs index fc62df1f..2c1b2781 100644 --- a/src/payloads/approve_chat_join_request.rs +++ b/src/payloads/approve_chat_join_request.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the _can_invite_users_ administrator right. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub ApproveChatJoinRequest (ApproveChatJoinRequestSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/ban_chat_member.rs b/src/payloads/ban_chat_member.rs index b91a5c70..1464935e 100644 --- a/src/payloads/ban_chat_member.rs +++ b/src/payloads/ban_chat_member.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless [unbanned] first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success. @@ -19,7 +19,7 @@ impl_payload! { pub BanChatMember (BanChatMemberSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/ban_chat_sender_chat.rs b/src/payloads/ban_chat_sender_chat.rs index d46e5def..3aaf7863 100644 --- a/src/payloads/ban_chat_sender_chat.rs +++ b/src/payloads/ban_chat_sender_chat.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. @@ -16,7 +16,7 @@ impl_payload! { pub BanChatSenderChat (BanChatSenderChatSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target sender chat pub sender_chat_id: i64, } diff --git a/src/payloads/copy_message.rs b/src/payloads/copy_message.rs index 6eec57d5..f0a56fbd 100644 --- a/src/payloads/copy_message.rs +++ b/src/payloads/copy_message.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, MessageEntity, MessageId, ParseMode, ReplyMarkup}; +use crate::types::{MessageEntity, MessageId, ParseMode, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to copy messages of any kind. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the [`MessageId`] of the sent message on success. @@ -18,9 +18,9 @@ impl_payload! { pub CopyMessage (CopyMessageSetters) => MessageId { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) - pub from_chat_id: ChatId [into], + pub from_chat_id: Recipient [into], /// Message identifier in the chat specified in _from\_chat\_id_ pub message_id: i32, } diff --git a/src/payloads/create_chat_invite_link.rs b/src/payloads/create_chat_invite_link.rs index 0e3f1929..ddb054c3 100644 --- a/src/payloads/create_chat_invite_link.rs +++ b/src/payloads/create_chat_invite_link.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{ChatId, ChatInviteLink}; +use crate::types::{ChatInviteLink, Recipient}; impl_payload! { /// Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The link can be revoked using the method [`RevokeChatInviteLink`]. Returns the new invite link as [`ChatInviteLink`] object. @@ -20,7 +20,7 @@ impl_payload! { pub CreateChatInviteLink (CreateChatInviteLinkSetters) => ChatInviteLink { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } optional { /// Invite link name; 0-32 characters diff --git a/src/payloads/decline_chat_join_request.rs b/src/payloads/decline_chat_join_request.rs index 7d96d17d..e7f5b87e 100644 --- a/src/payloads/decline_chat_join_request.rs +++ b/src/payloads/decline_chat_join_request.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the _can_invite_users_ administrator right. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub DeclineChatJoinRequest (DeclineChatJoinRequestSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/delete_chat_photo.rs b/src/payloads/delete_chat_photo.rs index 9905ba12..0e5f63af 100644 --- a/src/payloads/delete_chat_photo.rs +++ b/src/payloads/delete_chat_photo.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::ChatId; +use crate::types::Recipient; impl_payload! { /// 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 must have the appropriate admin rights. Returns True on success. @@ -16,7 +16,7 @@ impl_payload! { pub DeleteChatPhoto (DeleteChatPhotoSetters) => String { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/delete_chat_sticker_set.rs b/src/payloads/delete_chat_sticker_set.rs index c9042585..78151eef 100644 --- a/src/payloads/delete_chat_sticker_set.rs +++ b/src/payloads/delete_chat_sticker_set.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field `can_set_sticker_set` optionally returned in [`GetChat`] requests to check if the bot can use this method. Returns _True_ on success. @@ -18,7 +18,7 @@ impl_payload! { pub DeleteChatStickerSet (DeleteChatStickerSetSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/delete_message.rs b/src/payloads/delete_message.rs index a287ead9..35dfbcc1 100644 --- a/src/payloads/delete_message.rs +++ b/src/payloads/delete_message.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to delete a message, including service messages, with the following limitations: @@ -25,7 +25,7 @@ impl_payload! { pub DeleteMessage (DeleteMessageSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to delete pub message_id: i32, } diff --git a/src/payloads/edit_chat_invite_link.rs b/src/payloads/edit_chat_invite_link.rs index cc0cd110..4b1439b0 100644 --- a/src/payloads/edit_chat_invite_link.rs +++ b/src/payloads/edit_chat_invite_link.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::ChatId; +use crate::types::Recipient; impl_payload! { /// Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the edited invite link as a [`ChatInviteLink`] object. @@ -19,7 +19,7 @@ impl_payload! { pub EditChatInviteLink (EditChatInviteLinkSetters) => String { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// The invite link to edit pub invite_link: String [into], } diff --git a/src/payloads/edit_message_caption.rs b/src/payloads/edit_message_caption.rs index df901a8b..50092449 100644 --- a/src/payloads/edit_message_caption.rs +++ b/src/payloads/edit_message_caption.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InlineKeyboardMarkup, Message, MessageEntity, ParseMode}; +use crate::types::{InlineKeyboardMarkup, Message, MessageEntity, ParseMode, Recipient}; impl_payload! { /// Use this method to edit captions of messages. On success, the edited Message is returned. @@ -18,7 +18,7 @@ impl_payload! { pub EditMessageCaption (EditMessageCaptionSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, } diff --git a/src/payloads/edit_message_live_location.rs b/src/payloads/edit_message_live_location.rs index 26f2be3e..ff8000e9 100644 --- a/src/payloads/edit_message_live_location.rs +++ b/src/payloads/edit_message_live_location.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message, ReplyMarkup}; +use crate::types::{Message, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to [`StopMessageLiveLocation`]. On success, the edited Message is returned. @@ -20,7 +20,7 @@ impl_payload! { pub EditMessageLiveLocation (EditMessageLiveLocationSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, /// Latitude of new location diff --git a/src/payloads/edit_message_media.rs b/src/payloads/edit_message_media.rs index e2e99dba..2ab6b094 100644 --- a/src/payloads/edit_message_media.rs +++ b/src/payloads/edit_message_media.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InlineKeyboardMarkup, InputMedia, Message}; +use crate::types::{InlineKeyboardMarkup, InputMedia, Message, Recipient}; impl_payload! { /// Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, the edited Message is returned. @@ -18,7 +18,7 @@ impl_payload! { pub EditMessageMedia (EditMessageMediaSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, /// A JSON-serialized object for a new media content of the message diff --git a/src/payloads/edit_message_reply_markup.rs b/src/payloads/edit_message_reply_markup.rs index 81ab2496..31717940 100644 --- a/src/payloads/edit_message_reply_markup.rs +++ b/src/payloads/edit_message_reply_markup.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InlineKeyboardMarkup, Message}; +use crate::types::{InlineKeyboardMarkup, Message, Recipient}; impl_payload! { /// Use this method to edit only the reply markup of messages. On success, the edited Message is returned. @@ -18,7 +18,7 @@ impl_payload! { pub EditMessageReplyMarkup (EditMessageReplyMarkupSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, } diff --git a/src/payloads/edit_message_text.rs b/src/payloads/edit_message_text.rs index fb704638..b57670e8 100644 --- a/src/payloads/edit_message_text.rs +++ b/src/payloads/edit_message_text.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InlineKeyboardMarkup, Message, MessageEntity, ParseMode}; +use crate::types::{InlineKeyboardMarkup, Message, MessageEntity, ParseMode, Recipient}; impl_payload! { /// Use this method to edit text and [games] messages. On success, the edited Message is returned. @@ -20,7 +20,7 @@ impl_payload! { pub EditMessageText (EditMessageTextSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, /// New text of the message, 1-4096 characters after entities parsing diff --git a/src/payloads/export_chat_invite_link.rs b/src/payloads/export_chat_invite_link.rs index adf5e49e..affbb254 100644 --- a/src/payloads/export_chat_invite_link.rs +++ b/src/payloads/export_chat_invite_link.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::ChatId; +use crate::types::Recipient; impl_payload! { /// Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the new invite link as String on success. @@ -18,7 +18,7 @@ impl_payload! { pub ExportChatInviteLink (ExportChatInviteLinkSetters) => String { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/forward_message.rs b/src/payloads/forward_message.rs index 9c34f0b7..299b5de4 100644 --- a/src/payloads/forward_message.rs +++ b/src/payloads/forward_message.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message}; +use crate::types::{Message, Recipient}; impl_payload! { /// Use this method to forward messages of any kind. On success, the sent [`Message`] is returned. @@ -18,9 +18,9 @@ impl_payload! { pub ForwardMessage (ForwardMessageSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) - pub from_chat_id: ChatId [into], + pub from_chat_id: Recipient [into], /// Message identifier in the chat specified in _from\_chat\_id_ pub message_id: i32, } diff --git a/src/payloads/get_chat.rs b/src/payloads/get_chat.rs index 2b40a11d..1174c2c1 100644 --- a/src/payloads/get_chat.rs +++ b/src/payloads/get_chat.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Chat, ChatId}; +use crate::types::{Chat, Recipient}; impl_payload! { /// 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 or channel, etc.). Returns a [`Chat`] object on success. @@ -18,7 +18,7 @@ impl_payload! { pub GetChat (GetChatSetters) => Chat { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/get_chat_administrators.rs b/src/payloads/get_chat_administrators.rs index dc14eb20..aabf98d4 100644 --- a/src/payloads/get_chat_administrators.rs +++ b/src/payloads/get_chat_administrators.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, ChatMember}; +use crate::types::{ChatMember, Recipient}; impl_payload! { /// Use this method to get a list of administrators in a chat. On success, returns an Array of [`ChatMember`] objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. @@ -18,7 +18,7 @@ impl_payload! { pub GetChatAdministrators (GetChatAdministratorsSetters) => Vec { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/get_chat_member.rs b/src/payloads/get_chat_member.rs index 7b76d51c..dcf4f979 100644 --- a/src/payloads/get_chat_member.rs +++ b/src/payloads/get_chat_member.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, ChatMember}; +use crate::types::{ChatMember, Recipient}; impl_payload! { /// Use this method to get information about a member of a chat. Returns a [`ChatMember`] object on success. @@ -18,7 +18,7 @@ impl_payload! { pub GetChatMember (GetChatMemberSetters) => ChatMember { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/get_chat_member_count.rs b/src/payloads/get_chat_member_count.rs index aca48ab1..ef135206 100644 --- a/src/payloads/get_chat_member_count.rs +++ b/src/payloads/get_chat_member_count.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::ChatId; +use crate::types::Recipient; impl_payload! { /// Use this method to get the number of members in a chat. Returns _Int_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub GetChatMemberCount (GetChatMemberCountSetters) => u32 { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/get_chat_members_count.rs b/src/payloads/get_chat_members_count.rs index b5bb6350..7a86721a 100644 --- a/src/payloads/get_chat_members_count.rs +++ b/src/payloads/get_chat_members_count.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::ChatId; +use crate::types::Recipient; impl_payload! { /// Use this method to get the number of members in a chat. Returns _Int_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub GetChatMembersCount (GetChatMembersCountSetters) => u32 { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/kick_chat_member.rs b/src/payloads/kick_chat_member.rs index 5679d804..75eef991 100644 --- a/src/payloads/kick_chat_member.rs +++ b/src/payloads/kick_chat_member.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless [unbanned] first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success. @@ -19,7 +19,7 @@ impl_payload! { pub KickChatMember (KickChatMemberSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/leave_chat.rs b/src/payloads/leave_chat.rs index 32d417b6..212cc901 100644 --- a/src/payloads/leave_chat.rs +++ b/src/payloads/leave_chat.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method for your bot to leave a group, supergroup or channel. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub LeaveChat (LeaveChatSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/pin_chat_message.rs b/src/payloads/pin_chat_message.rs index b16dd8f3..b6a0552d 100644 --- a/src/payloads/pin_chat_message.rs +++ b/src/payloads/pin_chat_message.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in the supergroup or 'can_edit_messages' admin right in the channel. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub PinChatMessage (PinChatMessageSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of a message to pin pub message_id: i32, } diff --git a/src/payloads/promote_chat_member.rs b/src/payloads/promote_chat_member.rs index 9e69082f..3170756b 100644 --- a/src/payloads/promote_chat_member.rs +++ b/src/payloads/promote_chat_member.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass _False_ for all boolean parameters to demote a user. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub PromoteChatMember (PromoteChatMemberSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/restrict_chat_member.rs b/src/payloads/restrict_chat_member.rs index 6e78192c..003632a4 100644 --- a/src/payloads/restrict_chat_member.rs +++ b/src/payloads/restrict_chat_member.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{ChatId, ChatPermissions, True}; +use crate::types::{ChatPermissions, Recipient, True}; impl_payload! { /// Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass _True_ for all permissions to lift restrictions from a user. Returns _True_ on success. @@ -17,7 +17,7 @@ impl_payload! { pub RestrictChatMember (RestrictChatMemberSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, /// A JSON-serialized object for new user permissions diff --git a/src/payloads/revoke_chat_invite_link.rs b/src/payloads/revoke_chat_invite_link.rs index 04a7389f..7321413c 100644 --- a/src/payloads/revoke_chat_invite_link.rs +++ b/src/payloads/revoke_chat_invite_link.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::ChatId; +use crate::types::Recipient; impl_payload! { /// Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns the revoked invite link as [`ChatInviteLink`] object. @@ -18,7 +18,7 @@ impl_payload! { pub RevokeChatInviteLink (RevokeChatInviteLinkSetters) => String { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// The invite link to revoke pub invite_link: String [into], } diff --git a/src/payloads/send_animation.rs b/src/payloads/send_animation.rs index 8e718a8e..49e2fa36 100644 --- a/src/payloads/send_animation.rs +++ b/src/payloads/send_animation.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { @[multipart = animation, thumb] @@ -19,7 +19,7 @@ impl_payload! { pub SendAnimation (SendAnimationSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Animation to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_audio.rs b/src/payloads/send_audio.rs index c8123ec9..13906cc4 100644 --- a/src/payloads/send_audio.rs +++ b/src/payloads/send_audio.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { @[multipart = audio, thumb] @@ -22,7 +22,7 @@ impl_payload! { pub SendAudio (SendAudioSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_chat_action.rs b/src/payloads/send_chat_action.rs index 35e5ea51..45cd89de 100644 --- a/src/payloads/send_chat_action.rs +++ b/src/payloads/send_chat_action.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatAction, ChatId, True}; +use crate::types::{ChatAction, Recipient, True}; impl_payload! { /// Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success. @@ -22,7 +22,7 @@ impl_payload! { pub SendChatAction (SendChatActionSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for [text messages], upload_photo for [photos], record_video or upload_video for [videos], record_audio or upload_audio for [audio files], upload_document for [general files], choose_sticker for [stickers], find_location for [location data], record_video_note or upload_video_note for [video notes]. /// /// [text messages]: crate::payloads::SendMessage diff --git a/src/payloads/send_contact.rs b/src/payloads/send_contact.rs index ab530447..1af036cd 100644 --- a/src/payloads/send_contact.rs +++ b/src/payloads/send_contact.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message, ReplyMarkup}; +use crate::types::{Message, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to send phone contacts. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { pub SendContact (SendContactSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Contact's phone number pub phone_number: String [into], /// Contact's first name diff --git a/src/payloads/send_dice.rs b/src/payloads/send_dice.rs index 426154ac..70dd0339 100644 --- a/src/payloads/send_dice.rs +++ b/src/payloads/send_dice.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, DiceEmoji, Message, ReplyMarkup}; +use crate::types::{DiceEmoji, Message, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to send an animated emoji that will display a random value. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { pub SendDice (SendDiceSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } optional { /// Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲” diff --git a/src/payloads/send_document.rs b/src/payloads/send_document.rs index 7512f066..6bfc8330 100644 --- a/src/payloads/send_document.rs +++ b/src/payloads/send_document.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { @[multipart = document, thumb] @@ -19,7 +19,7 @@ impl_payload! { pub SendDocument (SendDocumentSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_invoice.rs b/src/payloads/send_invoice.rs index 503ddfb6..7a68601d 100644 --- a/src/payloads/send_invoice.rs +++ b/src/payloads/send_invoice.rs @@ -9,7 +9,7 @@ use serde::Serialize; use url::Url; -use crate::types::{ChatId, InlineKeyboardMarkup, LabeledPrice, Message}; +use crate::types::{InlineKeyboardMarkup, LabeledPrice, Message, Recipient}; impl_payload! { /// Use this method to send invoices. On success, the sent [`Message`] is returned. @@ -19,7 +19,7 @@ impl_payload! { pub SendInvoice (SendInvoiceSetters) => Message { required { /// Unique identifier for the target private chat - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Product name, 1-32 characters pub title: String [into], /// Product description, 1-255 characters diff --git a/src/payloads/send_location.rs b/src/payloads/send_location.rs index ba482dc2..99037b0d 100644 --- a/src/payloads/send_location.rs +++ b/src/payloads/send_location.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message, ReplyMarkup}; +use crate::types::{Message, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to send point on the map. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { pub SendLocation (SendLocationSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Latitude of the location pub latitude: f64, /// Longitude of the location diff --git a/src/payloads/send_media_group.rs b/src/payloads/send_media_group.rs index 95fd7886..108004cf 100644 --- a/src/payloads/send_media_group.rs +++ b/src/payloads/send_media_group.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputMedia, Message}; +use crate::types::{InputMedia, Message, Recipient}; impl_payload! { /// Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of [`Message`]s that were sent is returned. @@ -18,7 +18,7 @@ impl_payload! { pub SendMediaGroup (SendMediaGroupSetters) => Vec { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// A JSON-serialized array describing messages to be sent, must include 2-10 items pub media: Vec [collect], } diff --git a/src/payloads/send_message.rs b/src/payloads/send_message.rs index e27ddfc1..7563f7c1 100644 --- a/src/payloads/send_message.rs +++ b/src/payloads/send_message.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to send text messages. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { pub SendMessage (SendMessageSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Text of the message to be sent, 1-4096 characters after entities parsing pub text: String [into], } diff --git a/src/payloads/send_photo.rs b/src/payloads/send_photo.rs index e3e28d5b..8ab5d344 100644 --- a/src/payloads/send_photo.rs +++ b/src/payloads/send_photo.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { @[multipart = photo] @@ -19,7 +19,7 @@ impl_payload! { pub SendPhoto (SendPhotoSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_poll.rs b/src/payloads/send_poll.rs index 6b37f9c9..7409cbc0 100644 --- a/src/payloads/send_poll.rs +++ b/src/payloads/send_poll.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{ChatId, Message, MessageEntity, ParseMode, PollType, ReplyMarkup}; +use crate::types::{Message, MessageEntity, ParseMode, PollType, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to send phone contacts. On success, the sent [`Message`] is returned. @@ -19,7 +19,7 @@ impl_payload! { pub SendPoll (SendPollSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Poll question, 1-300 characters pub question: String [into], /// A JSON-serialized list of answer options, 2-10 strings 1-100 characters each diff --git a/src/payloads/send_sticker.rs b/src/payloads/send_sticker.rs index e80d0ee3..65513e8d 100644 --- a/src/payloads/send_sticker.rs +++ b/src/payloads/send_sticker.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, ReplyMarkup}; +use crate::types::{InputFile, Message, Recipient, ReplyMarkup}; impl_payload! { @[multipart = sticker] @@ -19,7 +19,7 @@ impl_payload! { pub SendSticker (SendStickerSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Sticker to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_venue.rs b/src/payloads/send_venue.rs index 78a901a2..33a99a72 100644 --- a/src/payloads/send_venue.rs +++ b/src/payloads/send_venue.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message, ReplyMarkup}; +use crate::types::{Message, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to send information about a venue. On success, the sent [`Message`] is returned. @@ -18,7 +18,7 @@ impl_payload! { pub SendVenue (SendVenueSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Latitude of new location pub latitude: f64, /// Longitude of new location diff --git a/src/payloads/send_video.rs b/src/payloads/send_video.rs index 75a7e652..ebf14dff 100644 --- a/src/payloads/send_video.rs +++ b/src/payloads/send_video.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { @[multipart = video, thumb] @@ -20,7 +20,7 @@ impl_payload! { pub SendVideo (SendVideoSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Video to send. Pass a file_id as String to send a video that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a video from the Internet, or upload a new video using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_video_note.rs b/src/payloads/send_video_note.rs index 54c5fd3f..828ca1a3 100644 --- a/src/payloads/send_video_note.rs +++ b/src/payloads/send_video_note.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, ReplyMarkup}; +use crate::types::{InputFile, Message, Recipient, ReplyMarkup}; impl_payload! { @[multipart = video_note, thumb] @@ -20,7 +20,7 @@ impl_payload! { pub SendVideoNote (SendVideoNoteSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. [More info on Sending Files »]. Sending video notes by a URL is currently unsupported /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/send_voice.rs b/src/payloads/send_voice.rs index 1d6c8035..bfbbd5fb 100644 --- a/src/payloads/send_voice.rs +++ b/src/payloads/send_voice.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, Message, MessageEntity, ParseMode, ReplyMarkup}; +use crate::types::{InputFile, Message, MessageEntity, ParseMode, Recipient, ReplyMarkup}; impl_payload! { @[multipart = voice] @@ -21,7 +21,7 @@ impl_payload! { pub SendVoice (SendVoiceSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/payloads/set_chat_administrator_custom_title.rs b/src/payloads/set_chat_administrator_custom_title.rs index 3ce02ccf..5f5d772a 100644 --- a/src/payloads/set_chat_administrator_custom_title.rs +++ b/src/payloads/set_chat_administrator_custom_title.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns _True_on success. @@ -16,7 +16,7 @@ impl_payload! { pub SetChatAdministratorCustomTitle (SetChatAdministratorCustomTitleSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, /// New custom title for the administrator; 0-16 characters, emoji are not allowed diff --git a/src/payloads/set_chat_description.rs b/src/payloads/set_chat_description.rs index 1c7cc88b..a9d08495 100644 --- a/src/payloads/set_chat_description.rs +++ b/src/payloads/set_chat_description.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub SetChatDescription (SetChatDescriptionSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } optional { /// New chat description, 0-255 characters diff --git a/src/payloads/set_chat_permissions.rs b/src/payloads/set_chat_permissions.rs index 1c619310..da9b5334 100644 --- a/src/payloads/set_chat_permissions.rs +++ b/src/payloads/set_chat_permissions.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, ChatPermissions, True}; +use crate::types::{ChatPermissions, Recipient, True}; impl_payload! { /// Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the _can_restrict_members_ admin rights. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub SetChatPermissions (SetChatPermissionsSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// New default chat permissions pub permissions: ChatPermissions, } diff --git a/src/payloads/set_chat_photo.rs b/src/payloads/set_chat_photo.rs index d7f475eb..316f2292 100644 --- a/src/payloads/set_chat_photo.rs +++ b/src/payloads/set_chat_photo.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InputFile, True}; +use crate::types::{InputFile, Recipient, True}; impl_payload! { @[multipart = photo] @@ -17,7 +17,7 @@ impl_payload! { pub SetChatPhoto (SetChatPhotoSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// New chat photo, uploaded using multipart/form-data pub photo: InputFile, } diff --git a/src/payloads/set_chat_sticker_set.rs b/src/payloads/set_chat_sticker_set.rs index 54410143..f63faa5d 100644 --- a/src/payloads/set_chat_sticker_set.rs +++ b/src/payloads/set_chat_sticker_set.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field _can\_set\_sticker\_set_ optionally returned in getChat requests to check if the bot can use this method. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub SetChatStickerSet (SetChatStickerSetSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Name of the sticker set to be set as the group sticker set pub sticker_set_name: String [into], } diff --git a/src/payloads/set_chat_title.rs b/src/payloads/set_chat_title.rs index 8b26a35c..8cdba296 100644 --- a/src/payloads/set_chat_title.rs +++ b/src/payloads/set_chat_title.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub SetChatTitle (SetChatTitleSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// New chat title, 1-255 characters pub title: String [into], } diff --git a/src/payloads/stop_message_live_location.rs b/src/payloads/stop_message_live_location.rs index 55c4e0e6..1ee26b5a 100644 --- a/src/payloads/stop_message_live_location.rs +++ b/src/payloads/stop_message_live_location.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, Message, ReplyMarkup}; +use crate::types::{Message, Recipient, ReplyMarkup}; impl_payload! { /// Use this method to edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to [`StopMessageLiveLocation`]. On success, the edited Message is returned. @@ -21,7 +21,7 @@ impl_payload! { pub StopMessageLiveLocation (StopMessageLiveLocationSetters) => Message { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, /// Latitude of new location diff --git a/src/payloads/stop_poll.rs b/src/payloads/stop_poll.rs index f5a956cf..c4e0ca24 100644 --- a/src/payloads/stop_poll.rs +++ b/src/payloads/stop_poll.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, InlineKeyboardMarkup, Poll}; +use crate::types::{InlineKeyboardMarkup, Poll, Recipient}; impl_payload! { /// Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned. @@ -16,7 +16,7 @@ impl_payload! { pub StopPoll (StopPollSetters) => Poll { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`). - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Identifier of the message to edit pub message_id: i32, } diff --git a/src/payloads/unban_chat_member.rs b/src/payloads/unban_chat_member.rs index ca94d87c..56dd522d 100644 --- a/src/payloads/unban_chat_member.rs +++ b/src/payloads/unban_chat_member.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// 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, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be **removed** from the chat. If you don't want this, use the parameter _only\_if\_banned_. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub UnbanChatMember (UnbanChatMemberSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target user pub user_id: i64, } diff --git a/src/payloads/unban_chat_sender_chat.rs b/src/payloads/unban_chat_sender_chat.rs index 17f5d9db..fb884acc 100644 --- a/src/payloads/unban_chat_sender_chat.rs +++ b/src/payloads/unban_chat_sender_chat.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. @@ -16,7 +16,7 @@ impl_payload! { pub UnbanChatSenderChat (UnbanChatSenderChatSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], /// Unique identifier of the target sender chat pub sender_chat_id: i64, } diff --git a/src/payloads/unpin_all_chat_messages.rs b/src/payloads/unpin_all_chat_messages.rs index 6629c6f8..25c8486a 100644 --- a/src/payloads/unpin_all_chat_messages.rs +++ b/src/payloads/unpin_all_chat_messages.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub UnpinAllChatMessages (UnpinAllChatMessagesSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } } } diff --git a/src/payloads/unpin_chat_message.rs b/src/payloads/unpin_chat_message.rs index 6ebce38b..0a05a594 100644 --- a/src/payloads/unpin_chat_message.rs +++ b/src/payloads/unpin_chat_message.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatId, True}; +use crate::types::{Recipient, True}; impl_payload! { /// Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' admin right in a supergroup or 'can_edit_messages' admin right in a channel. Returns _True_ on success. @@ -16,7 +16,7 @@ impl_payload! { pub UnpinChatMessage (UnpinChatMessageSetters) => True { required { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) - pub chat_id: ChatId [into], + pub chat_id: Recipient [into], } optional { /// Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. diff --git a/src/requests/requester.rs b/src/requests/requester.rs index 899342ed..37ad9c65 100644 --- a/src/requests/requester.rs +++ b/src/requests/requester.rs @@ -7,8 +7,8 @@ use crate::{ payloads::{GetMe, SendMessage, *}, requests::Request, types::{ - BotCommand, ChatAction, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, PassportElementError, TargetMessage, + BotCommand, ChatAction, ChatPermissions, InlineQueryResult, InputFile, InputMedia, + InputSticker, LabeledPrice, PassportElementError, Recipient, TargetMessage, }, }; @@ -103,7 +103,7 @@ pub trait Requester { /// For Telegram documentation see [`SendMessage`]. fn send_message(&self, chat_id: C, text: T) -> Self::SendMessage where - C: Into, + C: Into, T: Into; type ForwardMessage: Request; @@ -116,72 +116,72 @@ pub trait Requester { message_id: i32, ) -> Self::ForwardMessage where - C: Into, - F: Into; + C: Into, + F: Into; type CopyMessage: Request; /// For Telegram documentation see [`CopyMessage`]. fn copy_message(&self, chat_id: C, from_chat_id: F, message_id: i32) -> Self::CopyMessage where - C: Into, - F: Into; + C: Into, + F: Into; type SendPhoto: Request; /// For Telegram documentation see [`SendPhoto`]. fn send_photo(&self, chat_id: C, photo: InputFile) -> Self::SendPhoto where - C: Into; + C: Into; type SendAudio: Request; /// For Telegram documentation see [`SendAudio`]. fn send_audio(&self, chat_id: C, audio: InputFile) -> Self::SendAudio where - C: Into; + C: Into; type SendDocument: Request; /// For Telegram documentation see [`SendDocument`]. fn send_document(&self, chat_id: C, document: InputFile) -> Self::SendDocument where - C: Into; + C: Into; type SendVideo: Request; /// For Telegram documentation see [`SendVideo`]. fn send_video(&self, chat_id: C, video: InputFile) -> Self::SendVideo where - C: Into; + C: Into; type SendAnimation: Request; /// For Telegram documentation see [`SendAnimation`]. fn send_animation(&self, chat_id: C, animation: InputFile) -> Self::SendAnimation where - C: Into; + C: Into; type SendVoice: Request; /// For Telegram documentation see [`SendVoice`]. fn send_voice(&self, chat_id: C, voice: InputFile) -> Self::SendVoice where - C: Into; + C: Into; type SendVideoNote: Request; /// For Telegram documentation see [`SendVideoNote`]. fn send_video_note(&self, chat_id: C, video_note: InputFile) -> Self::SendVideoNote where - C: Into; + C: Into; type SendMediaGroup: Request; /// For Telegram documentation see [`SendMediaGroup`]. fn send_media_group(&self, chat_id: C, media: M) -> Self::SendMediaGroup where - C: Into, + C: Into, M: IntoIterator; type SendLocation: Request; @@ -189,7 +189,7 @@ pub trait Requester { /// For Telegram documentation see [`SendLocation`]. fn send_location(&self, chat_id: C, latitude: f64, longitude: f64) -> Self::SendLocation where - C: Into; + C: Into; type EditMessageLiveLocation: Request; @@ -202,7 +202,7 @@ pub trait Requester { longitude: f64, ) -> Self::EditMessageLiveLocation where - C: Into; + C: Into; type EditMessageLiveLocationInline: Request< Payload = EditMessageLiveLocationInline, @@ -230,7 +230,7 @@ pub trait Requester { longitude: f64, ) -> Self::StopMessageLiveLocation where - C: Into; + C: Into; type StopMessageLiveLocationInline: Request< Payload = StopMessageLiveLocationInline, @@ -259,7 +259,7 @@ pub trait Requester { address: A, ) -> Self::SendVenue where - C: Into, + C: Into, T: Into, A: Into; @@ -273,7 +273,7 @@ pub trait Requester { first_name: F, ) -> Self::SendContact where - C: Into, + C: Into, P: Into, F: Into; @@ -282,7 +282,7 @@ pub trait Requester { /// For Telegram documentation see [`SendPoll`]. fn send_poll(&self, chat_id: C, question: Q, options: O) -> Self::SendPoll where - C: Into, + C: Into, Q: Into, O: IntoIterator; @@ -291,14 +291,14 @@ pub trait Requester { /// For Telegram documentation see [`SendDice`]. fn send_dice(&self, chat_id: C) -> Self::SendDice where - C: Into; + C: Into; type SendChatAction: Request; /// For Telegram documentation see [`SendChatAction`]. fn send_chat_action(&self, chat_id: C, action: ChatAction) -> Self::SendChatAction where - C: Into; + C: Into; type GetUserProfilePhotos: Request; @@ -317,21 +317,21 @@ pub trait Requester { /// For Telegram documentation see [`BanChatMember`]. fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember where - C: Into; + C: Into; type KickChatMember: Request; /// For Telegram documentation see [`KickChatMember`]. fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember where - C: Into; + C: Into; type UnbanChatMember: Request; /// For Telegram documentation see [`UnbanChatMember`]. fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember where - C: Into; + C: Into; type RestrictChatMember: Request; @@ -343,14 +343,14 @@ pub trait Requester { permissions: ChatPermissions, ) -> Self::RestrictChatMember where - C: Into; + C: Into; type PromoteChatMember: Request; /// For Telegram documentation see [`PromoteChatMember`]. fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember where - C: Into; + C: Into; type SetChatAdministratorCustomTitle: Request< Payload = SetChatAdministratorCustomTitle, @@ -365,7 +365,7 @@ pub trait Requester { custom_title: Cu, ) -> Self::SetChatAdministratorCustomTitle where - Ch: Into, + Ch: Into, Cu: Into; type BanChatSenderChat: Request; @@ -373,7 +373,7 @@ pub trait Requester { /// For Telegram documentation see [`BanChatSenderChat`]. fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat where - C: Into; + C: Into; type UnbanChatSenderChat: Request; @@ -384,7 +384,7 @@ pub trait Requester { sender_chat_id: i64, ) -> Self::UnbanChatSenderChat where - C: Into; + C: Into; type SetChatPermissions: Request; @@ -395,28 +395,28 @@ pub trait Requester { permissions: ChatPermissions, ) -> Self::SetChatPermissions where - C: Into; + C: Into; type ExportChatInviteLink: Request; /// For Telegram documentation see [`ExportChatInviteLink`]. fn export_chat_invite_link(&self, chat_id: C) -> Self::ExportChatInviteLink where - C: Into; + C: Into; type CreateChatInviteLink: Request; /// For Telegram documentation see [`CreateChatInviteLink`]. fn create_chat_invite_link(&self, chat_id: C) -> Self::CreateChatInviteLink where - C: Into; + C: Into; type EditChatInviteLink: Request; /// For Telegram documentation see [`EditChatInviteLink`]. fn edit_chat_invite_link(&self, chat_id: C, invite_link: I) -> Self::EditChatInviteLink where - C: Into, + C: Into, I: Into; type RevokeChatInviteLink: Request; @@ -428,7 +428,7 @@ pub trait Requester { invite_link: I, ) -> Self::RevokeChatInviteLink where - C: Into, + C: Into, I: Into; type ApproveChatJoinRequest: Request; @@ -440,7 +440,7 @@ pub trait Requester { user_id: i64, ) -> Self::ApproveChatJoinRequest where - C: Into; + C: Into; type DeclineChatJoinRequest: Request; @@ -451,28 +451,28 @@ pub trait Requester { user_id: i64, ) -> Self::DeclineChatJoinRequest where - C: Into; + C: Into; type SetChatPhoto: Request; /// For Telegram documentation see [`SetChatPhoto`]. fn set_chat_photo(&self, chat_id: C, photo: InputFile) -> Self::SetChatPhoto where - C: Into; + C: Into; type DeleteChatPhoto: Request; /// For Telegram documentation see [`DeleteChatPhoto`]. fn delete_chat_photo(&self, chat_id: C) -> Self::DeleteChatPhoto where - C: Into; + C: Into; type SetChatTitle: Request; /// For Telegram documentation see [`SetChatTitle`]. fn set_chat_title(&self, chat_id: C, title: T) -> Self::SetChatTitle where - C: Into, + C: Into, T: Into; type SetChatDescription: Request; @@ -480,70 +480,70 @@ pub trait Requester { /// For Telegram documentation see [`SetChatDescription`]. fn set_chat_description(&self, chat_id: C) -> Self::SetChatDescription where - C: Into; + C: Into; type PinChatMessage: Request; /// For Telegram documentation see [`PinChatMessage`]. fn pin_chat_message(&self, chat_id: C, message_id: i32) -> Self::PinChatMessage where - C: Into; + C: Into; type UnpinChatMessage: Request; /// For Telegram documentation see [`UnpinChatMessage`]. fn unpin_chat_message(&self, chat_id: C) -> Self::UnpinChatMessage where - C: Into; + C: Into; type UnpinAllChatMessages: Request; /// For Telegram documentation see [`UnpinAllChatMessages`]. fn unpin_all_chat_messages(&self, chat_id: C) -> Self::UnpinAllChatMessages where - C: Into; + C: Into; type LeaveChat: Request; /// For Telegram documentation see [`LeaveChat`]. fn leave_chat(&self, chat_id: C) -> Self::LeaveChat where - C: Into; + C: Into; type GetChat: Request; /// For Telegram documentation see [`GetChat`]. fn get_chat(&self, chat_id: C) -> Self::GetChat where - C: Into; + C: Into; type GetChatAdministrators: Request; /// For Telegram documentation see [`GetChatAdministrators`]. fn get_chat_administrators(&self, chat_id: C) -> Self::GetChatAdministrators where - C: Into; + C: Into; type GetChatMemberCount: Request; /// For Telegram documentation see [`GetChatMemberCount`]. fn get_chat_member_count(&self, chat_id: C) -> Self::GetChatMemberCount where - C: Into; + C: Into; type GetChatMembersCount: Request; /// For Telegram documentation see [`GetChatMembersCount`]. fn get_chat_members_count(&self, chat_id: C) -> Self::GetChatMembersCount where - C: Into; + C: Into; type GetChatMember: Request; /// For Telegram documentation see [`GetChatMember`]. fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember where - C: Into; + C: Into; type SetChatStickerSet: Request; @@ -554,7 +554,7 @@ pub trait Requester { sticker_set_name: S, ) -> Self::SetChatStickerSet where - C: Into, + C: Into, S: Into; type DeleteChatStickerSet: Request; @@ -562,7 +562,7 @@ pub trait Requester { /// For Telegram documentation see [`DeleteChatStickerSet`]. fn delete_chat_sticker_set(&self, chat_id: C) -> Self::DeleteChatStickerSet where - C: Into; + C: Into; type AnswerCallbackQuery: Request; @@ -606,7 +606,7 @@ pub trait Requester { text: T, ) -> Self::EditMessageText where - C: Into, + C: Into, T: Into; type EditMessageTextInline: Request; @@ -626,7 +626,7 @@ pub trait Requester { /// For Telegram documentation see [`EditMessageCaption`]. fn edit_message_caption(&self, chat_id: C, message_id: i32) -> Self::EditMessageCaption where - C: Into; + C: Into; type EditMessageCaptionInline: Request; @@ -648,7 +648,7 @@ pub trait Requester { media: InputMedia, ) -> Self::EditMessageMedia where - C: Into; + C: Into; type EditMessageMediaInline: Request; @@ -670,7 +670,7 @@ pub trait Requester { message_id: i32, ) -> Self::EditMessageReplyMarkup where - C: Into; + C: Into; type EditMessageReplyMarkupInline: Request< Payload = EditMessageReplyMarkupInline, @@ -690,21 +690,21 @@ pub trait Requester { /// For Telegram documentation see [`StopPoll`]. fn stop_poll(&self, chat_id: C, message_id: i32) -> Self::StopPoll where - C: Into; + C: Into; type DeleteMessage: Request; /// For Telegram documentation see [`DeleteMessage`]. fn delete_message(&self, chat_id: C, message_id: i32) -> Self::DeleteMessage where - C: Into; + C: Into; type SendSticker: Request; /// For Telegram documentation see [`SendSticker`]. fn send_sticker(&self, chat_id: C, sticker: InputFile) -> Self::SendSticker where - C: Into; + C: Into; type GetStickerSet: Request; @@ -787,7 +787,7 @@ pub trait Requester { prices: Pri, ) -> Self::SendInvoice where - Ch: Into, + Ch: Into, T: Into, D: Into, Pa: Into, diff --git a/src/types.rs b/src/types.rs index 751b1842..c4a55ab3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -9,7 +9,6 @@ pub use callback_game::*; pub use callback_query::*; pub use chat::*; pub use chat_action::*; -pub use chat_id::*; pub use chat_invite_link::*; pub use chat_join_request::*; pub use chat_location::*; @@ -115,7 +114,6 @@ mod callback_game; mod callback_query; mod chat; mod chat_action; -mod chat_id; mod chat_invite_link; mod chat_join_request; mod chat_location; @@ -222,6 +220,10 @@ mod non_telegram_types { pub(super) mod until_date; } +mod recipient; + +pub use recipient::*; + pub(crate) mod serde_opt_date_from_unix_timestamp { use chrono::{DateTime, NaiveDateTime, Utc}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; diff --git a/src/types/bot_command_scope.rs b/src/types/bot_command_scope.rs index d6051941..e3b17517 100644 --- a/src/types/bot_command_scope.rs +++ b/src/types/bot_command_scope.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::ChatId; +use crate::types::Recipient; /// This object represents the scope to which bot commands are applied. /// @@ -49,20 +49,20 @@ pub enum BotCommandScope { AllPrivateChats, AllGroupChats, AllChatAdministrators, - Chat { chat_id: ChatId }, - ChatAdministrators { chat_id: ChatId }, - ChatMember { chat_id: ChatId, user_id: i64 }, + Chat { chat_id: Recipient }, + ChatAdministrators { chat_id: Recipient }, + ChatMember { chat_id: Recipient, user_id: i64 }, } #[test] fn issue_486() { serde_json::to_string(&BotCommandScope::Chat { - chat_id: ChatId::Id(0), + chat_id: Recipient::Id(0), }) .unwrap(); serde_json::to_string(&BotCommandScope::ChatAdministrators { - chat_id: ChatId::Id(0), + chat_id: Recipient::Id(0), }) .unwrap(); } diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index 8a5b88a9..8b137891 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -1,82 +1 @@ -use derive_more::{Display, From}; -use serde::{Deserialize, Serialize}; -/// A unique identifier for the target chat or username of the target channel -/// (in the format `@channelusername`). -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Display, From)] -#[serde(untagged)] -pub enum ChatId { - /// A chat identifier. - #[display(fmt = "{}", _0)] - Id(i64), - - /// A channel username (in the format @channelusername). - #[display(fmt = "{}", _0)] - ChannelUsername(String), -} - -impl ChatId { - pub(crate) fn is_channel(&self) -> bool { - matches!(self.unmark(), None | Some(UnmarkedChatId::Channel(_))) - } - - pub(crate) fn unmark(&self) -> Option { - use UnmarkedChatId::*; - - // https://github.com/mtcute/mtcute/blob/6933ecc3f82dd2e9100f52b0afec128af564713b/packages/core/src/utils/peer-utils.ts#L4 - const MIN_MARKED_CHANNEL_ID: i64 = -1997852516352; - const MAX_MARKED_CHANNEL_ID: i64 = -1000000000000; - const MIN_MARKED_CHAT_ID: i64 = MAX_MARKED_CHANNEL_ID + 1; - const MAX_MARKED_CHAT_ID: i64 = MIN_USER_ID - 1; - const MIN_USER_ID: i64 = 0; - const MAX_USER_ID: i64 = (1 << 40) - 1; - - let res = match self { - &Self::Id(id @ MIN_MARKED_CHAT_ID..=MAX_MARKED_CHAT_ID) => Chat(-id as _), - &Self::Id(id @ MIN_MARKED_CHANNEL_ID..=MAX_MARKED_CHANNEL_ID) => { - Channel((MAX_MARKED_CHANNEL_ID - id) as _) - } - &Self::Id(id @ MIN_USER_ID..=MAX_USER_ID) => User(id as _), - &Self::Id(id) => panic!("malformed chat id: {}", id), - Self::ChannelUsername(_) => return None, - }; - - Some(res) - } -} - -pub(crate) enum UnmarkedChatId { - User(u64), - Chat(u64), - Channel(u64), -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn chat_id_id_serialization() { - let expected_json = String::from(r#"123456"#); - let actual_json = serde_json::to_string(&ChatId::Id(123_456)).unwrap(); - - assert_eq!(expected_json, actual_json) - } - - #[test] - fn chat_id_channel_username_serialization() { - let expected_json = String::from(r#""@username""#); - let actual_json = - serde_json::to_string(&ChatId::ChannelUsername(String::from("@username"))).unwrap(); - - assert_eq!(expected_json, actual_json) - } - - #[test] - fn user_id_unmark() { - assert!(matches!( - ChatId::Id(5298363099).unmark(), - Some(UnmarkedChatId::User(5298363099)) - )); - } -} diff --git a/src/types/recipient.rs b/src/types/recipient.rs new file mode 100644 index 00000000..e1664448 --- /dev/null +++ b/src/types/recipient.rs @@ -0,0 +1,82 @@ +use derive_more::{Display, From}; +use serde::{Deserialize, Serialize}; + +/// A unique identifier for the target chat or username of the target channel +/// (in the format `@channelusername`). +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Display, From)] +#[serde(untagged)] +pub enum Recipient { + /// A chat identifier. + #[display(fmt = "{}", _0)] + Id(i64), + + /// A channel username (in the format @channelusername). + #[display(fmt = "{}", _0)] + ChannelUsername(String), +} + +impl Recipient { + pub(crate) fn is_channel(&self) -> bool { + matches!(self.unmark(), None | Some(UnmarkedChatId::Channel(_))) + } + + pub(crate) fn unmark(&self) -> Option { + use UnmarkedChatId::*; + + // https://github.com/mtcute/mtcute/blob/6933ecc3f82dd2e9100f52b0afec128af564713b/packages/core/src/utils/peer-utils.ts#L4 + const MIN_MARKED_CHANNEL_ID: i64 = -1997852516352; + const MAX_MARKED_CHANNEL_ID: i64 = -1000000000000; + const MIN_MARKED_CHAT_ID: i64 = MAX_MARKED_CHANNEL_ID + 1; + const MAX_MARKED_CHAT_ID: i64 = MIN_USER_ID - 1; + const MIN_USER_ID: i64 = 0; + const MAX_USER_ID: i64 = (1 << 40) - 1; + + let res = match self { + &Self::Id(id @ MIN_MARKED_CHAT_ID..=MAX_MARKED_CHAT_ID) => Chat(-id as _), + &Self::Id(id @ MIN_MARKED_CHANNEL_ID..=MAX_MARKED_CHANNEL_ID) => { + Channel((MAX_MARKED_CHANNEL_ID - id) as _) + } + &Self::Id(id @ MIN_USER_ID..=MAX_USER_ID) => User(id as _), + &Self::Id(id) => panic!("malformed chat id: {}", id), + Self::ChannelUsername(_) => return None, + }; + + Some(res) + } +} + +pub(crate) enum UnmarkedChatId { + User(u64), + Chat(u64), + Channel(u64), +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn chat_id_id_serialization() { + let expected_json = String::from(r#"123456"#); + let actual_json = serde_json::to_string(&Recipient::Id(123_456)).unwrap(); + + assert_eq!(expected_json, actual_json) + } + + #[test] + fn chat_id_channel_username_serialization() { + let expected_json = String::from(r#""@username""#); + let actual_json = + serde_json::to_string(&Recipient::ChannelUsername(String::from("@username"))).unwrap(); + + assert_eq!(expected_json, actual_json) + } + + #[test] + fn user_id_unmark() { + assert!(matches!( + Recipient::Id(5298363099).unmark(), + Some(UnmarkedChatId::User(5298363099)) + )); + } +} diff --git a/src/types/target_message.rs b/src/types/target_message.rs index 0c0d8cc1..66f2409e 100644 --- a/src/types/target_message.rs +++ b/src/types/target_message.rs @@ -1,4 +1,4 @@ -use crate::types::ChatId; +use crate::types::Recipient; use serde::{Deserialize, Serialize}; @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum TargetMessage { - Common { chat_id: ChatId, message_id: i32 }, + Common { chat_id: Recipient, message_id: i32 }, Inline { inline_message_id: String }, } From 41e09159a68e263da35e586bda7d095b5673c7b9 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 18:53:13 +0400 Subject: [PATCH 07/15] Make user id typed (add `UserId`) Reason: when user id is just an integer, it's easy to accidentally use a "random" integer instead of actual user id, typed APIs make code less prone to some mistakes. This commit also fixes an issue when a wrong integer type was used for `user_id` in `Contact`. Another option that this addition unlocks is adding methods/implementing foreign trait for `UserId`. --- src/adaptors/erased.rs | 77 +++++++++---------- src/bot/api.rs | 51 +++++++----- src/local_macros.rs | 72 ++++++++--------- src/payloads/add_sticker_to_set.rs | 4 +- src/payloads/approve_chat_join_request.rs | 4 +- src/payloads/ban_chat_member.rs | 4 +- src/payloads/create_new_sticker_set.rs | 4 +- src/payloads/decline_chat_join_request.rs | 4 +- src/payloads/get_chat_member.rs | 4 +- src/payloads/get_game_high_scores.rs | 4 +- src/payloads/get_user_profile_photos.rs | 4 +- src/payloads/kick_chat_member.rs | 4 +- src/payloads/promote_chat_member.rs | 4 +- src/payloads/restrict_chat_member.rs | 4 +- .../set_chat_administrator_custom_title.rs | 4 +- src/payloads/set_game_score.rs | 4 +- src/payloads/set_game_score_inline.rs | 4 +- src/payloads/set_passport_data_errors.rs | 4 +- src/payloads/set_sticker_set_thumb.rs | 4 +- src/payloads/unban_chat_member.rs | 4 +- src/payloads/upload_sticker_file.rs | 4 +- src/requests/requester.rs | 46 ++++++----- src/serde_multipart/mod.rs | 4 +- src/types.rs | 2 + src/types/bot_command_scope.rs | 4 +- src/types/callback_query.rs | 4 +- src/types/chat_member.rs | 4 +- src/types/contact.rs | 4 +- src/types/update.rs | 4 +- src/types/user.rs | 12 +-- src/types/user_id.rs | 33 ++++++++ 31 files changed, 224 insertions(+), 165 deletions(-) create mode 100644 src/types/user_id.rs diff --git a/src/adaptors/erased.rs b/src/adaptors/erased.rs index 3199c734..a951f037 100644 --- a/src/adaptors/erased.rs +++ b/src/adaptors/erased.rs @@ -6,10 +6,7 @@ use reqwest::Url; use crate::{ payloads::*, requests::{HasPayload, Output, Payload, Request, Requester}, - types::{ - BotCommand, ChatAction, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, PassportElementError, Recipient, TargetMessage, - }, + types::*, }; /// [`Requester`] with erased type. @@ -343,7 +340,7 @@ trait ErasableRequester<'a> { fn get_user_profile_photos( &self, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, GetUserProfilePhotos, Self::Err>; fn get_file(&self, file_id: String) -> ErasedRequest<'a, GetFile, Self::Err>; @@ -351,38 +348,38 @@ trait ErasableRequester<'a> { fn ban_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, BanChatMember, Self::Err>; fn kick_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, KickChatMember, Self::Err>; fn unban_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, UnbanChatMember, Self::Err>; fn restrict_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, permissions: ChatPermissions, ) -> ErasedRequest<'a, RestrictChatMember, Self::Err>; fn promote_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, PromoteChatMember, Self::Err>; fn set_chat_administrator_custom_title( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, custom_title: String, ) -> ErasedRequest<'a, SetChatAdministratorCustomTitle, Self::Err>; @@ -430,14 +427,14 @@ trait ErasableRequester<'a> { fn approve_chat_join_request( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, ApproveChatJoinRequest, Self::Err>; /// For Telegram documentation see [`DeclineChatJoinRequest`]. fn decline_chat_join_request( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, DeclineChatJoinRequest, Self::Err>; fn set_chat_photo( @@ -500,7 +497,7 @@ trait ErasableRequester<'a> { fn get_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, GetChatMember, Self::Err>; fn set_chat_sticker_set( @@ -604,13 +601,13 @@ trait ErasableRequester<'a> { fn upload_sticker_file( &self, - user_id: i64, + user_id: UserId, png_sticker: InputFile, ) -> ErasedRequest<'a, UploadStickerFile, Self::Err>; fn create_new_sticker_set( &self, - user_id: i64, + user_id: UserId, name: String, title: String, sticker: InputSticker, @@ -619,7 +616,7 @@ trait ErasableRequester<'a> { fn add_sticker_to_set( &self, - user_id: i64, + user_id: UserId, name: String, sticker: InputSticker, emojis: String, @@ -639,7 +636,7 @@ trait ErasableRequester<'a> { fn set_sticker_set_thumb( &self, name: String, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, SetStickerSetThumb, Self::Err>; // we can't change telegram API @@ -669,7 +666,7 @@ trait ErasableRequester<'a> { fn set_passport_data_errors( &self, - user_id: i64, + user_id: UserId, errors: Vec, ) -> ErasedRequest<'a, SetPassportDataErrors, Self::Err>; @@ -681,7 +678,7 @@ trait ErasableRequester<'a> { fn set_game_score( &self, - user_id: i64, + user_id: UserId, score: u64, chat_id: u32, message_id: i64, @@ -689,14 +686,14 @@ trait ErasableRequester<'a> { fn set_game_score_inline( &self, - user_id: i64, + user_id: UserId, score: u64, inline_message_id: String, ) -> ErasedRequest<'a, SetGameScoreInline, Self::Err>; fn get_game_high_scores( &self, - user_id: i64, + user_id: UserId, target: TargetMessage, ) -> ErasedRequest<'a, GetGameHighScores, Self::Err>; } @@ -919,7 +916,7 @@ where fn get_user_profile_photos( &self, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, GetUserProfilePhotos, Self::Err> { Requester::get_user_profile_photos(self, user_id).erase() } @@ -931,7 +928,7 @@ where fn ban_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, BanChatMember, Self::Err> { Requester::ban_chat_member(self, chat_id, user_id).erase() } @@ -939,7 +936,7 @@ where fn kick_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, KickChatMember, Self::Err> { Requester::kick_chat_member(self, chat_id, user_id).erase() } @@ -947,7 +944,7 @@ where fn unban_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, UnbanChatMember, Self::Err> { Requester::unban_chat_member(self, chat_id, user_id).erase() } @@ -955,7 +952,7 @@ where fn restrict_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, permissions: ChatPermissions, ) -> ErasedRequest<'a, RestrictChatMember, Self::Err> { Requester::restrict_chat_member(self, chat_id, user_id, permissions).erase() @@ -964,7 +961,7 @@ where fn promote_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, PromoteChatMember, Self::Err> { Requester::promote_chat_member(self, chat_id, user_id).erase() } @@ -972,7 +969,7 @@ where fn set_chat_administrator_custom_title( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, custom_title: String, ) -> ErasedRequest<'a, SetChatAdministratorCustomTitle, Self::Err> { Requester::set_chat_administrator_custom_title(self, chat_id, user_id, custom_title).erase() @@ -1036,7 +1033,7 @@ where fn approve_chat_join_request( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, ApproveChatJoinRequest, Self::Err> { Requester::approve_chat_join_request(self, chat_id, user_id).erase() } @@ -1045,7 +1042,7 @@ where fn decline_chat_join_request( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, DeclineChatJoinRequest, Self::Err> { Requester::decline_chat_join_request(self, chat_id, user_id).erase() } @@ -1134,7 +1131,7 @@ where fn get_chat_member( &self, chat_id: Recipient, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, GetChatMember, Self::Err> { Requester::get_chat_member(self, chat_id, user_id).erase() } @@ -1278,7 +1275,7 @@ where fn upload_sticker_file( &self, - user_id: i64, + user_id: UserId, png_sticker: InputFile, ) -> ErasedRequest<'a, UploadStickerFile, Self::Err> { Requester::upload_sticker_file(self, user_id, png_sticker).erase() @@ -1286,7 +1283,7 @@ where fn create_new_sticker_set( &self, - user_id: i64, + user_id: UserId, name: String, title: String, sticker: InputSticker, @@ -1297,7 +1294,7 @@ where fn add_sticker_to_set( &self, - user_id: i64, + user_id: UserId, name: String, sticker: InputSticker, emojis: String, @@ -1323,7 +1320,7 @@ where fn set_sticker_set_thumb( &self, name: String, - user_id: i64, + user_id: UserId, ) -> ErasedRequest<'a, SetStickerSetThumb, Self::Err> { Requester::set_sticker_set_thumb(self, name, user_id).erase() } @@ -1369,7 +1366,7 @@ where fn set_passport_data_errors( &self, - user_id: i64, + user_id: UserId, errors: Vec, ) -> ErasedRequest<'a, SetPassportDataErrors, Self::Err> { Requester::set_passport_data_errors(self, user_id, errors).erase() @@ -1385,7 +1382,7 @@ where fn set_game_score( &self, - user_id: i64, + user_id: UserId, score: u64, chat_id: u32, message_id: i64, @@ -1395,7 +1392,7 @@ where fn set_game_score_inline( &self, - user_id: i64, + user_id: UserId, score: u64, inline_message_id: String, ) -> ErasedRequest<'a, SetGameScoreInline, Self::Err> { @@ -1404,7 +1401,7 @@ where fn get_game_high_scores( &self, - user_id: i64, + user_id: UserId, target: TargetMessage, ) -> ErasedRequest<'a, GetGameHighScores, Self::Err> { Requester::get_game_high_scores(self, user_id, target).erase() diff --git a/src/bot/api.rs b/src/bot/api.rs index d9462f01..4383e536 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -6,7 +6,7 @@ use crate::{ requests::{JsonRequest, MultipartRequest}, types::{ BotCommand, ChatPermissions, InlineQueryResult, InputFile, InputMedia, InputSticker, - LabeledPrice, Recipient, + LabeledPrice, Recipient, UserId, }, Bot, }; @@ -306,7 +306,7 @@ impl Requester for Bot { type GetUserProfilePhotos = JsonRequest; - fn get_user_profile_photos(&self, user_id: i64) -> Self::GetUserProfilePhotos { + fn get_user_profile_photos(&self, user_id: UserId) -> Self::GetUserProfilePhotos { Self::GetUserProfilePhotos::new(self.clone(), payloads::GetUserProfilePhotos::new(user_id)) } @@ -321,7 +321,7 @@ impl Requester for Bot { type KickChatMember = JsonRequest; - fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember + fn kick_chat_member(&self, chat_id: C, user_id: UserId) -> Self::KickChatMember where C: Into, { @@ -333,7 +333,7 @@ impl Requester for Bot { type BanChatMember = JsonRequest; - fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember + fn ban_chat_member(&self, chat_id: C, user_id: UserId) -> Self::BanChatMember where C: Into, { @@ -342,7 +342,7 @@ impl Requester for Bot { type UnbanChatMember = JsonRequest; - fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember + fn unban_chat_member(&self, chat_id: C, user_id: UserId) -> Self::UnbanChatMember where C: Into, { @@ -357,7 +357,7 @@ impl Requester for Bot { fn restrict_chat_member( &self, chat_id: C, - user_id: i64, + user_id: UserId, permissions: ChatPermissions, ) -> Self::RestrictChatMember where @@ -371,7 +371,7 @@ impl Requester for Bot { type PromoteChatMember = JsonRequest; - fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember + fn promote_chat_member(&self, chat_id: C, user_id: UserId) -> Self::PromoteChatMember where C: Into, { @@ -386,7 +386,7 @@ impl Requester for Bot { fn set_chat_administrator_custom_title( &self, chat_id: Ch, - user_id: i64, + user_id: UserId, custom_title: Cu, ) -> Self::SetChatAdministratorCustomTitle where @@ -493,7 +493,11 @@ impl Requester for Bot { type ApproveChatJoinRequest = JsonRequest; - fn approve_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::ApproveChatJoinRequest + fn approve_chat_join_request( + &self, + chat_id: C, + user_id: UserId, + ) -> Self::ApproveChatJoinRequest where C: Into, { @@ -505,7 +509,11 @@ impl Requester for Bot { type DeclineChatJoinRequest = JsonRequest; - fn decline_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::DeclineChatJoinRequest + fn decline_chat_join_request( + &self, + chat_id: C, + user_id: UserId, + ) -> Self::DeclineChatJoinRequest where C: Into, { @@ -623,7 +631,7 @@ impl Requester for Bot { type GetChatMember = JsonRequest; - fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember + fn get_chat_member(&self, chat_id: C, user_id: UserId) -> Self::GetChatMember where C: Into, { @@ -857,8 +865,11 @@ impl Requester for Bot { type UploadStickerFile = MultipartRequest; - fn upload_sticker_file(&self, user_id: i64, png_sticker: InputFile) -> Self::UploadStickerFile where - { + fn upload_sticker_file( + &self, + user_id: UserId, + png_sticker: InputFile, + ) -> Self::UploadStickerFile where { Self::UploadStickerFile::new( self.clone(), payloads::UploadStickerFile::new(user_id, png_sticker), @@ -869,7 +880,7 @@ impl Requester for Bot { fn create_new_sticker_set( &self, - user_id: i64, + user_id: UserId, name: N, title: T, sticker: InputSticker, @@ -890,7 +901,7 @@ impl Requester for Bot { fn add_sticker_to_set( &self, - user_id: i64, + user_id: UserId, name: N, sticker: InputSticker, emojis: E, @@ -932,7 +943,7 @@ impl Requester for Bot { type SetStickerSetThumb = MultipartRequest; - fn set_sticker_set_thumb(&self, name: N, user_id: i64) -> Self::SetStickerSetThumb + fn set_sticker_set_thumb(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumb where N: Into, { @@ -1007,7 +1018,7 @@ impl Requester for Bot { type SetPassportDataErrors = JsonRequest; - fn set_passport_data_errors(&self, user_id: i64, errors: E) -> Self::SetPassportDataErrors + fn set_passport_data_errors(&self, user_id: UserId, errors: E) -> Self::SetPassportDataErrors where E: IntoIterator, { @@ -1033,7 +1044,7 @@ impl Requester for Bot { fn set_game_score( &self, - user_id: i64, + user_id: UserId, score: u64, chat_id: u32, message_id: i64, @@ -1048,7 +1059,7 @@ impl Requester for Bot { fn set_game_score_inline( &self, - user_id: i64, + user_id: UserId, score: u64, inline_message_id: I, ) -> Self::SetGameScoreInline @@ -1063,7 +1074,7 @@ impl Requester for Bot { type GetGameHighScores = JsonRequest; - fn get_game_high_scores(&self, user_id: i64, target: T) -> Self::GetGameHighScores + fn get_game_high_scores(&self, user_id: UserId, target: T) -> Self::GetGameHighScores where T: Into, { diff --git a/src/local_macros.rs b/src/local_macros.rs index f7289c51..e31876b8 100644 --- a/src/local_macros.rs +++ b/src/local_macros.rs @@ -659,9 +659,9 @@ macro_rules! requester_forward { (@method get_user_profile_photos $body:ident $ty:ident) => { type GetUserProfilePhotos = $ty![GetUserProfilePhotos]; - fn get_user_profile_photos(&self, user_id: i64) -> Self::GetUserProfilePhotos { + fn get_user_profile_photos(&self, user_id: UserId) -> Self::GetUserProfilePhotos { let this = self; - $body!(get_user_profile_photos this (user_id: i64)) + $body!(get_user_profile_photos this (user_id: UserId)) } }; (@method get_file $body:ident $ty:ident) => { @@ -675,50 +675,50 @@ macro_rules! requester_forward { (@method ban_chat_member $body:ident $ty:ident) => { type BanChatMember = $ty![BanChatMember]; - fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember where C: Into { + fn ban_chat_member(&self, chat_id: C, user_id: UserId) -> Self::BanChatMember where C: Into { let this = self; - $body!(ban_chat_member this (chat_id: C, user_id: i64)) + $body!(ban_chat_member this (chat_id: C, user_id: UserId)) } }; (@method kick_chat_member $body:ident $ty:ident) => { type KickChatMember = $ty![KickChatMember]; - fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember where C: Into { + fn kick_chat_member(&self, chat_id: C, user_id: UserId) -> Self::KickChatMember where C: Into { let this = self; - $body!(kick_chat_member this (chat_id: C, user_id: i64)) + $body!(kick_chat_member this (chat_id: C, user_id: UserId)) } }; (@method unban_chat_member $body:ident $ty:ident) => { type UnbanChatMember = $ty![UnbanChatMember]; - fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember where C: Into { + fn unban_chat_member(&self, chat_id: C, user_id: UserId) -> Self::UnbanChatMember where C: Into { let this = self; - $body!(unban_chat_member this (chat_id: C, user_id: i64)) + $body!(unban_chat_member this (chat_id: C, user_id: UserId)) } }; (@method restrict_chat_member $body:ident $ty:ident) => { type RestrictChatMember = $ty![RestrictChatMember]; - fn restrict_chat_member(&self, chat_id: C, user_id: i64, permissions: ChatPermissions) -> Self::RestrictChatMember where C: Into { + fn restrict_chat_member(&self, chat_id: C, user_id: UserId, permissions: ChatPermissions) -> Self::RestrictChatMember where C: Into { let this = self; - $body!(restrict_chat_member this (chat_id: C, user_id: i64, permissions: ChatPermissions)) + $body!(restrict_chat_member this (chat_id: C, user_id: UserId, permissions: ChatPermissions)) } }; (@method promote_chat_member $body:ident $ty:ident) => { type PromoteChatMember = $ty![PromoteChatMember]; - fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember where C: Into { + fn promote_chat_member(&self, chat_id: C, user_id: UserId) -> Self::PromoteChatMember where C: Into { let this = self; - $body!(promote_chat_member this (chat_id: C, user_id: i64)) + $body!(promote_chat_member this (chat_id: C, user_id: UserId)) } }; (@method set_chat_administrator_custom_title $body:ident $ty:ident) => { type SetChatAdministratorCustomTitle = $ty![SetChatAdministratorCustomTitle]; - fn set_chat_administrator_custom_title(&self, chat_id: Ch, user_id: i64, custom_title: Cu) -> Self::SetChatAdministratorCustomTitle where Ch: Into, + fn set_chat_administrator_custom_title(&self, chat_id: Ch, user_id: UserId, custom_title: Cu) -> Self::SetChatAdministratorCustomTitle where Ch: Into, Cu: Into { let this = self; - $body!(set_chat_administrator_custom_title this (chat_id: Ch, user_id: i64, custom_title: Cu)) + $body!(set_chat_administrator_custom_title this (chat_id: Ch, user_id: UserId, custom_title: Cu)) } }; (@method ban_chat_sender_chat $body:ident $ty:ident) => { @@ -782,17 +782,17 @@ macro_rules! requester_forward { (@method approve_chat_join_request $body:ident $ty:ident) => { type ApproveChatJoinRequest = $ty![ApproveChatJoinRequest]; - fn approve_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::ApproveChatJoinRequest where C: Into { + fn approve_chat_join_request(&self, chat_id: C, user_id: UserId) -> Self::ApproveChatJoinRequest where C: Into { let this = self; - $body!(approve_chat_join_request this (chat_id: C, user_id: i64)) + $body!(approve_chat_join_request this (chat_id: C, user_id: UserId)) } }; (@method decline_chat_join_request $body:ident $ty:ident) => { type DeclineChatJoinRequest = $ty![DeclineChatJoinRequest]; - fn decline_chat_join_request(&self, chat_id: C, user_id: i64) -> Self::DeclineChatJoinRequest where C: Into { + fn decline_chat_join_request(&self, chat_id: C, user_id: UserId) -> Self::DeclineChatJoinRequest where C: Into { let this = self; - $body!(decline_chat_join_request this (chat_id: C, user_id: i64)) + $body!(decline_chat_join_request this (chat_id: C, user_id: UserId)) } }; (@method set_chat_photo $body:ident $ty:ident) => { @@ -895,9 +895,9 @@ macro_rules! requester_forward { (@method get_chat_member $body:ident $ty:ident) => { type GetChatMember = $ty![GetChatMember]; - fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember where C: Into { + fn get_chat_member(&self, chat_id: C, user_id: UserId) -> Self::GetChatMember where C: Into { let this = self; - $body!(get_chat_member this (chat_id: C, user_id: i64)) + $body!(get_chat_member this (chat_id: C, user_id: UserId)) } }; (@method set_chat_sticker_set $body:ident $ty:ident) => { @@ -1059,28 +1059,28 @@ macro_rules! requester_forward { (@method upload_sticker_file $body:ident $ty:ident) => { type UploadStickerFile = $ty![UploadStickerFile]; - fn upload_sticker_file(&self, user_id: i64, png_sticker: InputFile) -> Self::UploadStickerFile { + fn upload_sticker_file(&self, user_id: UserId, png_sticker: InputFile) -> Self::UploadStickerFile { let this = self; - $body!(upload_sticker_file this (user_id: i64, png_sticker: InputFile)) + $body!(upload_sticker_file this (user_id: UserId, png_sticker: InputFile)) } }; (@method create_new_sticker_set $body:ident $ty:ident) => { type CreateNewStickerSet = $ty![CreateNewStickerSet]; - fn create_new_sticker_set(&self, user_id: i64, name: N, title: T, sticker: InputSticker, emojis: E) -> Self::CreateNewStickerSet where N: Into, + fn create_new_sticker_set(&self, user_id: UserId, name: N, title: T, sticker: InputSticker, emojis: E) -> Self::CreateNewStickerSet where N: Into, T: Into, E: Into { let this = self; - $body!(create_new_sticker_set this (user_id: i64, name: N, title: T, sticker: InputSticker, emojis: E)) + $body!(create_new_sticker_set this (user_id: UserId, name: N, title: T, sticker: InputSticker, emojis: E)) } }; (@method add_sticker_to_set $body:ident $ty:ident) => { type AddStickerToSet = $ty![AddStickerToSet]; - fn add_sticker_to_set(&self, user_id: i64, name: N, sticker: InputSticker, emojis: E) -> Self::AddStickerToSet where N: Into, + fn add_sticker_to_set(&self, user_id: UserId, name: N, sticker: InputSticker, emojis: E) -> Self::AddStickerToSet where N: Into, E: Into { let this = self; - $body!(add_sticker_to_set this (user_id: i64, name: N, sticker: InputSticker, emojis: E)) + $body!(add_sticker_to_set this (user_id: UserId, name: N, sticker: InputSticker, emojis: E)) } }; (@method set_sticker_position_in_set $body:ident $ty:ident) => { @@ -1102,9 +1102,9 @@ macro_rules! requester_forward { (@method set_sticker_set_thumb $body:ident $ty:ident) => { type SetStickerSetThumb = $ty![SetStickerSetThumb]; - fn set_sticker_set_thumb(&self, name: N, user_id: i64) -> Self::SetStickerSetThumb where N: Into { + fn set_sticker_set_thumb(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumb where N: Into { let this = self; - $body!(set_sticker_set_thumb this (name: N, user_id: i64)) + $body!(set_sticker_set_thumb this (name: N, user_id: UserId)) } }; (@method send_invoice $body:ident $ty:ident) => { @@ -1140,9 +1140,9 @@ macro_rules! requester_forward { (@method set_passport_data_errors $body:ident $ty:ident) => { type SetPassportDataErrors = $ty![SetPassportDataErrors]; - fn set_passport_data_errors(&self, user_id: i64, errors: E) -> Self::SetPassportDataErrors where E: IntoIterator { + fn set_passport_data_errors(&self, user_id: UserId, errors: E) -> Self::SetPassportDataErrors where E: IntoIterator { let this = self; - $body!(set_passport_data_errors this (user_id: i64, errors: E)) + $body!(set_passport_data_errors this (user_id: UserId, errors: E)) } }; (@method send_game $body:ident $ty:ident) => { @@ -1156,25 +1156,25 @@ macro_rules! requester_forward { (@method set_game_score $body:ident $ty:ident) => { type SetGameScore = $ty![SetGameScore]; - fn set_game_score(&self, user_id: i64, score: u64, chat_id: u32, message_id: i64) -> Self::SetGameScore { + fn set_game_score(&self, user_id: UserId, score: u64, chat_id: u32, message_id: i64) -> Self::SetGameScore { let this = self; - $body!(set_game_score this (user_id: i64, score: u64, chat_id: u32, message_id: i64)) + $body!(set_game_score this (user_id: UserId, score: u64, chat_id: u32, message_id: i64)) } }; (@method set_game_score_inline $body:ident $ty:ident) => { type SetGameScoreInline = $ty![SetGameScoreInline]; - fn set_game_score_inline(&self, user_id: i64, score: u64, inline_message_id: I) -> Self::SetGameScoreInline where I: Into { + fn set_game_score_inline(&self, user_id: UserId, score: u64, inline_message_id: I) -> Self::SetGameScoreInline where I: Into { let this = self; - $body!(set_game_score_inline this (user_id: i64, score: u64, inline_message_id: I)) + $body!(set_game_score_inline this (user_id: UserId, score: u64, inline_message_id: I)) } }; (@method get_game_high_scores $body:ident $ty:ident) => { type GetGameHighScores = $ty![GetGameHighScores]; - fn get_game_high_scores(&self, user_id: i64, target: T) -> Self::GetGameHighScores where T: Into { + fn get_game_high_scores(&self, user_id: UserId, target: T) -> Self::GetGameHighScores where T: Into { let this = self; - $body!(get_game_high_scores this (user_id: i64, target: T)) + $body!(get_game_high_scores this (user_id: UserId, target: T)) } }; } diff --git a/src/payloads/add_sticker_to_set.rs b/src/payloads/add_sticker_to_set.rs index 0ea3907e..a231d9e3 100644 --- a/src/payloads/add_sticker_to_set.rs +++ b/src/payloads/add_sticker_to_set.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{InputSticker, MaskPosition, True}; +use crate::types::{InputSticker, MaskPosition, True, UserId}; impl_payload! { @[multipart = sticker] @@ -17,7 +17,7 @@ impl_payload! { pub AddStickerToSet (AddStickerToSetSetters) => True { required { /// User identifier of sticker file owner - pub user_id: i64, + pub user_id: UserId, /// Sticker set name pub name: String [into], /// **PNG** or **TGS** image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a _file\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »] diff --git a/src/payloads/approve_chat_join_request.rs b/src/payloads/approve_chat_join_request.rs index 2c1b2781..eac96cf3 100644 --- a/src/payloads/approve_chat_join_request.rs +++ b/src/payloads/approve_chat_join_request.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the _can_invite_users_ administrator right. Returns _True_ on success. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } } } diff --git a/src/payloads/ban_chat_member.rs b/src/payloads/ban_chat_member.rs index 1464935e..c9262bfd 100644 --- a/src/payloads/ban_chat_member.rs +++ b/src/payloads/ban_chat_member.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless [unbanned] first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success. @@ -21,7 +21,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } optional { /// Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever diff --git a/src/payloads/create_new_sticker_set.rs b/src/payloads/create_new_sticker_set.rs index c3fa4abe..1ba21044 100644 --- a/src/payloads/create_new_sticker_set.rs +++ b/src/payloads/create_new_sticker_set.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{InputSticker, MaskPosition, True}; +use crate::types::{InputSticker, MaskPosition, True, UserId}; impl_payload! { @[multipart = sticker] @@ -17,7 +17,7 @@ impl_payload! { pub CreateNewStickerSet (CreateNewStickerSetSetters) => True { required { /// User identifier of sticker file owner - pub user_id: i64, + pub user_id: UserId, /// Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g., _animals_). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in _“\_by\_”. _ is case insensitive. 1-64 characters. pub name: String [into], /// Sticker set title, 1-64 characters diff --git a/src/payloads/decline_chat_join_request.rs b/src/payloads/decline_chat_join_request.rs index e7f5b87e..6524b027 100644 --- a/src/payloads/decline_chat_join_request.rs +++ b/src/payloads/decline_chat_join_request.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the _can_invite_users_ administrator right. Returns _True_ on success. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } } } diff --git a/src/payloads/get_chat_member.rs b/src/payloads/get_chat_member.rs index dcf4f979..eee95f01 100644 --- a/src/payloads/get_chat_member.rs +++ b/src/payloads/get_chat_member.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{ChatMember, Recipient}; +use crate::types::{ChatMember, Recipient, UserId}; impl_payload! { /// Use this method to get information about a member of a chat. Returns a [`ChatMember`] object on success. @@ -20,7 +20,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } } } diff --git a/src/payloads/get_game_high_scores.rs b/src/payloads/get_game_high_scores.rs index 854cd5e4..d38a3468 100644 --- a/src/payloads/get_game_high_scores.rs +++ b/src/payloads/get_game_high_scores.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{TargetMessage, True}; +use crate::types::{TargetMessage, True, UserId}; impl_payload! { /// Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of [`GameHighScore`] objects. @@ -20,7 +20,7 @@ impl_payload! { pub GetGameHighScores (GetGameHighScoresSetters) => True { required { /// User identifier - pub user_id: i64, + pub user_id: UserId, /// Target message #[serde(flatten)] pub target: TargetMessage [into], diff --git a/src/payloads/get_user_profile_photos.rs b/src/payloads/get_user_profile_photos.rs index 56a97492..193e8438 100644 --- a/src/payloads/get_user_profile_photos.rs +++ b/src/payloads/get_user_profile_photos.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::UserProfilePhotos; +use crate::types::{UserId, UserProfilePhotos}; impl_payload! { /// Use this method to get a list of profile pictures for a user. Returns a [`UserProfilePhotos`] object. @@ -18,7 +18,7 @@ impl_payload! { pub GetUserProfilePhotos (GetUserProfilePhotosSetters) => UserProfilePhotos { required { /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } optional { /// Sequential number of the first photo to be returned. By default, all photos are returned. diff --git a/src/payloads/kick_chat_member.rs b/src/payloads/kick_chat_member.rs index 75eef991..9b45538d 100644 --- a/src/payloads/kick_chat_member.rs +++ b/src/payloads/kick_chat_member.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless [unbanned] first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns _True_ on success. @@ -21,7 +21,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } optional { /// Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever diff --git a/src/payloads/promote_chat_member.rs b/src/payloads/promote_chat_member.rs index 3170756b..8af4b0b9 100644 --- a/src/payloads/promote_chat_member.rs +++ b/src/payloads/promote_chat_member.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass _False_ for all boolean parameters to demote a user. Returns _True_ on success. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } optional { /// Pass True, if the administrator's presence in the chat is hidden diff --git a/src/payloads/restrict_chat_member.rs b/src/payloads/restrict_chat_member.rs index 003632a4..a390cbef 100644 --- a/src/payloads/restrict_chat_member.rs +++ b/src/payloads/restrict_chat_member.rs @@ -9,7 +9,7 @@ use chrono::{DateTime, Utc}; use serde::Serialize; -use crate::types::{ChatPermissions, Recipient, True}; +use crate::types::{ChatPermissions, Recipient, True, UserId}; impl_payload! { /// Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass _True_ for all permissions to lift restrictions from a user. Returns _True_ on success. @@ -19,7 +19,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, /// A JSON-serialized object for new user permissions pub permissions: ChatPermissions, } diff --git a/src/payloads/set_chat_administrator_custom_title.rs b/src/payloads/set_chat_administrator_custom_title.rs index 5f5d772a..fe82a6c7 100644 --- a/src/payloads/set_chat_administrator_custom_title.rs +++ b/src/payloads/set_chat_administrator_custom_title.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// Use this method to set a custom title for an administrator in a supergroup promoted by the bot. Returns _True_on success. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, /// New custom title for the administrator; 0-16 characters, emoji are not allowed pub custom_title: String [into], } diff --git a/src/payloads/set_game_score.rs b/src/payloads/set_game_score.rs index 5d1bdb4c..540a7323 100644 --- a/src/payloads/set_game_score.rs +++ b/src/payloads/set_game_score.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::Message; +use crate::types::{Message, UserId}; impl_payload! { /// Use this method to set the score of the specified user in a game. On success, returns the edited [`Message`]. Returns an error, if the new score is not greater than the user's current score in the chat and force is False. @@ -20,7 +20,7 @@ impl_payload! { pub SetGameScore (SetGameScoreSetters) => Message { required { /// User identifier - pub user_id: i64, + pub user_id: UserId, /// New score pub score: u64, /// Unique identifier for the target chat diff --git a/src/payloads/set_game_score_inline.rs b/src/payloads/set_game_score_inline.rs index 1b62c50a..90f6269b 100644 --- a/src/payloads/set_game_score_inline.rs +++ b/src/payloads/set_game_score_inline.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::Message; +use crate::types::{Message, UserId}; impl_payload! { /// Use this method to set the score of the specified user in a game. On success, returns _True_. Returns an error, if the new score is not greater than the user's current score in the chat and force is False. @@ -18,7 +18,7 @@ impl_payload! { pub SetGameScoreInline (SetGameScoreInlineSetters) => Message { required { /// User identifier - pub user_id: i64, + pub user_id: UserId, /// New score pub score: u64, /// Identifier of the inline message diff --git a/src/payloads/set_passport_data_errors.rs b/src/payloads/set_passport_data_errors.rs index fdb52796..d906071f 100644 --- a/src/payloads/set_passport_data_errors.rs +++ b/src/payloads/set_passport_data_errors.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{PassportElementError, True}; +use crate::types::{PassportElementError, True, UserId}; impl_payload! { /// Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns _True_ on success. @@ -18,7 +18,7 @@ impl_payload! { pub SetPassportDataErrors (SetPassportDataErrorsSetters) => True { required { /// User identifier - pub user_id: i64, + pub user_id: UserId, /// A JSON-serialized array describing the errors pub errors: Vec [collect], } diff --git a/src/payloads/set_sticker_set_thumb.rs b/src/payloads/set_sticker_set_thumb.rs index 022ab8e3..1aaecab3 100644 --- a/src/payloads/set_sticker_set_thumb.rs +++ b/src/payloads/set_sticker_set_thumb.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{InputFile, True}; +use crate::types::{InputFile, True, UserId}; impl_payload! { @[multipart = thumb] @@ -19,7 +19,7 @@ impl_payload! { /// Name of the sticker set pub name: String [into], /// User identifier of sticker file owner - pub user_id: i64, + pub user_id: UserId, } optional { /// A **PNG** image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a **TGS** animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements. Pass a _file\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »]. Animated sticker set thumbnail can't be uploaded via HTTP URL. diff --git a/src/payloads/unban_chat_member.rs b/src/payloads/unban_chat_member.rs index 56dd522d..d58f35c8 100644 --- a/src/payloads/unban_chat_member.rs +++ b/src/payloads/unban_chat_member.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{Recipient, True, UserId}; impl_payload! { /// 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, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be **removed** from the chat. If you don't want this, use the parameter _only\_if\_banned_. Returns _True_ on success. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target user - pub user_id: i64, + pub user_id: UserId, } optional { /// Do nothing if the user is not banned diff --git a/src/payloads/upload_sticker_file.rs b/src/payloads/upload_sticker_file.rs index f1d190eb..77c5468b 100644 --- a/src/payloads/upload_sticker_file.rs +++ b/src/payloads/upload_sticker_file.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{File, InputFile}; +use crate::types::{File, InputFile, UserId}; impl_payload! { @[multipart = png_sticker] @@ -17,7 +17,7 @@ impl_payload! { pub UploadStickerFile (UploadStickerFileSetters) => File { required { /// User identifier of sticker file owner - pub user_id: i64, + pub user_id: UserId, /// PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile diff --git a/src/requests/requester.rs b/src/requests/requester.rs index 37ad9c65..7df85bee 100644 --- a/src/requests/requester.rs +++ b/src/requests/requester.rs @@ -8,7 +8,7 @@ use crate::{ requests::Request, types::{ BotCommand, ChatAction, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, PassportElementError, Recipient, TargetMessage, + InputSticker, LabeledPrice, PassportElementError, Recipient, TargetMessage, UserId, }, }; @@ -303,7 +303,7 @@ pub trait Requester { type GetUserProfilePhotos: Request; /// For Telegram documentation see [`GetUserProfilePhotos`]. - fn get_user_profile_photos(&self, user_id: i64) -> Self::GetUserProfilePhotos; + fn get_user_profile_photos(&self, user_id: UserId) -> Self::GetUserProfilePhotos; type GetFile: Request; @@ -315,21 +315,21 @@ pub trait Requester { type BanChatMember: Request; /// For Telegram documentation see [`BanChatMember`]. - fn ban_chat_member(&self, chat_id: C, user_id: i64) -> Self::BanChatMember + fn ban_chat_member(&self, chat_id: C, user_id: UserId) -> Self::BanChatMember where C: Into; type KickChatMember: Request; /// For Telegram documentation see [`KickChatMember`]. - fn kick_chat_member(&self, chat_id: C, user_id: i64) -> Self::KickChatMember + fn kick_chat_member(&self, chat_id: C, user_id: UserId) -> Self::KickChatMember where C: Into; type UnbanChatMember: Request; /// For Telegram documentation see [`UnbanChatMember`]. - fn unban_chat_member(&self, chat_id: C, user_id: i64) -> Self::UnbanChatMember + fn unban_chat_member(&self, chat_id: C, user_id: UserId) -> Self::UnbanChatMember where C: Into; @@ -339,7 +339,7 @@ pub trait Requester { fn restrict_chat_member( &self, chat_id: C, - user_id: i64, + user_id: UserId, permissions: ChatPermissions, ) -> Self::RestrictChatMember where @@ -348,7 +348,7 @@ pub trait Requester { type PromoteChatMember: Request; /// For Telegram documentation see [`PromoteChatMember`]. - fn promote_chat_member(&self, chat_id: C, user_id: i64) -> Self::PromoteChatMember + fn promote_chat_member(&self, chat_id: C, user_id: UserId) -> Self::PromoteChatMember where C: Into; @@ -361,7 +361,7 @@ pub trait Requester { fn set_chat_administrator_custom_title( &self, chat_id: Ch, - user_id: i64, + user_id: UserId, custom_title: Cu, ) -> Self::SetChatAdministratorCustomTitle where @@ -437,7 +437,7 @@ pub trait Requester { fn approve_chat_join_request( &self, chat_id: C, - user_id: i64, + user_id: UserId, ) -> Self::ApproveChatJoinRequest where C: Into; @@ -448,7 +448,7 @@ pub trait Requester { fn decline_chat_join_request( &self, chat_id: C, - user_id: i64, + user_id: UserId, ) -> Self::DeclineChatJoinRequest where C: Into; @@ -541,7 +541,7 @@ pub trait Requester { type GetChatMember: Request; /// For Telegram documentation see [`GetChatMember`]. - fn get_chat_member(&self, chat_id: C, user_id: i64) -> Self::GetChatMember + fn get_chat_member(&self, chat_id: C, user_id: UserId) -> Self::GetChatMember where C: Into; @@ -716,14 +716,18 @@ pub trait Requester { type UploadStickerFile: Request; /// For Telegram documentation see [`UploadStickerFile`]. - fn upload_sticker_file(&self, user_id: i64, png_sticker: InputFile) -> Self::UploadStickerFile; + fn upload_sticker_file( + &self, + user_id: UserId, + png_sticker: InputFile, + ) -> Self::UploadStickerFile; type CreateNewStickerSet: Request; /// For Telegram documentation see [`CreateNewStickerSet`]. fn create_new_sticker_set( &self, - user_id: i64, + user_id: UserId, name: N, title: T, sticker: InputSticker, @@ -739,7 +743,7 @@ pub trait Requester { /// For Telegram documentation see [`AddStickerToSet`]. fn add_sticker_to_set( &self, - user_id: i64, + user_id: UserId, name: N, sticker: InputSticker, emojis: E, @@ -769,7 +773,7 @@ pub trait Requester { type SetStickerSetThumb: Request; /// For Telegram documentation see [`SetStickerSetThumb`]. - fn set_sticker_set_thumb(&self, name: N, user_id: i64) -> Self::SetStickerSetThumb + fn set_sticker_set_thumb(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumb where N: Into; @@ -816,7 +820,11 @@ pub trait Requester { type SetPassportDataErrors: Request; /// For Telegram documentation see [`SetPassportDataErrors`]. - fn set_passport_data_errors(&self, user_id: i64, errors: E) -> Self::SetPassportDataErrors + fn set_passport_data_errors( + &self, + user_id: UserId, + errors: E, + ) -> Self::SetPassportDataErrors where E: IntoIterator; @@ -832,7 +840,7 @@ pub trait Requester { /// For Telegram documentation see [`SetGameScore`]. fn set_game_score( &self, - user_id: i64, + user_id: UserId, score: u64, chat_id: u32, message_id: i64, @@ -843,7 +851,7 @@ pub trait Requester { /// For Telegram documentation see [`SetGameScoreInline`]. fn set_game_score_inline( &self, - user_id: i64, + user_id: UserId, score: u64, inline_message_id: I, ) -> Self::SetGameScoreInline @@ -853,7 +861,7 @@ pub trait Requester { type GetGameHighScores: Request; /// For Telegram documentation see [`GetGameHighScores`]. - fn get_game_high_scores(&self, user_id: i64, target: T) -> Self::GetGameHighScores + fn get_game_high_scores(&self, user_id: UserId, target: T) -> Self::GetGameHighScores where T: Into; } diff --git a/src/serde_multipart/mod.rs b/src/serde_multipart/mod.rs index 5e992595..bb279722 100644 --- a/src/serde_multipart/mod.rs +++ b/src/serde_multipart/mod.rs @@ -90,7 +90,7 @@ mod tests { types::{ InputFile, InputMedia, InputMediaAnimation, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo, InputSticker, MessageEntity, MessageEntityKind, - ParseMode, + ParseMode, UserId, }, }; @@ -151,7 +151,7 @@ mod tests { #[tokio::test] async fn test_add_sticker_to_set() { to_form_ref(&payloads::AddStickerToSet::new( - 0, + UserId(0), "name", InputSticker::Png(InputFile::file("./media/logo.png")), "✈️⚙️", diff --git a/src/types.rs b/src/types.rs index c4a55ab3..230fdcaf 100644 --- a/src/types.rs +++ b/src/types.rs @@ -221,8 +221,10 @@ mod non_telegram_types { } mod recipient; +mod user_id; pub use recipient::*; +pub use user_id::*; pub(crate) mod serde_opt_date_from_unix_timestamp { use chrono::{DateTime, NaiveDateTime, Utc}; diff --git a/src/types/bot_command_scope.rs b/src/types/bot_command_scope.rs index e3b17517..8a7042c9 100644 --- a/src/types/bot_command_scope.rs +++ b/src/types/bot_command_scope.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::Recipient; +use crate::types::{Recipient, UserId}; /// This object represents the scope to which bot commands are applied. /// @@ -51,7 +51,7 @@ pub enum BotCommandScope { AllChatAdministrators, Chat { chat_id: Recipient }, ChatAdministrators { chat_id: Recipient }, - ChatMember { chat_id: Recipient, user_id: i64 }, + ChatMember { chat_id: Recipient, user_id: UserId }, } #[test] diff --git a/src/types/callback_query.rs b/src/types/callback_query.rs index 47cedb96..92d2f920 100644 --- a/src/types/callback_query.rs +++ b/src/types/callback_query.rs @@ -51,6 +51,8 @@ pub struct CallbackQuery { #[cfg(test)] mod tests { + use crate::types::UserId; + use super::*; #[test] @@ -70,7 +72,7 @@ mod tests { let expected = CallbackQuery { id: "id".to_string(), from: User { - id: 12345, + id: UserId(12345), is_bot: false, first_name: "firstName".to_string(), last_name: None, diff --git a/src/types/chat_member.rs b/src/types/chat_member.rs index ed577bac..0bfd5607 100644 --- a/src/types/chat_member.rs +++ b/src/types/chat_member.rs @@ -591,6 +591,8 @@ pub enum ChatMemberStatus { #[cfg(test)] mod tests { + use crate::types::UserId; + use super::*; #[test] @@ -618,7 +620,7 @@ mod tests { }"#; let expected = ChatMember { user: User { - id: 1029940401, + id: UserId(1029940401), is_bot: false, first_name: "First".to_string(), last_name: Some("Last".to_string()), diff --git a/src/types/contact.rs b/src/types/contact.rs index 147d31dd..f2fef9be 100644 --- a/src/types/contact.rs +++ b/src/types/contact.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::types::UserId; + /// This object represents a phone contact. /// /// [The official docs](https://core.telegram.org/bots/api#contact). @@ -16,7 +18,7 @@ pub struct Contact { pub last_name: Option, /// A contact's user identifier in Telegram. - pub user_id: Option, + pub user_id: Option, /// Additional data about the contact in the form of a [vCard]. /// diff --git a/src/types/update.rs b/src/types/update.rs index 02d62a77..1b97031b 100644 --- a/src/types/update.rs +++ b/src/types/update.rs @@ -295,7 +295,7 @@ impl Serialize for UpdateKind { mod test { use crate::types::{ Chat, ChatKind, ChatPrivate, MediaKind, MediaText, Message, MessageCommon, MessageKind, - Update, UpdateKind, User, + Update, UpdateKind, User, UserId, }; use chrono::{DateTime, NaiveDateTime, Utc}; @@ -350,7 +350,7 @@ mod test { }, kind: MessageKind::Common(MessageCommon { from: Some(User { - id: 218_485_655, + id: UserId(218_485_655), is_bot: false, first_name: String::from("Waffle"), last_name: None, diff --git a/src/types/user.rs b/src/types/user.rs index f748fe96..978ddfa0 100644 --- a/src/types/user.rs +++ b/src/types/user.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::types::UserId; + /// This object represents a Telegram user or bot. /// /// [The official docs](https://core.telegram.org/bots/api#user). @@ -7,7 +9,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct User { /// Unique identifier for this user or bot. - pub id: i64, + pub id: UserId, /// `true`, if this user is a bot. pub is_bot: bool, @@ -53,7 +55,7 @@ impl User { /// denote an anonymous user that sends messages on behalf of a group. pub fn is_anonymous(&self) -> bool { // https://github.com/tdlib/td/blob/4791fb6a2af0257f6cad8396e10424a79ee5f768/td/telegram/ContactsManager.cpp#L4941-L4943 - const ANON_ID: i64 = 1087968824; + const ANON_ID: UserId = UserId(1087968824); // Sanity check debug_assert!( @@ -71,7 +73,7 @@ impl User { /// denote an anonymous user that sends messages on behalf of a channel. pub fn is_channel(&self) -> bool { // https://github.com/tdlib/td/blob/4791fb6a2af0257f6cad8396e10424a79ee5f768/td/telegram/ContactsManager.cpp#L4945-L4947 - const ANON_CHANNEL_ID: i64 = 136817688; + const ANON_CHANNEL_ID: UserId = UserId(136817688); // Sanity check debug_assert!( @@ -91,7 +93,7 @@ impl User { /// is automatically forwarded to a group, bots in a group will get a /// message where `from` is the Telegram user. pub fn is_telegram(&self) -> bool { - const TELEGRAM_USER_ID: i64 = 777000; + const TELEGRAM_USER_ID: UserId = UserId(777000); // Sanity check debug_assert!( @@ -121,7 +123,7 @@ mod tests { "language_code":"ru" }"#; let expected = User { - id: 12345, + id: UserId(12345), is_bot: false, first_name: "firstName".to_string(), last_name: Some("lastName".to_string()), diff --git a/src/types/user_id.rs b/src/types/user_id.rs new file mode 100644 index 00000000..70211323 --- /dev/null +++ b/src/types/user_id.rs @@ -0,0 +1,33 @@ +use derive_more::Display; +use serde::{Deserialize, Serialize}; + +/// Identifier of a user. +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Serialize, Deserialize, +)] +#[serde(transparent)] +pub struct UserId(pub u64); + +#[cfg(test)] +mod tests { + use serde::{Deserialize, Serialize}; + + use crate::types::UserId; + + /// Test that `UserId` is serialized as the underlying integer + #[test] + fn deser() { + let user_id = S { + user_id: UserId(17), + }; + let json = r#"{"user_id":17}"#; + + #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] + struct S { + user_id: UserId, + } + + assert_eq!(serde_json::to_string(&user_id).unwrap(), json); + assert_eq!(user_id, serde_json::from_str(json).unwrap()); + } +} From f2378935b74edf9a4570b60a2af05d351132f17a Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 20:33:08 +0400 Subject: [PATCH 08/15] Make chat id typed (add `ChatId`) Note that this is different from the previous `ChatId` (that was renamed to `Recipient`), since it can't hold @channelusername. Reason: same as w/ `UserId` --- src/adaptors/erased.rs | 8 +-- src/adaptors/throttle.rs | 4 +- src/bot/api.rs | 8 +-- src/lib.rs | 2 +- src/local_macros.rs | 8 +-- src/payloads/ban_chat_sender_chat.rs | 4 +- src/payloads/unban_chat_sender_chat.rs | 4 +- src/requests/request.rs | 6 +- src/requests/requester.rs | 31 +++++++---- src/serde_multipart/mod.rs | 12 ++-- src/types.rs | 2 + src/types/bot_command_scope.rs | 6 +- src/types/chat.rs | 18 +++--- src/types/chat_id.rs | 77 ++++++++++++++++++++++++++ src/types/message.rs | 40 ++++++------- src/types/recipient.rs | 50 +++-------------- src/types/update.rs | 6 +- 17 files changed, 171 insertions(+), 115 deletions(-) diff --git a/src/adaptors/erased.rs b/src/adaptors/erased.rs index a951f037..6dd77a1b 100644 --- a/src/adaptors/erased.rs +++ b/src/adaptors/erased.rs @@ -386,13 +386,13 @@ trait ErasableRequester<'a> { fn ban_chat_sender_chat( &self, chat_id: Recipient, - sender_chat_id: i64, + sender_chat_id: ChatId, ) -> ErasedRequest<'a, BanChatSenderChat, Self::Err>; fn unban_chat_sender_chat( &self, chat_id: Recipient, - sender_chat_id: i64, + sender_chat_id: ChatId, ) -> ErasedRequest<'a, UnbanChatSenderChat, Self::Err>; fn set_chat_permissions( @@ -978,7 +978,7 @@ where fn ban_chat_sender_chat( &self, chat_id: Recipient, - sender_chat_id: i64, + sender_chat_id: ChatId, ) -> ErasedRequest<'a, BanChatSenderChat, Self::Err> { Requester::ban_chat_sender_chat(self, chat_id, sender_chat_id).erase() } @@ -986,7 +986,7 @@ where fn unban_chat_sender_chat( &self, chat_id: Recipient, - sender_chat_id: i64, + sender_chat_id: ChatId, ) -> ErasedRequest<'a, UnbanChatSenderChat, Self::Err> { Requester::unban_chat_sender_chat(self, chat_id, sender_chat_id).erase() } diff --git a/src/adaptors/throttle.rs b/src/adaptors/throttle.rs index 8c03535f..908697a0 100644 --- a/src/adaptors/throttle.rs +++ b/src/adaptors/throttle.rs @@ -638,14 +638,14 @@ download_forward! { /// usernames. (It is just a hashed username.) #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)] enum ChatIdHash { - Id(i64), + Id(ChatId), ChannelUsernameHash(u64), } impl ChatIdHash { fn is_channel(&self) -> bool { match self { - &Self::Id(id) => Recipient::Id(id).is_channel(), + &Self::Id(id) => id.is_channel(), Self::ChannelUsernameHash(_) => true, } } diff --git a/src/bot/api.rs b/src/bot/api.rs index 4383e536..0fdb8a51 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -5,8 +5,8 @@ use crate::{ prelude::Requester, requests::{JsonRequest, MultipartRequest}, types::{ - BotCommand, ChatPermissions, InlineQueryResult, InputFile, InputMedia, InputSticker, - LabeledPrice, Recipient, UserId, + BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, + InputSticker, LabeledPrice, Recipient, UserId, }, Bot, }; @@ -401,7 +401,7 @@ impl Requester for Bot { type BanChatSenderChat = JsonRequest; - fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat + fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: ChatId) -> Self::BanChatSenderChat where C: Into, { @@ -416,7 +416,7 @@ impl Requester for Bot { fn unban_chat_sender_chat( &self, chat_id: C, - sender_chat_id: i64, + sender_chat_id: ChatId, ) -> Self::UnbanChatSenderChat where C: Into, diff --git a/src/lib.rs b/src/lib.rs index 1f222b6b..71e89323 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ //! ``` //! # #[cfg(feature = "auto_send")] //! # async { -//! # let chat_id = 0; +//! # let chat_id = teloxide_core::types::ChatId(-1); //! use teloxide_core::{ //! prelude::*, //! types::{DiceEmoji, ParseMode}, diff --git a/src/local_macros.rs b/src/local_macros.rs index e31876b8..43f26711 100644 --- a/src/local_macros.rs +++ b/src/local_macros.rs @@ -724,17 +724,17 @@ macro_rules! requester_forward { (@method ban_chat_sender_chat $body:ident $ty:ident) => { type BanChatSenderChat = $ty![BanChatSenderChat]; - fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat where C: Into { + fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: ChatId) -> Self::BanChatSenderChat where C: Into { let this = self; - $body!(ban_chat_sender_chat this (chat_id: C, sender_chat_id: i64)) + $body!(ban_chat_sender_chat this (chat_id: C, sender_chat_id: ChatId)) } }; (@method unban_chat_sender_chat $body:ident $ty:ident) => { type UnbanChatSenderChat = $ty![UnbanChatSenderChat]; - fn unban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::UnbanChatSenderChat where C: Into { + fn unban_chat_sender_chat(&self, chat_id: C, sender_chat_id: ChatId) -> Self::UnbanChatSenderChat where C: Into { let this = self; - $body!(unban_chat_sender_chat this (chat_id: C, sender_chat_id: i64)) + $body!(unban_chat_sender_chat this (chat_id: C, sender_chat_id: ChatId)) } }; (@method set_chat_permissions $body:ident $ty:ident) => { diff --git a/src/payloads/ban_chat_sender_chat.rs b/src/payloads/ban_chat_sender_chat.rs index 3aaf7863..dd1d43ef 100644 --- a/src/payloads/ban_chat_sender_chat.rs +++ b/src/payloads/ban_chat_sender_chat.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{ChatId, Recipient, True}; impl_payload! { /// Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target sender chat - pub sender_chat_id: i64, + pub sender_chat_id: ChatId, } } } diff --git a/src/payloads/unban_chat_sender_chat.rs b/src/payloads/unban_chat_sender_chat.rs index fb884acc..b4ec78f2 100644 --- a/src/payloads/unban_chat_sender_chat.rs +++ b/src/payloads/unban_chat_sender_chat.rs @@ -8,7 +8,7 @@ // [`schema`]: https://github.com/WaffleLapkin/tg-methods-schema use serde::Serialize; -use crate::types::{Recipient, True}; +use crate::types::{ChatId, Recipient, True}; impl_payload! { /// Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target sender chat - pub sender_chat_id: i64, + pub sender_chat_id: ChatId, } } } diff --git a/src/requests/request.rs b/src/requests/request.rs index 0dd99e86..ee91232b 100644 --- a/src/requests/request.rs +++ b/src/requests/request.rs @@ -75,12 +75,12 @@ pub trait Request: HasPayload { /// ## Examples /// ``` /// # async { - /// use teloxide_core::{prelude::*, requests::Request, Bot}; + /// use teloxide_core::{prelude::*, requests::Request, types::ChatId, Bot}; /// /// let bot = Bot::new("TOKEN"); - /// # let chat_ids = vec![1i64, 2, 3, 4].into_iter().map(Into::into); + /// # let chat_ids = vec![1i64, 2, 3, 4].into_iter().map(ChatId).map(Into::into).collect::>(); /// - /// let mut req = bot.send_message(0, "Hi there!"); + /// let mut req = bot.send_message(ChatId(0xAAAAAAAA), "Hi there!"); /// for chat_id in chat_ids { /// req.chat_id = chat_id; /// req.send_ref().await.unwrap(); diff --git a/src/requests/requester.rs b/src/requests/requester.rs index 7df85bee..1cde022e 100644 --- a/src/requests/requester.rs +++ b/src/requests/requester.rs @@ -6,10 +6,7 @@ use url::Url; use crate::{ payloads::{GetMe, SendMessage, *}, requests::Request, - types::{ - BotCommand, ChatAction, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, PassportElementError, Recipient, TargetMessage, UserId, - }, + types::*, }; /// Methods for building requests. @@ -22,27 +19,35 @@ use crate::{ /// /// ``` /// # async { -/// use teloxide_core::{prelude::*, types::ParseMode}; +/// # let chat_id = ChatId(-1); +/// use teloxide_core::{ +/// prelude::*, +/// types::{ChatId, ParseMode}, +/// }; /// /// // Bot implements `Requester` /// let bot = Bot::new("TOKEN"); /// /// // Required parameters are supplied to the `Requester` methods: -/// bot.send_message(0, "Text") +/// bot.send_message(chat_id, "Text") /// // Optional parameters can be supplied by calling setters /// .parse_mode(ParseMode::Html) /// // To send request to telegram you need to call `.send()` and await the resulting future /// .send() /// .await?; -/// # Ok::<_, teloxide_core::RequestError>(()) }; +/// # Ok::<_, teloxide_core::RequestError>(()) +/// # }; /// ``` /// /// Using `Requester` in a generic context: /// /// ``` -/// use teloxide_core::{prelude::*, types::Message}; +/// use teloxide_core::{ +/// prelude::*, +/// types::{ChatId, Message}, +/// }; /// -/// async fn send_hi(bot: R, chat: i64) -> Message +/// async fn send_hi(bot: R, chat: ChatId) -> Message /// where /// R: Requester, /// { @@ -371,7 +376,11 @@ pub trait Requester { type BanChatSenderChat: Request; /// For Telegram documentation see [`BanChatSenderChat`]. - fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: i64) -> Self::BanChatSenderChat + fn ban_chat_sender_chat( + &self, + chat_id: C, + sender_chat_id: ChatId, + ) -> Self::BanChatSenderChat where C: Into; @@ -381,7 +390,7 @@ pub trait Requester { fn unban_chat_sender_chat( &self, chat_id: C, - sender_chat_id: i64, + sender_chat_id: ChatId, ) -> Self::UnbanChatSenderChat where C: Into; diff --git a/src/serde_multipart/mod.rs b/src/serde_multipart/mod.rs index bb279722..5d04902a 100644 --- a/src/serde_multipart/mod.rs +++ b/src/serde_multipart/mod.rs @@ -88,9 +88,9 @@ mod tests { use crate::{ payloads::{self, setters::*}, types::{ - InputFile, InputMedia, InputMediaAnimation, InputMediaAudio, InputMediaDocument, - InputMediaPhoto, InputMediaVideo, InputSticker, MessageEntity, MessageEntityKind, - ParseMode, UserId, + ChatId, InputFile, InputMedia, InputMediaAnimation, InputMediaAudio, + InputMediaDocument, InputMediaPhoto, InputMediaVideo, InputSticker, MessageEntity, + MessageEntityKind, ParseMode, UserId, }, }; @@ -98,7 +98,7 @@ mod tests { #[tokio::test] async fn issue_473() { to_form_ref( - &payloads::SendPhoto::new(0, InputFile::file_id("0")).caption_entities([ + &payloads::SendPhoto::new(ChatId(0), InputFile::file_id("0")).caption_entities([ MessageEntity { kind: MessageEntityKind::Url, offset: 0, @@ -115,7 +115,7 @@ mod tests { const CAPTION: &str = "caption"; to_form_ref(&payloads::SendMediaGroup::new( - 0, + ChatId(0), [ InputMedia::Photo( InputMediaPhoto::new(InputFile::file("./media/logo.png")) @@ -163,7 +163,7 @@ mod tests { #[tokio::test] async fn test_send_animation() { to_form_ref( - &payloads::SendAnimation::new(0, InputFile::file("./media/logo.png")) + &payloads::SendAnimation::new(ChatId(0), InputFile::file("./media/logo.png")) .caption_entities(entities()) .thumb(InputFile::read( File::open("./media/logo.png").await.unwrap(), diff --git a/src/types.rs b/src/types.rs index 230fdcaf..100b1279 100644 --- a/src/types.rs +++ b/src/types.rs @@ -220,9 +220,11 @@ mod non_telegram_types { pub(super) mod until_date; } +mod chat_id; mod recipient; mod user_id; +pub use chat_id::*; pub use recipient::*; pub use user_id::*; diff --git a/src/types/bot_command_scope.rs b/src/types/bot_command_scope.rs index 8a7042c9..e005aabb 100644 --- a/src/types/bot_command_scope.rs +++ b/src/types/bot_command_scope.rs @@ -56,13 +56,15 @@ pub enum BotCommandScope { #[test] fn issue_486() { + use crate::types::ChatId; + serde_json::to_string(&BotCommandScope::Chat { - chat_id: Recipient::Id(0), + chat_id: Recipient::Id(ChatId(0)), }) .unwrap(); serde_json::to_string(&BotCommandScope::ChatAdministrators { - chat_id: Recipient::Id(0), + chat_id: Recipient::Id(ChatId(0)), }) .unwrap(); } diff --git a/src/types/chat.rs b/src/types/chat.rs index a3e6f3fa..626b4d95 100644 --- a/src/types/chat.rs +++ b/src/types/chat.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{ChatLocation, ChatPermissions, ChatPhoto, Message, True}; +use crate::types::{ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, True}; /// This object represents a chat. /// @@ -8,12 +8,8 @@ use crate::types::{ChatLocation, ChatPermissions, ChatPhoto, Message, True}; #[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Chat { - /// A unique identifier for this chat. This number may be greater than 32 - /// bits and some programming languages may have difficulty/silent defects - /// in interpreting it. But it is smaller than 52 bits, so a signed 64 bit - /// integer or double-precision float type are safe for storing this - /// identifier. - pub id: i64, + /// A unique identifier for this chat. + pub id: ChatId, #[serde(flatten)] pub kind: ChatKind, @@ -454,11 +450,11 @@ mod tests { #[test] fn channel_de() { let expected = Chat { - id: -1, + id: ChatId(-1), kind: ChatKind::Public(ChatPublic { title: None, kind: PublicChatKind::Channel(PublicChatChannel { - username: Some("channelname".into()), + username: Some("channel_name".into()), linked_chat_id: None, }), description: None, @@ -469,7 +465,7 @@ mod tests { pinned_message: None, message_auto_delete_time: None, }; - let actual = from_str(r#"{"id":-1,"type":"channel","username":"channelname"}"#).unwrap(); + let actual = from_str(r#"{"id":-1,"type":"channel","username":"channel_name"}"#).unwrap(); assert_eq!(expected, actual); } @@ -477,7 +473,7 @@ mod tests { fn private_chat_de() { assert_eq!( Chat { - id: 0, + id: ChatId(0), kind: ChatKind::Private(ChatPrivate { type_: (), username: Some("username".into()), diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index 8b137891..d66c84f3 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -1 +1,78 @@ +use derive_more::Display; +use serde::{Deserialize, Serialize}; +use crate::types::UserId; + +/// Identifier of a chat. +/// +/// Note that "a chat" here means any of group, supergroup, channel or user PM. +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Serialize, Deserialize, +)] +#[serde(transparent)] +pub struct ChatId(pub i64); + +impl ChatId { + pub(crate) fn is_channel(self) -> bool { + matches!(self.unmark(), UnmarkedChatId::Channel(_)) + } + + pub(crate) fn unmark(self) -> UnmarkedChatId { + use UnmarkedChatId::*; + + // https://github.com/mtcute/mtcute/blob/6933ecc3f82dd2e9100f52b0afec128af564713b/packages/core/src/utils/peer-utils.ts#L4 + const MIN_MARKED_CHANNEL_ID: i64 = -1997852516352; + const MAX_MARKED_CHANNEL_ID: i64 = -1000000000000; + const MIN_MARKED_CHAT_ID: i64 = MAX_MARKED_CHANNEL_ID + 1; + const MAX_MARKED_CHAT_ID: i64 = MIN_USER_ID - 1; + const MIN_USER_ID: i64 = 0; + const MAX_USER_ID: i64 = (1 << 40) - 1; + + match self.0 { + id @ MIN_MARKED_CHAT_ID..=MAX_MARKED_CHAT_ID => Group(-id as _), + id @ MIN_MARKED_CHANNEL_ID..=MAX_MARKED_CHANNEL_ID => { + Channel((MAX_MARKED_CHANNEL_ID - id) as _) + } + id @ MIN_USER_ID..=MAX_USER_ID => User(UserId(id as _)), + id => panic!("malformed chat id: {}", id), + } + } +} + +pub(crate) enum UnmarkedChatId { + User(UserId), + Group(u64), + Channel(u64), +} + +#[cfg(test)] +mod tests { + use serde::{Deserialize, Serialize}; + + use crate::types::{ChatId, UnmarkedChatId, UserId}; + + /// Test that `ChatId` is serialized as the underlying integer + #[test] + fn deser() { + let chat_id = S { + chat_id: ChatId(0xAA), + }; + let json = r#"{"chat_id":170}"#; + + #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] + struct S { + chat_id: ChatId, + } + + assert_eq!(serde_json::to_string(&chat_id).unwrap(), json); + assert_eq!(chat_id, serde_json::from_str(json).unwrap()); + } + + #[test] + fn user_id_unmark() { + assert!(matches!( + ChatId(5298363099).unmark(), + UnmarkedChatId::User(UserId(5298363099)) + )); + } +} diff --git a/src/types/message.rs b/src/types/message.rs index b7d58e88..bc680e5f 100644 --- a/src/types/message.rs +++ b/src/types/message.rs @@ -4,8 +4,8 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use crate::types::{ - Animation, Audio, Chat, Contact, Dice, Document, Game, InlineKeyboardMarkup, Invoice, Location, - MessageAutoDeleteTimerChanged, MessageEntity, PassportData, PhotoSize, Poll, + Animation, Audio, Chat, ChatId, Contact, Dice, Document, Game, InlineKeyboardMarkup, Invoice, + Location, MessageAutoDeleteTimerChanged, MessageEntity, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, SuccessfulPayment, True, User, Venue, Video, VideoNote, Voice, VoiceChatEnded, VoiceChatParticipantsInvited, VoiceChatScheduled, VoiceChatStarted, }; @@ -187,14 +187,14 @@ pub enum ChatMigration { /// identifier `chat_id`. To { #[serde(rename = "migrate_to_chat_id")] - chat_id: i64, + chat_id: ChatId, }, /// The supergroup has been migrated from a group with the specified /// identifier `chat_id`. From { #[serde(rename = "migrate_from_chat_id")] - chat_id: i64, + chat_id: ChatId, }, } @@ -519,14 +519,15 @@ mod getters { use std::ops::Deref; use crate::types::{ - self, message::MessageKind::*, Chat, ChatMigration, Forward, ForwardedFrom, MediaAnimation, - MediaAudio, MediaContact, MediaDocument, MediaGame, MediaKind, MediaLocation, MediaPhoto, - MediaPoll, MediaSticker, MediaText, MediaVenue, MediaVideo, MediaVideoNote, MediaVoice, - Message, MessageChannelChatCreated, MessageCommon, MessageConnectedWebsite, - MessageDeleteChatPhoto, MessageDice, MessageEntity, MessageGroupChatCreated, - MessageInvoice, MessageLeftChatMember, MessageNewChatMembers, MessageNewChatPhoto, - MessageNewChatTitle, MessagePassportData, MessagePinned, MessageProximityAlertTriggered, - MessageSuccessfulPayment, MessageSupergroupChatCreated, PhotoSize, True, User, + self, message::MessageKind::*, Chat, ChatId, ChatMigration, Forward, ForwardedFrom, + MediaAnimation, MediaAudio, MediaContact, MediaDocument, MediaGame, MediaKind, + MediaLocation, MediaPhoto, MediaPoll, MediaSticker, MediaText, MediaVenue, MediaVideo, + MediaVideoNote, MediaVoice, Message, MessageChannelChatCreated, MessageCommon, + MessageConnectedWebsite, MessageDeleteChatPhoto, MessageDice, MessageEntity, + MessageGroupChatCreated, MessageInvoice, MessageLeftChatMember, MessageNewChatMembers, + MessageNewChatPhoto, MessageNewChatTitle, MessagePassportData, MessagePinned, + MessageProximityAlertTriggered, MessageSuccessfulPayment, MessageSupergroupChatCreated, + PhotoSize, True, User, }; /// Getters for [Message] fields from [telegram docs]. @@ -558,7 +559,7 @@ mod getters { } #[deprecated(since = "0.4.2", note = "use `.chat.id` field instead")] - pub fn chat_id(&self) -> i64 { + pub fn chat_id(&self) -> ChatId { self.chat.id } @@ -931,7 +932,7 @@ mod getters { } } - pub fn migrate_to_chat_id(&self) -> Option { + pub fn migrate_to_chat_id(&self) -> Option { match &self.kind { Common(MessageCommon { media_kind: MediaKind::Migration(ChatMigration::To { chat_id }), @@ -941,7 +942,7 @@ mod getters { } } - pub fn migrate_from_chat_id(&self) -> Option { + pub fn migrate_from_chat_id(&self) -> Option { match &self.kind { Common(MessageCommon { media_kind: MediaKind::Migration(ChatMigration::From { chat_id }), @@ -1069,7 +1070,8 @@ impl Message { // accessible to the group members. None => format!( "https://t.me/c/{0}/{1}/", - (-self.chat.id) - 1000000000000, + // FIXME: this may be wrong for private channels + (-self.chat.id.0) - 1000000000000, self.id ), }; @@ -1326,7 +1328,7 @@ mod tests { let message: Message = serde_json::from_str(json).unwrap(); let group = Chat { - id: -1001160242915, + id: ChatId(-1001160242915), kind: ChatKind::Public(ChatPublic { title: Some("a".to_owned()), kind: PublicChatKind::Supergroup(PublicChatSupergroup { @@ -1360,8 +1362,8 @@ mod tests { /// Regression test for #[test] fn issue_427() { - let old = -599075523; - let new = -1001555296434; + let old = ChatId(-599075523); + let new = ChatId(-1001555296434); // Migration to a supergroup let json = r#"{"chat":{"all_members_are_administrators":false,"id":-599075523,"title":"test","type":"group"},"date":1629404938,"from":{"first_name":"nullptr","id":729497414,"is_bot":false,"language_code":"en","username":"hex0x0000"},"message_id":16,"migrate_to_chat_id":-1001555296434}"#; diff --git a/src/types/recipient.rs b/src/types/recipient.rs index e1664448..dc719f62 100644 --- a/src/types/recipient.rs +++ b/src/types/recipient.rs @@ -1,6 +1,8 @@ use derive_more::{Display, From}; use serde::{Deserialize, Serialize}; +use crate::types::ChatId; + /// A unique identifier for the target chat or username of the target channel /// (in the format `@channelusername`). #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Display, From)] @@ -8,7 +10,7 @@ use serde::{Deserialize, Serialize}; pub enum Recipient { /// A chat identifier. #[display(fmt = "{}", _0)] - Id(i64), + Id(ChatId), /// A channel username (in the format @channelusername). #[display(fmt = "{}", _0)] @@ -16,39 +18,13 @@ pub enum Recipient { } impl Recipient { + #[allow(unused)] pub(crate) fn is_channel(&self) -> bool { - matches!(self.unmark(), None | Some(UnmarkedChatId::Channel(_))) + match self { + Recipient::Id(id) => id.is_channel(), + Recipient::ChannelUsername(_) => true, + } } - - pub(crate) fn unmark(&self) -> Option { - use UnmarkedChatId::*; - - // https://github.com/mtcute/mtcute/blob/6933ecc3f82dd2e9100f52b0afec128af564713b/packages/core/src/utils/peer-utils.ts#L4 - const MIN_MARKED_CHANNEL_ID: i64 = -1997852516352; - const MAX_MARKED_CHANNEL_ID: i64 = -1000000000000; - const MIN_MARKED_CHAT_ID: i64 = MAX_MARKED_CHANNEL_ID + 1; - const MAX_MARKED_CHAT_ID: i64 = MIN_USER_ID - 1; - const MIN_USER_ID: i64 = 0; - const MAX_USER_ID: i64 = (1 << 40) - 1; - - let res = match self { - &Self::Id(id @ MIN_MARKED_CHAT_ID..=MAX_MARKED_CHAT_ID) => Chat(-id as _), - &Self::Id(id @ MIN_MARKED_CHANNEL_ID..=MAX_MARKED_CHANNEL_ID) => { - Channel((MAX_MARKED_CHANNEL_ID - id) as _) - } - &Self::Id(id @ MIN_USER_ID..=MAX_USER_ID) => User(id as _), - &Self::Id(id) => panic!("malformed chat id: {}", id), - Self::ChannelUsername(_) => return None, - }; - - Some(res) - } -} - -pub(crate) enum UnmarkedChatId { - User(u64), - Chat(u64), - Channel(u64), } #[cfg(test)] @@ -58,7 +34,7 @@ mod tests { #[test] fn chat_id_id_serialization() { let expected_json = String::from(r#"123456"#); - let actual_json = serde_json::to_string(&Recipient::Id(123_456)).unwrap(); + let actual_json = serde_json::to_string(&Recipient::Id(ChatId(123_456))).unwrap(); assert_eq!(expected_json, actual_json) } @@ -71,12 +47,4 @@ mod tests { assert_eq!(expected_json, actual_json) } - - #[test] - fn user_id_unmark() { - assert!(matches!( - Recipient::Id(5298363099).unmark(), - Some(UnmarkedChatId::User(5298363099)) - )); - } } diff --git a/src/types/update.rs b/src/types/update.rs index 1b97031b..05a316e7 100644 --- a/src/types/update.rs +++ b/src/types/update.rs @@ -294,8 +294,8 @@ impl Serialize for UpdateKind { #[cfg(test)] mod test { use crate::types::{ - Chat, ChatKind, ChatPrivate, MediaKind, MediaText, Message, MessageCommon, MessageKind, - Update, UpdateKind, User, UserId, + Chat, ChatId, ChatKind, ChatPrivate, MediaKind, MediaText, Message, MessageCommon, + MessageKind, Update, UpdateKind, User, UserId, }; use chrono::{DateTime, NaiveDateTime, Utc}; @@ -335,7 +335,7 @@ mod test { id: 6557, date, chat: Chat { - id: 218_485_655, + id: ChatId(218_485_655), kind: ChatKind::Private(ChatPrivate { type_: (), username: Some(String::from("WaffleLapkin")), From 036c46caaa153abd3135e8868d30ddac37eca5ea Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 20:43:46 +0400 Subject: [PATCH 09/15] reformat code a bit --- rustfmt.toml | 1 + src/types/chat_id.rs | 8 ++++---- src/types/recipient.rs | 4 +++- src/types/user_id.rs | 8 ++++---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 9b0523d1..16746573 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -3,3 +3,4 @@ wrap_comments = true format_strings = true imports_granularity = "Crate" use_field_init_shorthand = true +merge_derives = false diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index d66c84f3..4d35840a 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -1,4 +1,3 @@ -use derive_more::Display; use serde::{Deserialize, Serialize}; use crate::types::UserId; @@ -6,9 +5,10 @@ use crate::types::UserId; /// Identifier of a chat. /// /// Note that "a chat" here means any of group, supergroup, channel or user PM. -#[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Serialize, Deserialize, -)] +#[derive(Clone, Copy)] +#[derive(Debug, derive_more::Display)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Serialize, Deserialize)] #[serde(transparent)] pub struct ChatId(pub i64); diff --git a/src/types/recipient.rs b/src/types/recipient.rs index dc719f62..36679686 100644 --- a/src/types/recipient.rs +++ b/src/types/recipient.rs @@ -5,7 +5,9 @@ use crate::types::ChatId; /// A unique identifier for the target chat or username of the target channel /// (in the format `@channelusername`). -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Display, From)] +#[derive(Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Display, From)] +#[derive(Serialize, Deserialize)] #[serde(untagged)] pub enum Recipient { /// A chat identifier. diff --git a/src/types/user_id.rs b/src/types/user_id.rs index 70211323..bfee58bf 100644 --- a/src/types/user_id.rs +++ b/src/types/user_id.rs @@ -1,10 +1,10 @@ -use derive_more::Display; use serde::{Deserialize, Serialize}; /// Identifier of a user. -#[derive( - Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Serialize, Deserialize, -)] +#[derive(Clone, Copy)] +#[derive(Debug, derive_more::Display)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Serialize, Deserialize)] #[serde(transparent)] pub struct UserId(pub u64); From 4fbec56674e5d93da4147c942bf170bf30754ec3 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 20:47:30 +0400 Subject: [PATCH 10/15] Impl `From` for `ChatId` and `Recipient` --- src/types/chat_id.rs | 6 ++++++ src/types/recipient.rs | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index 4d35840a..2e8a69c1 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -12,6 +12,12 @@ use crate::types::UserId; #[serde(transparent)] pub struct ChatId(pub i64); +impl From for ChatId { + fn from(UserId(id): UserId) -> Self { + Self(id as _) + } +} + impl ChatId { pub(crate) fn is_channel(self) -> bool { matches!(self.unmark(), UnmarkedChatId::Channel(_)) diff --git a/src/types/recipient.rs b/src/types/recipient.rs index 36679686..e7a29672 100644 --- a/src/types/recipient.rs +++ b/src/types/recipient.rs @@ -1,7 +1,7 @@ use derive_more::{Display, From}; use serde::{Deserialize, Serialize}; -use crate::types::ChatId; +use crate::types::{ChatId, UserId}; /// A unique identifier for the target chat or username of the target channel /// (in the format `@channelusername`). @@ -29,6 +29,12 @@ impl Recipient { } } +impl From for Recipient { + fn from(id: UserId) -> Self { + Self::Id(id.into()) + } +} + #[cfg(test)] mod tests { use super::*; From 71dee3b5635752e01ae300ddd7d33327952d562c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 24 Mar 2022 21:08:30 +0400 Subject: [PATCH 11/15] Use `Into` in methods --- src/bot/api.rs | 8 +++++--- src/local_macros.rs | 10 ++++++---- src/payloads/ban_chat_sender_chat.rs | 2 +- src/payloads/unban_chat_sender_chat.rs | 2 +- src/requests/requester.rs | 16 +++++++--------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/bot/api.rs b/src/bot/api.rs index 0fdb8a51..396c935d 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -401,9 +401,10 @@ impl Requester for Bot { type BanChatSenderChat = JsonRequest; - fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: ChatId) -> Self::BanChatSenderChat + fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: S) -> Self::BanChatSenderChat where C: Into, + S: Into, { Self::BanChatSenderChat::new( self.clone(), @@ -413,13 +414,14 @@ impl Requester for Bot { type UnbanChatSenderChat = JsonRequest; - fn unban_chat_sender_chat( + fn unban_chat_sender_chat( &self, chat_id: C, - sender_chat_id: ChatId, + sender_chat_id: S, ) -> Self::UnbanChatSenderChat where C: Into, + S: Into, { Self::UnbanChatSenderChat::new( self.clone(), diff --git a/src/local_macros.rs b/src/local_macros.rs index 43f26711..9971da25 100644 --- a/src/local_macros.rs +++ b/src/local_macros.rs @@ -724,17 +724,19 @@ macro_rules! requester_forward { (@method ban_chat_sender_chat $body:ident $ty:ident) => { type BanChatSenderChat = $ty![BanChatSenderChat]; - fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: ChatId) -> Self::BanChatSenderChat where C: Into { + fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: S) -> Self::BanChatSenderChat where C: Into, + S: Into { let this = self; - $body!(ban_chat_sender_chat this (chat_id: C, sender_chat_id: ChatId)) + $body!(ban_chat_sender_chat this (chat_id: C, sender_chat_id: S)) } }; (@method unban_chat_sender_chat $body:ident $ty:ident) => { type UnbanChatSenderChat = $ty![UnbanChatSenderChat]; - fn unban_chat_sender_chat(&self, chat_id: C, sender_chat_id: ChatId) -> Self::UnbanChatSenderChat where C: Into { + fn unban_chat_sender_chat(&self, chat_id: C, sender_chat_id: S) -> Self::UnbanChatSenderChat where C: Into, + S: Into { let this = self; - $body!(unban_chat_sender_chat this (chat_id: C, sender_chat_id: ChatId)) + $body!(unban_chat_sender_chat this (chat_id: C, sender_chat_id: S)) } }; (@method set_chat_permissions $body:ident $ty:ident) => { diff --git a/src/payloads/ban_chat_sender_chat.rs b/src/payloads/ban_chat_sender_chat.rs index dd1d43ef..2416fbd6 100644 --- a/src/payloads/ban_chat_sender_chat.rs +++ b/src/payloads/ban_chat_sender_chat.rs @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target sender chat - pub sender_chat_id: ChatId, + pub sender_chat_id: ChatId [into], } } } diff --git a/src/payloads/unban_chat_sender_chat.rs b/src/payloads/unban_chat_sender_chat.rs index b4ec78f2..54d4d4ea 100644 --- a/src/payloads/unban_chat_sender_chat.rs +++ b/src/payloads/unban_chat_sender_chat.rs @@ -18,7 +18,7 @@ impl_payload! { /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) pub chat_id: Recipient [into], /// Unique identifier of the target sender chat - pub sender_chat_id: ChatId, + pub sender_chat_id: ChatId [into], } } } diff --git a/src/requests/requester.rs b/src/requests/requester.rs index 1cde022e..282e5ba4 100644 --- a/src/requests/requester.rs +++ b/src/requests/requester.rs @@ -376,24 +376,22 @@ pub trait Requester { type BanChatSenderChat: Request; /// For Telegram documentation see [`BanChatSenderChat`]. - fn ban_chat_sender_chat( - &self, - chat_id: C, - sender_chat_id: ChatId, - ) -> Self::BanChatSenderChat + fn ban_chat_sender_chat(&self, chat_id: C, sender_chat_id: S) -> Self::BanChatSenderChat where - C: Into; + C: Into, + S: Into; type UnbanChatSenderChat: Request; /// For Telegram documentation see [`UnbanChatSenderChat`]. - fn unban_chat_sender_chat( + fn unban_chat_sender_chat( &self, chat_id: C, - sender_chat_id: ChatId, + sender_chat_id: S, ) -> Self::UnbanChatSenderChat where - C: Into; + C: Into, + S: Into; type SetChatPermissions: Request; From c2d2a15ef17657c50cdc1b870abf9ef6e1037555 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 2 Apr 2022 18:13:32 +0400 Subject: [PATCH 12/15] Split derives because rustfmt hates me --- src/types/reply_keyboard_remove.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/reply_keyboard_remove.rs b/src/types/reply_keyboard_remove.rs index 5acb6ccc..7e8490c7 100644 --- a/src/types/reply_keyboard_remove.rs +++ b/src/types/reply_keyboard_remove.rs @@ -13,7 +13,8 @@ use crate::types::True; /// /// [`KeyboardMarkup`]: crate::types::KeyboardMarkup #[serde_with_macros::skip_serializing_none] -#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Eq, Hash, PartialEq)] pub struct KeyboardRemove { /// Requests clients to remove the custom keyboard (user will not be able /// to summon this keyboard; if you want to hide the keyboard from sight From 380ebde98bb76514a1087891216f321e05759417 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 2 Apr 2022 18:26:18 +0400 Subject: [PATCH 13/15] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8c45682..a6408f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased +### Changed + +- `user.id` now uses `UserId` type, `ChatId` now represents only _chat id_, not channel username, all `chat_id` function parameters now accept `Recipient` [**BC**] + ## 0.4.4 - 2022-04-21 ### Added From ea7226795984cf035b02b0da73ff45f2ac63e34f Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 2 Apr 2022 18:28:38 +0400 Subject: [PATCH 14/15] restart CI From 9b3c0d88d23ecc9444341b130e06d8b57cc85bd1 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 2 Apr 2022 18:30:47 +0400 Subject: [PATCH 15/15] restart CI