From 181b30304f9ec2ff22359408801fe71ca5514114 Mon Sep 17 00:00:00 2001 From: Andrey Brusnik Date: Tue, 27 Aug 2024 02:10:11 +0400 Subject: [PATCH 01/38] Add dedicated `Rgb` struct to replace `[u8; 3]` --- Cargo.lock | 18 ++- crates/teloxide-core/CHANGELOG.md | 6 + crates/teloxide-core/Cargo.toml | 1 + crates/teloxide-core/schema.ron | 8 +- crates/teloxide-core/src/adaptors/erased.rs | 4 +- crates/teloxide-core/src/bot/api.rs | 4 +- crates/teloxide-core/src/local_macros.rs | 4 +- .../src/payloads/create_forum_topic.rs | 8 +- .../teloxide-core/src/requests/requester.rs | 2 +- crates/teloxide-core/src/types.rs | 66 +--------- crates/teloxide-core/src/types/forum_topic.rs | 8 +- .../src/types/forum_topic_created.rs | 10 +- crates/teloxide-core/src/types/rgb.rs | 113 ++++++++++++++++++ 13 files changed, 164 insertions(+), 88 deletions(-) create mode 100644 crates/teloxide-core/src/types/rgb.rs diff --git a/Cargo.lock b/Cargo.lock index 71d1bd4b..ff7098ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,6 +235,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "bytemuck" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" + [[package]] name = "byteorder" version = "1.5.0" @@ -1668,6 +1674,15 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "rgb" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f86ae463694029097b846d8f99fd5536740602ae00022c0c50c5600720b2f71" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.17.8" @@ -2302,6 +2317,7 @@ dependencies = [ "pretty_env_logger", "rc-box", "reqwest", + "rgb", "ron", "serde", "serde_json", @@ -2791,7 +2807,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index c3565652..7d3eb13d 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -49,6 +49,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - MSRV (Minimal Supported Rust Version) was bumped from `1.70.0` to `1.80.0` - Some dependencies was bumped: `reqwest` to `0.12.7` and `ron` to `0.8.1` - `tokio` version was explicitly specified as `1.39` and feature `io-util` was enabled for it +- `[u8; 3]` sometimes used for RGB values was replaced with dedicated `Rgb` struct: ([#1151][pr1151]) + - `serde_rgb` module from `types.rs` file was removed + - `CreateForumTopic`, `ForumTopicCreated` and `ForumTopic` structs now use `Rgb` instead of `[u8; 3]` for `icon_color` field + - Added `rgb` crate dependency to Cargo.toml + - Added `Rgb` struct with `From` implementation for `RGB8` type from popular `rgb` crate - Support for TBA 7.2 ([#1146](pr1146)) - Remove `flags` field from `StickerSet` struct @@ -60,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr1134]: https://github.com/teloxide/teloxide/pull/1134 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 [pr1147]: https://github.com/teloxide/teloxide/pull/1147 +[pr1151]: https://github.com/teloxide/teloxide/pull/1151 ### Removed diff --git a/crates/teloxide-core/Cargo.toml b/crates/teloxide-core/Cargo.toml index e3d1fdd3..6c30efef 100644 --- a/crates/teloxide-core/Cargo.toml +++ b/crates/teloxide-core/Cargo.toml @@ -76,6 +76,7 @@ rc-box = "1.1.1" chrono = { version = "0.4.32", default-features = false } either = "1.6.1" bitflags = { version = "1.2" } +rgb = "0.8.48" vecrem = { version = "0.1", optional = true } diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 540cc047..c1216ca7 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -2754,9 +2754,11 @@ Schema( ), Param( name: "icon_color", - // FIXME: use an Rgb or something - ty: u32, - descr: Doc(md: "Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)") + ty: RawTy("Rgb"), + descr: Doc( + md: "Color of the topic icon in RGB format. Currently, must be one of 7322096 (`0x6FB9F0`), 16766590 (`0xFFD67E`), 13338331 (`0xCB86DB`), 9367192 (`0x8EEE98`), 16749490 (`0xFF93B2`), or 16478047 (`0xFB6F5F`). To construct color from these values use [`Rgb::from_u32`]", + md_links: {"`Rgb::from_u32`": "crate::types::Rgb::from_u32"} + ) ), Param( name: "icon_custom_emoji_id", diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index e813300a..1e0728a4 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -671,7 +671,7 @@ trait ErasableRequester<'a> { &self, chat_id: Recipient, name: String, - icon_color: u32, + icon_color: Rgb, icon_custom_emoji_id: String, ) -> ErasedRequest<'a, CreateForumTopic, Self::Err>; @@ -1506,7 +1506,7 @@ where &self, chat_id: Recipient, name: String, - icon_color: u32, + icon_color: Rgb, icon_custom_emoji_id: String, ) -> ErasedRequest<'a, CreateForumTopic, Self::Err> { Requester::create_forum_topic(self, chat_id, name, icon_color, icon_custom_emoji_id).erase() diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 4305505c..7fed7fc5 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -6,7 +6,7 @@ use crate::{ requests::{JsonRequest, MultipartRequest}, types::{ BotCommand, BusinessConnectionId, ChatId, ChatPermissions, InlineQueryResult, InputFile, - InputMedia, InputSticker, LabeledPrice, MessageId, Recipient, StickerFormat, ThreadId, + InputMedia, InputSticker, LabeledPrice, MessageId, Recipient, Rgb, StickerFormat, ThreadId, UserId, }, Bot, @@ -686,7 +686,7 @@ impl Requester for Bot { &self, chat_id: C, name: N, - icon_color: u32, + icon_color: Rgb, icon_custom_emoji_id: I, ) -> Self::CreateForumTopic where diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index db71eea2..a6d2abbf 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -949,11 +949,11 @@ macro_rules! requester_forward { (@method create_forum_topic $body:ident $ty:ident) => { type CreateForumTopic = $ty![CreateForumTopic]; - fn create_forum_topic(&self, chat_id: C, name: N, icon_color: u32, icon_custom_emoji_id: I) -> Self::CreateForumTopic where C: Into, + fn create_forum_topic(&self, chat_id: C, name: N, icon_color: Rgb, icon_custom_emoji_id: I) -> Self::CreateForumTopic where C: Into, N: Into, I: Into { let this = self; - $body!(create_forum_topic this (chat_id: C, name: N, icon_color: u32, icon_custom_emoji_id: I)) + $body!(create_forum_topic this (chat_id: C, name: N, icon_color: Rgb, icon_custom_emoji_id: I)) } }; (@method edit_forum_topic $body:ident $ty:ident) => { diff --git a/crates/teloxide-core/src/payloads/create_forum_topic.rs b/crates/teloxide-core/src/payloads/create_forum_topic.rs index a1412fb3..ef9824f2 100644 --- a/crates/teloxide-core/src/payloads/create_forum_topic.rs +++ b/crates/teloxide-core/src/payloads/create_forum_topic.rs @@ -2,7 +2,7 @@ use serde::Serialize; -use crate::types::{ForumTopic, Recipient}; +use crate::types::{ForumTopic, Recipient, Rgb}; impl_payload! { /// Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the _can\_manage\_topics_ administrator rights. Returns information about the created topic as a `ForumTopic` object. @@ -13,8 +13,10 @@ impl_payload! { pub chat_id: Recipient [into], /// Topic name, 1-128 characters pub name: String [into], - /// Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) - pub icon_color: u32, + /// Color of the topic icon in RGB format. Currently, must be one of 7322096 (`0x6FB9F0`), 16766590 (`0xFFD67E`), 13338331 (`0xCB86DB`), 9367192 (`0x8EEE98`), 16749490 (`0xFF93B2`), or 16478047 (`0xFB6F5F`). To construct color from these values use [`Rgb::from_u32`] + /// + /// [`Rgb::from_u32`]: crate::types::Rgb::from_u32 + pub icon_color: Rgb, /// Unique identifier of the custom emoji shown as the topic icon. Use `getForumTopicIconStickers` to get all allowed custom emoji identifiers. pub icon_custom_emoji_id: String [into], } diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 7e34161a..a758f167 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -702,7 +702,7 @@ pub trait Requester { &self, chat_id: C, name: N, - icon_color: u32, + icon_color: Rgb, icon_custom_emoji_id: I, ) -> Self::CreateForumTopic where diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 36b73ac9..3d10253b 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -128,6 +128,7 @@ pub use reply_markup::*; pub use reply_parameters::*; pub use request_id::*; pub use response_parameters::*; +pub use rgb::*; pub use sent_web_app_message::*; pub use shared_user::*; pub use shipping_address::*; @@ -262,6 +263,7 @@ mod reply_markup; mod reply_parameters; mod request_id; mod response_parameters; +mod rgb; mod sent_web_app_message; mod shared_user; mod shipping_address; @@ -544,67 +546,3 @@ pub(crate) mod option_msg_id_as_int { } } } - -pub(crate) mod serde_rgb { - use serde::{de::Visitor, Deserializer, Serializer}; - - pub fn serialize(&this: &[u8; 3], s: S) -> Result { - s.serialize_u32(to_u32(this)) - } - - pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<[u8; 3], D::Error> { - struct V; - - impl Visitor<'_> for V { - type Value = [u8; 3]; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("an integer represeting an RGB color") - } - - fn visit_u32(self, v: u32) -> Result - where - E: serde::de::Error, - { - Ok(from_u32(v)) - } - - fn visit_u64(self, v: u64) -> Result - where - E: serde::de::Error, - { - self.visit_u32(v.try_into().map_err(|_| E::custom("rgb value doesn't fit u32"))?) - } - } - d.deserialize_u32(V) - } - - fn to_u32([r, g, b]: [u8; 3]) -> u32 { - u32::from_be_bytes([0, r, g, b]) - } - - fn from_u32(rgb: u32) -> [u8; 3] { - let [_, r, g, b] = rgb.to_be_bytes(); - [r, g, b] - } - - #[test] - fn bytes() { - assert_eq!(to_u32([0xAA, 0xBB, 0xCC]), 0x00AABBCC); - assert_eq!(from_u32(0x00AABBCC), [0xAA, 0xBB, 0xCC]); - } - - #[test] - fn json() { - #[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] - struct Struct { - #[serde(with = "self")] - color: [u8; 3], - } - - let json = format!(r#"{{"color":{}}}"#, 0x00AABBCC); - let Struct { color } = serde_json::from_str(&json).unwrap(); - - assert_eq!(color, [0xAA, 0xBB, 0xCC]) - } -} diff --git a/crates/teloxide-core/src/types/forum_topic.rs b/crates/teloxide-core/src/types/forum_topic.rs index 1eae5e8e..50228823 100644 --- a/crates/teloxide-core/src/types/forum_topic.rs +++ b/crates/teloxide-core/src/types/forum_topic.rs @@ -1,7 +1,7 @@ -use crate::types::ThreadId; - use serde::{Deserialize, Serialize}; +use crate::types::{Rgb, ThreadId}; + /// This object represents a forum topic. /// /// [The official docs](https://core.telegram.org/bots/api#forumtopiccreated). @@ -16,9 +16,7 @@ pub struct ForumTopic { pub name: String, /// Color of the topic icon in RGB format. - // FIXME: use/add a specialized rgb color type? - #[serde(with = "crate::types::serde_rgb")] - pub icon_color: [u8; 3], + pub icon_color: Rgb, /// Unique identifier of the custom emoji shown as the topic icon. // FIXME: CustomEmojiId diff --git a/crates/teloxide-core/src/types/forum_topic_created.rs b/crates/teloxide-core/src/types/forum_topic_created.rs index b7f04344..02662649 100644 --- a/crates/teloxide-core/src/types/forum_topic_created.rs +++ b/crates/teloxide-core/src/types/forum_topic_created.rs @@ -1,5 +1,7 @@ use serde::{Deserialize, Serialize}; +use crate::types::Rgb; + /// This object represents a service message about a new forum topic created in /// the chat. /// @@ -11,9 +13,7 @@ pub struct ForumTopicCreated { pub name: String, /// Color of the topic icon in RGB format. - // FIXME: use/add a specialized rgb color type? - #[serde(with = "crate::types::serde_rgb")] - pub icon_color: [u8; 3], + pub icon_color: Rgb, /// Unique identifier of the custom emoji shown as the topic icon. // FIXME: CustomEmojiId @@ -22,7 +22,7 @@ pub struct ForumTopicCreated { #[cfg(test)] mod tests { - use crate::types::ForumTopicCreated; + use super::*; #[test] fn deserialization() { @@ -32,7 +32,7 @@ mod tests { let event = serde_json::from_str::(json).unwrap(); assert_eq!(event.name, "???"); - assert_eq!(event.icon_color, [0x8E, 0xEE, 0x98]); + assert_eq!(event.icon_color, Rgb { r: 0x8E, g: 0xEE, b: 0x98 }); assert_eq!(event.icon_custom_emoji_id.as_deref(), Some("5312536423851630001")); } } diff --git a/crates/teloxide-core/src/types/rgb.rs b/crates/teloxide-core/src/types/rgb.rs new file mode 100644 index 00000000..22b4b568 --- /dev/null +++ b/crates/teloxide-core/src/types/rgb.rs @@ -0,0 +1,113 @@ +use rgb::RGB8; +use serde::{de::Visitor, Deserialize, Serialize}; + +/// RGB color format +#[repr(C)] +#[derive(Clone, Copy, Debug)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Rgb { + pub r: u8, + pub g: u8, + pub b: u8, +} + +impl Rgb { + /// Convert a [`Rgb`] struct into a big endian `u32` representing the RGB + /// color. + /// + /// # Example + /// + /// ``` + /// use teloxide_core::types::Rgb; + /// assert_eq!(Rgb { r: 0xAA, g: 0xBB, b: 0xCC }.to_u32(), 0xAABBCC); + /// ``` + /// + /// [`Rgb`]: Rgb + pub fn to_u32(self) -> u32 { + u32::from_be_bytes([0, self.r, self.g, self.b]) + } + + /// Convert a big endian `u32` representing the RGB color into a [`Rgb`] + /// struct. + /// + /// # Example + /// + /// ``` + /// use teloxide_core::types::Rgb; + /// assert_eq!(Rgb::from_u32(0xAABBCC), Rgb { r: 0xAA, g: 0xBB, b: 0xCC }); + /// ``` + /// + /// [`Rgb`]: Rgb + pub fn from_u32(rgb: u32) -> Self { + let [_, r, g, b] = rgb.to_be_bytes(); + Rgb { r, g, b } + } +} + +impl Serialize for Rgb { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_u32(self.to_u32()) + } +} + +impl<'de> Deserialize<'de> for Rgb { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct V; + + impl Visitor<'_> for V { + type Value = Rgb; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("an integer represeting an RGB color") + } + + fn visit_u32(self, v: u32) -> Result + where + E: serde::de::Error, + { + Ok(Self::Value::from_u32(v)) + } + + fn visit_u64(self, v: u64) -> Result + where + E: serde::de::Error, + { + self.visit_u32(v.try_into().map_err(|_| E::custom("rgb value doesn't fit u32"))?) + } + } + + deserializer.deserialize_u32(V) + } +} + +impl From for Rgb { + fn from(color: RGB8) -> Self { + Rgb { r: color.r, g: color.g, b: color.b } + } +} + +#[cfg(test)] +mod tests { + use serde::{Deserialize, Serialize}; + + use super::*; + + #[test] + fn json() { + #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] + struct Struct { + color: Rgb, + } + + let json = format!(r#"{{"color":{}}}"#, 0x00AABBCC); + let Struct { color } = serde_json::from_str(&json).unwrap(); + + assert_eq!(color, Rgb { r: 0xAA, g: 0xBB, b: 0xCC }) + } +} From 3977b79b90a6a5e7a0670a2b3988a42d81117498 Mon Sep 17 00:00:00 2001 From: Johannes Dertmann Date: Thu, 29 Aug 2024 00:17:37 +0200 Subject: [PATCH 02/38] Add BotKickedFromChannel variant to ApiError --- crates/teloxide-core/CHANGELOG.md | 2 ++ crates/teloxide-core/src/errors.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 7d3eb13d..906527cd 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -42,6 +42,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `BusinessMessagesDeleted` struct - Add `BusinessConnection`, `BusinessMessage`, `EditedBusinessMessage` and `DeletedBusinessMessages` variants to `UpdateKind` enum +- `ApiError::BotKickedFromChannel` + ### Changed - `MaybeAnonymousUser` type introduced, which replaced `PollAnswer::voter: Voter` and `MessageReactionUpdated::{user, actor_chat}` in `MessageReactionUpdated`([#1134][pr1134]) diff --git a/crates/teloxide-core/src/errors.rs b/crates/teloxide-core/src/errors.rs index fc0d707b..d8e6b611 100644 --- a/crates/teloxide-core/src/errors.rs +++ b/crates/teloxide-core/src/errors.rs @@ -644,6 +644,15 @@ impl_api_error! { /// [`SendMessage`]: crate::payloads::SendMessage BotKickedFromSupergroup = "Forbidden: bot was kicked from the supergroup chat", + /// Occurs when bot tries to do something in a channel the bot was + /// kicked from. + /// + /// May happen in methods: + /// 1. [`SendMessage`] + /// + /// [`SendMessage`]: crate::payloads::SendMessage + BotKickedFromChannel = "Forbidden: bot was kicked from the channel chat", + /// Occurs when bot tries to send a message to a deactivated user (i.e. a /// user that was banned by telegram). /// From 55141db2acdb99711eed2c78875313b75ac01066 Mon Sep 17 00:00:00 2001 From: Tima Kinsart Date: Wed, 28 Aug 2024 21:52:19 -0400 Subject: [PATCH 03/38] Link PR #1157 in the changelog --- crates/teloxide-core/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 906527cd..9a856377 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -42,7 +42,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `BusinessMessagesDeleted` struct - Add `BusinessConnection`, `BusinessMessage`, `EditedBusinessMessage` and `DeletedBusinessMessages` variants to `UpdateKind` enum -- `ApiError::BotKickedFromChannel` +- `ApiError::BotKickedFromChannel` ([#1157][pr1157]) + +[pr1157]: https://github.com/teloxide/teloxide/pull/1157 ### Changed From 431d67d535ba076acc187e5703589b746d064ec8 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 05:03:41 +0300 Subject: [PATCH 04/38] Added bot message sugar --- CHANGELOG.md | 1 + crates/teloxide-core/src/types/message.rs | 10 + crates/teloxide/src/lib.rs | 1 + crates/teloxide/src/sugar.rs | 3 + crates/teloxide/src/sugar/bot.rs | 244 ++++++++++++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 crates/teloxide/src/sugar.rs create mode 100644 crates/teloxide/src/sugar/bot.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index ac09cb91..b38ea06b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `filter_boost_added` and `filter_reply_to_story` filters to `MessageFilterExt` trait - Add `filter_mention_command` filter to `HandlerExt` trait ([issue #494](https://github.com/teloxide/teloxide/issues/494)) - Add `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to update filters ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) +- Add `bot.forward`, `bot.copy` and `bot.delete` to new `crate::sugar::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) ### Changed diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 2b2ce6e2..93411078 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1816,6 +1816,16 @@ impl Message { } } +/// Implemented for syntax sugar, see issue +impl IntoIterator for Message { + type Item = Message; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + vec![self].into_iter() + } +} + #[cfg(test)] mod tests { use chrono::DateTime; diff --git a/crates/teloxide/src/lib.rs b/crates/teloxide/src/lib.rs index bcb901f1..edab596d 100644 --- a/crates/teloxide/src/lib.rs +++ b/crates/teloxide/src/lib.rs @@ -140,6 +140,7 @@ pub mod prelude; #[cfg(feature = "ctrlc_handler")] pub mod repls; pub mod stop; +pub mod sugar; pub mod update_listeners; pub mod utils; diff --git a/crates/teloxide/src/sugar.rs b/crates/teloxide/src/sugar.rs new file mode 100644 index 00000000..6bb10ad8 --- /dev/null +++ b/crates/teloxide/src/sugar.rs @@ -0,0 +1,3 @@ +//! Some non-detrimental, but nice additions + +pub mod bot; diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs new file mode 100644 index 00000000..1d69380d --- /dev/null +++ b/crates/teloxide/src/sugar/bot.rs @@ -0,0 +1,244 @@ +//! Additions to [`Bot`]. +//! +//! [`Bot`]: crate::Bot +use crate::{prelude::*, types::*}; +use std::collections::HashSet; + +pub trait BotMessagesExt { + /// This function is the same as [`Bot::forward_messages`], + /// but can take in [`Message`], including just one. + /// + /// [`Bot::forward_messages`]: crate::Bot::forward_messages + /// [`Message`]: crate::types::Message + fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + where + C: Into, + M: IntoIterator; + + /// This function is the same as [`Bot::copy_messages`], + /// but can take in [`Message`], including just one. + /// + /// [`Bot::copy_messages`]: crate::Bot::copy_messages + /// [`Message`]: crate::types::Message + fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + where + C: Into, + M: IntoIterator; + + /// This function is the same as [`Bot::delete_messages`], + /// but can take in [`Message`], including just one. + /// + /// [`Bot::delete_messages`]: crate::Bot::delete_messages + /// [`Message`]: crate::types::Message + fn delete(&self, messages: M) -> ::DeleteMessages + where + M: IntoIterator; +} + +fn compress_chat_messages(messages: M) -> (ChatId, Vec) +where + M: IntoIterator, +{ + let (message_ids, unique_chat_ids): (Vec, HashSet) = + messages.into_iter().map(|m| (m.id, m.chat.id)).unzip(); + + if unique_chat_ids.is_empty() { + panic!("There needs to be at least one message!"); + } else if unique_chat_ids.len() > 1 { + panic!( + "Messages shouldn't come from different chats! Current chat ids: {:?}", + unique_chat_ids.into_iter().map(|c| c.0).collect::>() + ); + } + + // Unwrap: length is checked to be non-zero before + let chat_id = unique_chat_ids.into_iter().next().unwrap(); + + (chat_id, message_ids) +} + +impl BotMessagesExt for Bot { + fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + where + C: Into, + M: IntoIterator, + { + let (from_chat_id, message_ids) = compress_chat_messages(messages); + self.forward_messages(to_chat_id, from_chat_id, message_ids) + } + + fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + where + C: Into, + M: IntoIterator, + { + let (from_chat_id, message_ids) = compress_chat_messages(messages); + self.copy_messages(to_chat_id, from_chat_id, message_ids) + } + + fn delete(&self, messages: M) -> ::DeleteMessages + where + M: IntoIterator, + { + let (chat_id, message_ids) = compress_chat_messages(messages); + self.delete_messages(chat_id, message_ids) + } +} + +#[cfg(test)] +mod tests { + use std::ops::Deref; + + use chrono::DateTime; + + use super::*; + + fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { + let timestamp = 1_569_518_829; + let date = DateTime::from_timestamp(timestamp, 0).unwrap(); + Message { + via_bot: None, + id: message_id, + thread_id: None, + from: Some(User { + id: UserId(109_998_024), + is_bot: false, + first_name: String::from("Laster"), + last_name: None, + username: Some(String::from("laster_alex")), + language_code: Some(String::from("en")), + is_premium: false, + added_to_attachment_menu: false, + }), + sender_chat: None, + is_topic_message: false, + sender_business_bot: None, + date, + chat: Chat { + id: chat_id, + kind: ChatKind::Private(ChatPrivate { + username: Some(String::from("Laster")), + first_name: Some(String::from("laster_alex")), + last_name: None, + bio: None, + has_private_forwards: None, + has_restricted_voice_and_video_messages: None, + business_intro: None, + business_location: None, + business_opening_hours: None, + birthdate: None, + personal_chat: None, + }), + photo: None, + available_reactions: None, + pinned_message: None, + message_auto_delete_time: None, + has_hidden_members: false, + has_aggressive_anti_spam_enabled: false, + chat_full_info: ChatFullInfo::default(), + }, + kind: MessageKind::Common(MessageCommon { + reply_to_message: None, + forward_origin: None, + external_reply: None, + quote: None, + edit_date: None, + media_kind: MediaKind::Text(MediaText { + text: "text".to_owned(), + entities: vec![], + link_preview_options: None, + }), + reply_markup: None, + author_signature: None, + is_automatic_forward: false, + has_protected_content: false, + reply_to_story: None, + sender_boost_count: None, + is_from_offline: false, + business_connection_id: None, + }), + } + } + + #[test] + fn test_forward() { + let bot = Bot::new("TOKEN"); + + let to_chat_id = ChatId(12345); + let from_chat_id = ChatId(6789); + let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + + let sugar_forward_req = bot.forward( + to_chat_id, + vec![ + make_message(from_chat_id, message_ids[0]), + make_message(from_chat_id, message_ids[1]), + make_message(from_chat_id, message_ids[2]), + ], + ); + let real_forward_req = bot.forward_messages(to_chat_id, from_chat_id, message_ids); + + assert_eq!(sugar_forward_req.deref(), real_forward_req.deref()) + } + + #[test] + fn test_copy() { + let bot = Bot::new("TOKEN"); + + let to_chat_id = ChatId(12345); + let from_chat_id = ChatId(6789); + let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + + let sugar_copy_req = bot.copy( + to_chat_id, + vec![ + make_message(from_chat_id, message_ids[0]), + make_message(from_chat_id, message_ids[1]), + make_message(from_chat_id, message_ids[2]), + ], + ); + let real_copy_req = bot.copy_messages(to_chat_id, from_chat_id, message_ids); + + assert_eq!(sugar_copy_req.deref(), real_copy_req.deref()) + } + + #[test] + fn test_delete() { + let bot = Bot::new("TOKEN"); + + let chat_id = ChatId(6789); + let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + + let sugar_delete_req = bot.delete(vec![ + make_message(chat_id, message_ids[0]), + make_message(chat_id, message_ids[1]), + make_message(chat_id, message_ids[2]), + ]); + let real_delete_req = bot.delete_messages(chat_id, message_ids); + + assert_eq!(sugar_delete_req.deref(), real_delete_req.deref()) + } + + #[test] + #[should_panic] + fn test_forward_many_chats() { + // They all use the same validation, only one check is enough + let bot = Bot::new("TOKEN"); + + let _ = bot.forward( + ChatId(12345), + vec![ + make_message(ChatId(6789), MessageId(100)), + make_message(ChatId(6789), MessageId(101)), + make_message(ChatId(9012), MessageId(102)), + ], + ); + } + + #[test] + fn message_to_iterator() { + // Just to make sure one message still can be passed in + let message = make_message(ChatId(1), MessageId(1)); + assert_eq!(message.clone().into_iter().next(), Some(message)); + } +} From 19ae8dd7a9b616d3d19e7abada5148be0f6ff36a Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 06:17:44 +0300 Subject: [PATCH 05/38] Added simple json request sugar --- crates/teloxide/src/sugar.rs | 1 + crates/teloxide/src/sugar/request.rs | 51 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 crates/teloxide/src/sugar/request.rs diff --git a/crates/teloxide/src/sugar.rs b/crates/teloxide/src/sugar.rs index 6bb10ad8..b6f23cc0 100644 --- a/crates/teloxide/src/sugar.rs +++ b/crates/teloxide/src/sugar.rs @@ -1,3 +1,4 @@ //! Some non-detrimental, but nice additions pub mod bot; +pub mod request; diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs new file mode 100644 index 00000000..a3b82091 --- /dev/null +++ b/crates/teloxide/src/sugar/request.rs @@ -0,0 +1,51 @@ +//! Additions to [`JsonRequest`]. +//! +//! [`JsonRequest`]: teloxide_core::requests::JsonRequest + +use teloxide_core::{payloads::*, prelude::Requester, types::*, Bot}; + +macro_rules! impl_request_reply_ext { + ($($t:ty),*) => { + $( + impl RequestReplyExt for $t { + fn reply_to(self, message_id: M) -> Self + where + M: Into, + Self: teloxide_core::requests::HasPayload + Sized, + { + self.reply_parameters(ReplyParameters::new(message_id.into())) + } + } + )* + }; +} + +pub trait RequestReplyExt { + fn reply_to(self, message_id: M) -> Self + where + M: Into, + Self: Sized; +} + +impl_request_reply_ext! { + ::SendMessage +} + +#[cfg(test)] +mod tests { + use std::ops::Deref; + + use super::*; + use teloxide_core::{prelude::Requester, Bot}; + + #[test] + fn test_reply_to() { + let bot = Bot::new("TOKEN"); + let real_reply_req = bot + .send_message(ChatId(1234), "test") + .reply_parameters(ReplyParameters::new(MessageId(1))); + let sugar_reply_req = bot.send_message(ChatId(1234), "test").reply_to(MessageId(1)); + + assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) + } +} From cc0f2a73a8e412ac22084cd74ab57860e4e61689 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 06:28:39 +0300 Subject: [PATCH 06/38] Added link preview sugar --- crates/teloxide/src/sugar/request.rs | 51 +++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs index a3b82091..dc31ae50 100644 --- a/crates/teloxide/src/sugar/request.rs +++ b/crates/teloxide/src/sugar/request.rs @@ -11,7 +11,7 @@ macro_rules! impl_request_reply_ext { fn reply_to(self, message_id: M) -> Self where M: Into, - Self: teloxide_core::requests::HasPayload + Sized, + Self: Sized, { self.reply_parameters(ReplyParameters::new(message_id.into())) } @@ -20,6 +20,28 @@ macro_rules! impl_request_reply_ext { }; } +macro_rules! impl_request_link_preview_ext { + ($($t:ty),*) => { + $( + impl RequestLinkPreviewExt for $t { + fn disable_link_preview(self) -> Self + where + Self: Sized + { + let link_preview_options = LinkPreviewOptions { + is_disabled: true, + url: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, + }; + self.link_preview_options(link_preview_options) + } + } + )* + }; +} + pub trait RequestReplyExt { fn reply_to(self, message_id: M) -> Self where @@ -27,10 +49,20 @@ pub trait RequestReplyExt { Self: Sized; } +pub trait RequestLinkPreviewExt { + fn disable_link_preview(self) -> Self + where + Self: Sized; +} + impl_request_reply_ext! { ::SendMessage } +impl_request_link_preview_ext! { + ::SendMessage +} + #[cfg(test)] mod tests { use std::ops::Deref; @@ -48,4 +80,21 @@ mod tests { assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) } + + #[test] + fn test_disable_link_preview() { + let link_preview_options = LinkPreviewOptions { + is_disabled: true, + url: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, + }; + let bot = Bot::new("TOKEN"); + let real_link_req = + bot.send_message(ChatId(1234), "test").link_preview_options(link_preview_options); + let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(); + + assert_eq!(real_link_req.deref(), sugar_link_req.deref()) + } } From fc7abb70d58b60f55215a64a9b6ed2a98f4c4d22 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:05:49 +0300 Subject: [PATCH 07/38] More types + some fixes --- crates/teloxide-core/src/types/message.rs | 8 +++ crates/teloxide/src/sugar/bot.rs | 28 ++++++--- crates/teloxide/src/sugar/request.rs | 71 ++++++++++++++++++++--- 3 files changed, 91 insertions(+), 16 deletions(-) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 93411078..36fec591 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1826,6 +1826,14 @@ impl IntoIterator for Message { } } +/// Implemented for syntax sugar, see issue +#[allow(clippy::from_over_into)] +impl Into for Message { + fn into(self) -> MessageId { + self.id + } +} + #[cfg(test)] mod tests { use chrono::DateTime; diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index 1d69380d..4c8781a2 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -2,15 +2,19 @@ //! //! [`Bot`]: crate::Bot use crate::{prelude::*, types::*}; +use teloxide_core::{payloads::*, requests::JsonRequest}; use std::collections::HashSet; +/// Adds useful manipulations with [`Message`] structs +/// +/// [`Message`]: crate::types::Message pub trait BotMessagesExt { /// This function is the same as [`Bot::forward_messages`], /// but can take in [`Message`], including just one. /// /// [`Bot::forward_messages`]: crate::Bot::forward_messages /// [`Message`]: crate::types::Message - fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + fn forward(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator; @@ -20,7 +24,7 @@ pub trait BotMessagesExt { /// /// [`Bot::copy_messages`]: crate::Bot::copy_messages /// [`Message`]: crate::types::Message - fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + fn copy(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator; @@ -30,7 +34,7 @@ pub trait BotMessagesExt { /// /// [`Bot::delete_messages`]: crate::Bot::delete_messages /// [`Message`]: crate::types::Message - fn delete(&self, messages: M) -> ::DeleteMessages + fn delete(&self, messages: M) -> JsonRequest where M: IntoIterator; } @@ -58,7 +62,7 @@ where } impl BotMessagesExt for Bot { - fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + fn forward(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator, @@ -67,7 +71,7 @@ impl BotMessagesExt for Bot { self.forward_messages(to_chat_id, from_chat_id, message_ids) } - fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + fn copy(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator, @@ -76,7 +80,7 @@ impl BotMessagesExt for Bot { self.copy_messages(to_chat_id, from_chat_id, message_ids) } - fn delete(&self, messages: M) -> ::DeleteMessages + fn delete(&self, messages: M) -> JsonRequest where M: IntoIterator, { @@ -86,14 +90,14 @@ impl BotMessagesExt for Bot { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use std::ops::Deref; use chrono::DateTime; use super::*; - fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { + pub(crate) fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { let timestamp = 1_569_518_829; let date = DateTime::from_timestamp(timestamp, 0).unwrap(); Message { @@ -241,4 +245,12 @@ mod tests { let message = make_message(ChatId(1), MessageId(1)); assert_eq!(message.clone().into_iter().next(), Some(message)); } + + #[test] + fn message_to_message_id() { + // Just to make sure message still can be in Into + let message = make_message(ChatId(1), MessageId(1)); + let message_id: MessageId = message.into(); + assert_eq!(message_id, MessageId(1)); + } } diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs index dc31ae50..6c2d4f3d 100644 --- a/crates/teloxide/src/sugar/request.rs +++ b/crates/teloxide/src/sugar/request.rs @@ -1,8 +1,13 @@ -//! Additions to [`JsonRequest`]. +//! Additions to [`JsonRequest`] and [`MultipartRequest`]. //! //! [`JsonRequest`]: teloxide_core::requests::JsonRequest +//! [`MultipartRequest`]: teloxide_core::requests::MultipartRequest -use teloxide_core::{payloads::*, prelude::Requester, types::*, Bot}; +use teloxide_core::{ + payloads::*, + requests::{JsonRequest, MultipartRequest}, + types::*, +}; macro_rules! impl_request_reply_ext { ($($t:ty),*) => { @@ -24,12 +29,12 @@ macro_rules! impl_request_link_preview_ext { ($($t:ty),*) => { $( impl RequestLinkPreviewExt for $t { - fn disable_link_preview(self) -> Self + fn disable_link_preview(self, is_disabled: bool) -> Self where Self: Sized { let link_preview_options = LinkPreviewOptions { - is_disabled: true, + is_disabled, url: None, prefer_small_media: false, prefer_large_media: false, @@ -42,25 +47,57 @@ macro_rules! impl_request_link_preview_ext { }; } +/// Adds `.reply_to(message_id)` to requests pub trait RequestReplyExt { + /// Replaces `.reply_parameters(ReplyParameters::new(msg.id))` + /// with `.reply_to(msg.id)` or `.reply_to(msg)` fn reply_to(self, message_id: M) -> Self where M: Into, Self: Sized; } +/// Adds `.disable_link_preview(is_disabled)` to requests pub trait RequestLinkPreviewExt { - fn disable_link_preview(self) -> Self + /// Replaces + /// `.link_preview_options(LinkPreviewOptions { + /// is_disabled: true, + /// url: None, + /// prefer_small_media: false, + /// prefer_large_media: false, + /// show_above_text: false + /// };)` + /// + /// With `.disable_link_preview(true)` + fn disable_link_preview(self, is_disabled: bool) -> Self where Self: Sized; } impl_request_reply_ext! { - ::SendMessage + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest } impl_request_link_preview_ext! { - ::SendMessage + JsonRequest, + JsonRequest } #[cfg(test)] @@ -73,6 +110,7 @@ mod tests { #[test] fn test_reply_to() { let bot = Bot::new("TOKEN"); + let real_reply_req = bot .send_message(ChatId(1234), "test") .reply_parameters(ReplyParameters::new(MessageId(1))); @@ -81,6 +119,22 @@ mod tests { assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) } + #[test] + fn test_reply_to_multipart() { + let bot = Bot::new("TOKEN"); + let document = InputFile::memory("hello world!"); + + let real_reply_req = bot + .send_document(ChatId(1234), document.clone()) + .reply_parameters(ReplyParameters::new(MessageId(1))); + let sugar_reply_req = bot.send_document(ChatId(1234), document).reply_to(MessageId(1)); + + assert_eq!( + real_reply_req.deref().reply_parameters, + sugar_reply_req.deref().reply_parameters + ) + } + #[test] fn test_disable_link_preview() { let link_preview_options = LinkPreviewOptions { @@ -91,9 +145,10 @@ mod tests { show_above_text: false, }; let bot = Bot::new("TOKEN"); + let real_link_req = bot.send_message(ChatId(1234), "test").link_preview_options(link_preview_options); - let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(); + let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(true); assert_eq!(real_link_req.deref(), sugar_link_req.deref()) } From a52fe8eeb59294f571ac45e94232c8213a38eb52 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:10:25 +0300 Subject: [PATCH 08/38] Fixed Vec serialization --- crates/teloxide-core/src/payloads/codegen.rs | 5 +++ .../src/payloads/copy_messages.rs | 1 + .../src/payloads/delete_messages.rs | 1 + .../src/payloads/forward_messages.rs | 1 + crates/teloxide-core/src/types.rs | 32 +++++++++++++++++++ 5 files changed, 40 insertions(+) diff --git a/crates/teloxide-core/src/payloads/codegen.rs b/crates/teloxide-core/src/payloads/codegen.rs index f3503a1b..03bb9957 100644 --- a/crates/teloxide-core/src/payloads/codegen.rs +++ b/crates/teloxide-core/src/payloads/codegen.rs @@ -223,6 +223,11 @@ fn params(params: impl Iterator>) -> String { { "\n #[serde(flatten)]" } + Type::ArrayOf(b) if **b == Type::RawTy("MessageId".to_string()) => + { + "\n #[serde(with = \ + \"crate::types::vec_msg_id_as_vec_int\")]" + } _ => "", }; let with = match ty { diff --git a/crates/teloxide-core/src/payloads/copy_messages.rs b/crates/teloxide-core/src/payloads/copy_messages.rs index 90a4cd90..87b6c915 100644 --- a/crates/teloxide-core/src/payloads/copy_messages.rs +++ b/crates/teloxide-core/src/payloads/copy_messages.rs @@ -17,6 +17,7 @@ impl_payload! { /// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) pub from_chat_id: Recipient [into], /// Identifiers of 1-100 messages in the chat _from\_chat\_id_ to copy. The identifiers must be specified in a strictly increasing order. + #[serde(with = "crate::types::vec_msg_id_as_vec_int")] pub message_ids: Vec [collect], } optional { diff --git a/crates/teloxide-core/src/payloads/delete_messages.rs b/crates/teloxide-core/src/payloads/delete_messages.rs index f8306c03..e28e04ae 100644 --- a/crates/teloxide-core/src/payloads/delete_messages.rs +++ b/crates/teloxide-core/src/payloads/delete_messages.rs @@ -14,6 +14,7 @@ impl_payload! { /// Identifiers of 1-100 messages to delete. See [`DeleteMessage`] for limitations on which messages can be deleted /// /// [`DeleteMessage`]: crate::payloads::DeleteMessage + #[serde(with = "crate::types::vec_msg_id_as_vec_int")] pub message_ids: Vec [collect], } } diff --git a/crates/teloxide-core/src/payloads/forward_messages.rs b/crates/teloxide-core/src/payloads/forward_messages.rs index e191725b..e0ff6a23 100644 --- a/crates/teloxide-core/src/payloads/forward_messages.rs +++ b/crates/teloxide-core/src/payloads/forward_messages.rs @@ -16,6 +16,7 @@ impl_payload! { /// Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) pub from_chat_id: Recipient [into], /// A JSON-serialized list of 1-100 identifiers of messages in the chat _from\_chat\_id_ to forward. The identifiers must be specified in a strictly increasing order. + #[serde(with = "crate::types::vec_msg_id_as_vec_int")] pub message_ids: Vec [collect], } optional { diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 3d10253b..465869d6 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -546,3 +546,35 @@ pub(crate) mod option_msg_id_as_int { } } } + +pub(crate) mod vec_msg_id_as_vec_int { + use crate::types::MessageId; + + use serde::{ser::SerializeSeq, Serializer}; + + pub(crate) fn serialize(msg_ids: &Vec, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(msg_ids.len()))?; + for e in msg_ids { + seq.serialize_element(&e.0)?; + } + seq.end() + } + + #[test] + fn test() { + #[derive(serde::Serialize)] + struct Struct { + #[serde(with = "crate::types::vec_msg_id_as_vec_int")] + msg_ids: Vec, + } + + { + let s = Struct {msg_ids: vec![MessageId(1), MessageId(2)]}; + let json = serde_json::to_string(&s).unwrap(); + assert_eq!(json, "{\"msg_ids\":[1,2]}"); + } + } +} From 83f5508495dd27ba25ed21d7b667c7a0d6035bd0 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:15:28 +0300 Subject: [PATCH 09/38] Cargo fmt --- crates/teloxide-core/src/payloads/codegen.rs | 6 ++---- crates/teloxide-core/src/types.rs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/teloxide-core/src/payloads/codegen.rs b/crates/teloxide-core/src/payloads/codegen.rs index 03bb9957..f4660b2f 100644 --- a/crates/teloxide-core/src/payloads/codegen.rs +++ b/crates/teloxide-core/src/payloads/codegen.rs @@ -223,10 +223,8 @@ fn params(params: impl Iterator>) -> String { { "\n #[serde(flatten)]" } - Type::ArrayOf(b) if **b == Type::RawTy("MessageId".to_string()) => - { - "\n #[serde(with = \ - \"crate::types::vec_msg_id_as_vec_int\")]" + Type::ArrayOf(b) if **b == Type::RawTy("MessageId".to_string()) => { + "\n #[serde(with = \"crate::types::vec_msg_id_as_vec_int\")]" } _ => "", }; diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 465869d6..44308524 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -572,7 +572,7 @@ pub(crate) mod vec_msg_id_as_vec_int { } { - let s = Struct {msg_ids: vec![MessageId(1), MessageId(2)]}; + let s = Struct { msg_ids: vec![MessageId(1), MessageId(2)] }; let json = serde_json::to_string(&s).unwrap(); assert_eq!(json, "{\"msg_ids\":[1,2]}"); } From 173fe6e90d7753781fb3a96ae25aa5a09783bfcb Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:21:26 +0300 Subject: [PATCH 10/38] CHANGELOG added fix --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac09cb91..e9a314e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Some dependencies was bumped: `sqlx` to `0.8.1`, `tower` to `0.5.0`, `reqwest` to `0.12.7` - `tokio` version was explicitly specified as `1.39` +### Fixed + +- Now Vec in requests serializes into [number] instead of [ {message_id: number} ], `forward_messages`, `copy_messages` and `delete_messages` now work properly + [pr1147]: https://github.com/teloxide/teloxide/pull/1147 ## 0.13.0 - 2024-08-16 From 578b6655417f8932766d0ea8bd4fa1d94af3cf07 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 05:03:41 +0300 Subject: [PATCH 11/38] Added bot message sugar --- CHANGELOG.md | 1 + crates/teloxide-core/src/types/message.rs | 10 + crates/teloxide/src/lib.rs | 1 + crates/teloxide/src/sugar.rs | 3 + crates/teloxide/src/sugar/bot.rs | 244 ++++++++++++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 crates/teloxide/src/sugar.rs create mode 100644 crates/teloxide/src/sugar/bot.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a314e6..916126ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `filter_boost_added` and `filter_reply_to_story` filters to `MessageFilterExt` trait - Add `filter_mention_command` filter to `HandlerExt` trait ([issue #494](https://github.com/teloxide/teloxide/issues/494)) - Add `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to update filters ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) +- Add `bot.forward`, `bot.copy` and `bot.delete` to new `crate::sugar::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) ### Changed diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 2b2ce6e2..93411078 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1816,6 +1816,16 @@ impl Message { } } +/// Implemented for syntax sugar, see issue +impl IntoIterator for Message { + type Item = Message; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + vec![self].into_iter() + } +} + #[cfg(test)] mod tests { use chrono::DateTime; diff --git a/crates/teloxide/src/lib.rs b/crates/teloxide/src/lib.rs index bcb901f1..edab596d 100644 --- a/crates/teloxide/src/lib.rs +++ b/crates/teloxide/src/lib.rs @@ -140,6 +140,7 @@ pub mod prelude; #[cfg(feature = "ctrlc_handler")] pub mod repls; pub mod stop; +pub mod sugar; pub mod update_listeners; pub mod utils; diff --git a/crates/teloxide/src/sugar.rs b/crates/teloxide/src/sugar.rs new file mode 100644 index 00000000..6bb10ad8 --- /dev/null +++ b/crates/teloxide/src/sugar.rs @@ -0,0 +1,3 @@ +//! Some non-detrimental, but nice additions + +pub mod bot; diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs new file mode 100644 index 00000000..1d69380d --- /dev/null +++ b/crates/teloxide/src/sugar/bot.rs @@ -0,0 +1,244 @@ +//! Additions to [`Bot`]. +//! +//! [`Bot`]: crate::Bot +use crate::{prelude::*, types::*}; +use std::collections::HashSet; + +pub trait BotMessagesExt { + /// This function is the same as [`Bot::forward_messages`], + /// but can take in [`Message`], including just one. + /// + /// [`Bot::forward_messages`]: crate::Bot::forward_messages + /// [`Message`]: crate::types::Message + fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + where + C: Into, + M: IntoIterator; + + /// This function is the same as [`Bot::copy_messages`], + /// but can take in [`Message`], including just one. + /// + /// [`Bot::copy_messages`]: crate::Bot::copy_messages + /// [`Message`]: crate::types::Message + fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + where + C: Into, + M: IntoIterator; + + /// This function is the same as [`Bot::delete_messages`], + /// but can take in [`Message`], including just one. + /// + /// [`Bot::delete_messages`]: crate::Bot::delete_messages + /// [`Message`]: crate::types::Message + fn delete(&self, messages: M) -> ::DeleteMessages + where + M: IntoIterator; +} + +fn compress_chat_messages(messages: M) -> (ChatId, Vec) +where + M: IntoIterator, +{ + let (message_ids, unique_chat_ids): (Vec, HashSet) = + messages.into_iter().map(|m| (m.id, m.chat.id)).unzip(); + + if unique_chat_ids.is_empty() { + panic!("There needs to be at least one message!"); + } else if unique_chat_ids.len() > 1 { + panic!( + "Messages shouldn't come from different chats! Current chat ids: {:?}", + unique_chat_ids.into_iter().map(|c| c.0).collect::>() + ); + } + + // Unwrap: length is checked to be non-zero before + let chat_id = unique_chat_ids.into_iter().next().unwrap(); + + (chat_id, message_ids) +} + +impl BotMessagesExt for Bot { + fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + where + C: Into, + M: IntoIterator, + { + let (from_chat_id, message_ids) = compress_chat_messages(messages); + self.forward_messages(to_chat_id, from_chat_id, message_ids) + } + + fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + where + C: Into, + M: IntoIterator, + { + let (from_chat_id, message_ids) = compress_chat_messages(messages); + self.copy_messages(to_chat_id, from_chat_id, message_ids) + } + + fn delete(&self, messages: M) -> ::DeleteMessages + where + M: IntoIterator, + { + let (chat_id, message_ids) = compress_chat_messages(messages); + self.delete_messages(chat_id, message_ids) + } +} + +#[cfg(test)] +mod tests { + use std::ops::Deref; + + use chrono::DateTime; + + use super::*; + + fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { + let timestamp = 1_569_518_829; + let date = DateTime::from_timestamp(timestamp, 0).unwrap(); + Message { + via_bot: None, + id: message_id, + thread_id: None, + from: Some(User { + id: UserId(109_998_024), + is_bot: false, + first_name: String::from("Laster"), + last_name: None, + username: Some(String::from("laster_alex")), + language_code: Some(String::from("en")), + is_premium: false, + added_to_attachment_menu: false, + }), + sender_chat: None, + is_topic_message: false, + sender_business_bot: None, + date, + chat: Chat { + id: chat_id, + kind: ChatKind::Private(ChatPrivate { + username: Some(String::from("Laster")), + first_name: Some(String::from("laster_alex")), + last_name: None, + bio: None, + has_private_forwards: None, + has_restricted_voice_and_video_messages: None, + business_intro: None, + business_location: None, + business_opening_hours: None, + birthdate: None, + personal_chat: None, + }), + photo: None, + available_reactions: None, + pinned_message: None, + message_auto_delete_time: None, + has_hidden_members: false, + has_aggressive_anti_spam_enabled: false, + chat_full_info: ChatFullInfo::default(), + }, + kind: MessageKind::Common(MessageCommon { + reply_to_message: None, + forward_origin: None, + external_reply: None, + quote: None, + edit_date: None, + media_kind: MediaKind::Text(MediaText { + text: "text".to_owned(), + entities: vec![], + link_preview_options: None, + }), + reply_markup: None, + author_signature: None, + is_automatic_forward: false, + has_protected_content: false, + reply_to_story: None, + sender_boost_count: None, + is_from_offline: false, + business_connection_id: None, + }), + } + } + + #[test] + fn test_forward() { + let bot = Bot::new("TOKEN"); + + let to_chat_id = ChatId(12345); + let from_chat_id = ChatId(6789); + let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + + let sugar_forward_req = bot.forward( + to_chat_id, + vec![ + make_message(from_chat_id, message_ids[0]), + make_message(from_chat_id, message_ids[1]), + make_message(from_chat_id, message_ids[2]), + ], + ); + let real_forward_req = bot.forward_messages(to_chat_id, from_chat_id, message_ids); + + assert_eq!(sugar_forward_req.deref(), real_forward_req.deref()) + } + + #[test] + fn test_copy() { + let bot = Bot::new("TOKEN"); + + let to_chat_id = ChatId(12345); + let from_chat_id = ChatId(6789); + let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + + let sugar_copy_req = bot.copy( + to_chat_id, + vec![ + make_message(from_chat_id, message_ids[0]), + make_message(from_chat_id, message_ids[1]), + make_message(from_chat_id, message_ids[2]), + ], + ); + let real_copy_req = bot.copy_messages(to_chat_id, from_chat_id, message_ids); + + assert_eq!(sugar_copy_req.deref(), real_copy_req.deref()) + } + + #[test] + fn test_delete() { + let bot = Bot::new("TOKEN"); + + let chat_id = ChatId(6789); + let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + + let sugar_delete_req = bot.delete(vec![ + make_message(chat_id, message_ids[0]), + make_message(chat_id, message_ids[1]), + make_message(chat_id, message_ids[2]), + ]); + let real_delete_req = bot.delete_messages(chat_id, message_ids); + + assert_eq!(sugar_delete_req.deref(), real_delete_req.deref()) + } + + #[test] + #[should_panic] + fn test_forward_many_chats() { + // They all use the same validation, only one check is enough + let bot = Bot::new("TOKEN"); + + let _ = bot.forward( + ChatId(12345), + vec![ + make_message(ChatId(6789), MessageId(100)), + make_message(ChatId(6789), MessageId(101)), + make_message(ChatId(9012), MessageId(102)), + ], + ); + } + + #[test] + fn message_to_iterator() { + // Just to make sure one message still can be passed in + let message = make_message(ChatId(1), MessageId(1)); + assert_eq!(message.clone().into_iter().next(), Some(message)); + } +} From c6eb43138dffe63dcd266c464840ec4462a55f9c Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 06:17:44 +0300 Subject: [PATCH 12/38] Added simple json request sugar --- crates/teloxide/src/sugar.rs | 1 + crates/teloxide/src/sugar/request.rs | 51 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 crates/teloxide/src/sugar/request.rs diff --git a/crates/teloxide/src/sugar.rs b/crates/teloxide/src/sugar.rs index 6bb10ad8..b6f23cc0 100644 --- a/crates/teloxide/src/sugar.rs +++ b/crates/teloxide/src/sugar.rs @@ -1,3 +1,4 @@ //! Some non-detrimental, but nice additions pub mod bot; +pub mod request; diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs new file mode 100644 index 00000000..a3b82091 --- /dev/null +++ b/crates/teloxide/src/sugar/request.rs @@ -0,0 +1,51 @@ +//! Additions to [`JsonRequest`]. +//! +//! [`JsonRequest`]: teloxide_core::requests::JsonRequest + +use teloxide_core::{payloads::*, prelude::Requester, types::*, Bot}; + +macro_rules! impl_request_reply_ext { + ($($t:ty),*) => { + $( + impl RequestReplyExt for $t { + fn reply_to(self, message_id: M) -> Self + where + M: Into, + Self: teloxide_core::requests::HasPayload + Sized, + { + self.reply_parameters(ReplyParameters::new(message_id.into())) + } + } + )* + }; +} + +pub trait RequestReplyExt { + fn reply_to(self, message_id: M) -> Self + where + M: Into, + Self: Sized; +} + +impl_request_reply_ext! { + ::SendMessage +} + +#[cfg(test)] +mod tests { + use std::ops::Deref; + + use super::*; + use teloxide_core::{prelude::Requester, Bot}; + + #[test] + fn test_reply_to() { + let bot = Bot::new("TOKEN"); + let real_reply_req = bot + .send_message(ChatId(1234), "test") + .reply_parameters(ReplyParameters::new(MessageId(1))); + let sugar_reply_req = bot.send_message(ChatId(1234), "test").reply_to(MessageId(1)); + + assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) + } +} From 2ea545a15cfa09cf0204a0c2e3ea3220789dc6f7 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 06:28:39 +0300 Subject: [PATCH 13/38] Added link preview sugar --- crates/teloxide/src/sugar/request.rs | 51 +++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs index a3b82091..dc31ae50 100644 --- a/crates/teloxide/src/sugar/request.rs +++ b/crates/teloxide/src/sugar/request.rs @@ -11,7 +11,7 @@ macro_rules! impl_request_reply_ext { fn reply_to(self, message_id: M) -> Self where M: Into, - Self: teloxide_core::requests::HasPayload + Sized, + Self: Sized, { self.reply_parameters(ReplyParameters::new(message_id.into())) } @@ -20,6 +20,28 @@ macro_rules! impl_request_reply_ext { }; } +macro_rules! impl_request_link_preview_ext { + ($($t:ty),*) => { + $( + impl RequestLinkPreviewExt for $t { + fn disable_link_preview(self) -> Self + where + Self: Sized + { + let link_preview_options = LinkPreviewOptions { + is_disabled: true, + url: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, + }; + self.link_preview_options(link_preview_options) + } + } + )* + }; +} + pub trait RequestReplyExt { fn reply_to(self, message_id: M) -> Self where @@ -27,10 +49,20 @@ pub trait RequestReplyExt { Self: Sized; } +pub trait RequestLinkPreviewExt { + fn disable_link_preview(self) -> Self + where + Self: Sized; +} + impl_request_reply_ext! { ::SendMessage } +impl_request_link_preview_ext! { + ::SendMessage +} + #[cfg(test)] mod tests { use std::ops::Deref; @@ -48,4 +80,21 @@ mod tests { assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) } + + #[test] + fn test_disable_link_preview() { + let link_preview_options = LinkPreviewOptions { + is_disabled: true, + url: None, + prefer_small_media: false, + prefer_large_media: false, + show_above_text: false, + }; + let bot = Bot::new("TOKEN"); + let real_link_req = + bot.send_message(ChatId(1234), "test").link_preview_options(link_preview_options); + let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(); + + assert_eq!(real_link_req.deref(), sugar_link_req.deref()) + } } From 83b178c8ca4262f0e74611e87fdb7a9e987da4cd Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:05:49 +0300 Subject: [PATCH 14/38] More types + some fixes --- crates/teloxide-core/src/types/message.rs | 8 +++ crates/teloxide/src/sugar/bot.rs | 28 ++++++--- crates/teloxide/src/sugar/request.rs | 71 ++++++++++++++++++++--- 3 files changed, 91 insertions(+), 16 deletions(-) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 93411078..36fec591 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1826,6 +1826,14 @@ impl IntoIterator for Message { } } +/// Implemented for syntax sugar, see issue +#[allow(clippy::from_over_into)] +impl Into for Message { + fn into(self) -> MessageId { + self.id + } +} + #[cfg(test)] mod tests { use chrono::DateTime; diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index 1d69380d..4c8781a2 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -2,15 +2,19 @@ //! //! [`Bot`]: crate::Bot use crate::{prelude::*, types::*}; +use teloxide_core::{payloads::*, requests::JsonRequest}; use std::collections::HashSet; +/// Adds useful manipulations with [`Message`] structs +/// +/// [`Message`]: crate::types::Message pub trait BotMessagesExt { /// This function is the same as [`Bot::forward_messages`], /// but can take in [`Message`], including just one. /// /// [`Bot::forward_messages`]: crate::Bot::forward_messages /// [`Message`]: crate::types::Message - fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + fn forward(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator; @@ -20,7 +24,7 @@ pub trait BotMessagesExt { /// /// [`Bot::copy_messages`]: crate::Bot::copy_messages /// [`Message`]: crate::types::Message - fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + fn copy(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator; @@ -30,7 +34,7 @@ pub trait BotMessagesExt { /// /// [`Bot::delete_messages`]: crate::Bot::delete_messages /// [`Message`]: crate::types::Message - fn delete(&self, messages: M) -> ::DeleteMessages + fn delete(&self, messages: M) -> JsonRequest where M: IntoIterator; } @@ -58,7 +62,7 @@ where } impl BotMessagesExt for Bot { - fn forward(&self, to_chat_id: C, messages: M) -> ::ForwardMessages + fn forward(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator, @@ -67,7 +71,7 @@ impl BotMessagesExt for Bot { self.forward_messages(to_chat_id, from_chat_id, message_ids) } - fn copy(&self, to_chat_id: C, messages: M) -> ::CopyMessages + fn copy(&self, to_chat_id: C, messages: M) -> JsonRequest where C: Into, M: IntoIterator, @@ -76,7 +80,7 @@ impl BotMessagesExt for Bot { self.copy_messages(to_chat_id, from_chat_id, message_ids) } - fn delete(&self, messages: M) -> ::DeleteMessages + fn delete(&self, messages: M) -> JsonRequest where M: IntoIterator, { @@ -86,14 +90,14 @@ impl BotMessagesExt for Bot { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use std::ops::Deref; use chrono::DateTime; use super::*; - fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { + pub(crate) fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { let timestamp = 1_569_518_829; let date = DateTime::from_timestamp(timestamp, 0).unwrap(); Message { @@ -241,4 +245,12 @@ mod tests { let message = make_message(ChatId(1), MessageId(1)); assert_eq!(message.clone().into_iter().next(), Some(message)); } + + #[test] + fn message_to_message_id() { + // Just to make sure message still can be in Into + let message = make_message(ChatId(1), MessageId(1)); + let message_id: MessageId = message.into(); + assert_eq!(message_id, MessageId(1)); + } } diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs index dc31ae50..6c2d4f3d 100644 --- a/crates/teloxide/src/sugar/request.rs +++ b/crates/teloxide/src/sugar/request.rs @@ -1,8 +1,13 @@ -//! Additions to [`JsonRequest`]. +//! Additions to [`JsonRequest`] and [`MultipartRequest`]. //! //! [`JsonRequest`]: teloxide_core::requests::JsonRequest +//! [`MultipartRequest`]: teloxide_core::requests::MultipartRequest -use teloxide_core::{payloads::*, prelude::Requester, types::*, Bot}; +use teloxide_core::{ + payloads::*, + requests::{JsonRequest, MultipartRequest}, + types::*, +}; macro_rules! impl_request_reply_ext { ($($t:ty),*) => { @@ -24,12 +29,12 @@ macro_rules! impl_request_link_preview_ext { ($($t:ty),*) => { $( impl RequestLinkPreviewExt for $t { - fn disable_link_preview(self) -> Self + fn disable_link_preview(self, is_disabled: bool) -> Self where Self: Sized { let link_preview_options = LinkPreviewOptions { - is_disabled: true, + is_disabled, url: None, prefer_small_media: false, prefer_large_media: false, @@ -42,25 +47,57 @@ macro_rules! impl_request_link_preview_ext { }; } +/// Adds `.reply_to(message_id)` to requests pub trait RequestReplyExt { + /// Replaces `.reply_parameters(ReplyParameters::new(msg.id))` + /// with `.reply_to(msg.id)` or `.reply_to(msg)` fn reply_to(self, message_id: M) -> Self where M: Into, Self: Sized; } +/// Adds `.disable_link_preview(is_disabled)` to requests pub trait RequestLinkPreviewExt { - fn disable_link_preview(self) -> Self + /// Replaces + /// `.link_preview_options(LinkPreviewOptions { + /// is_disabled: true, + /// url: None, + /// prefer_small_media: false, + /// prefer_large_media: false, + /// show_above_text: false + /// };)` + /// + /// With `.disable_link_preview(true)` + fn disable_link_preview(self, is_disabled: bool) -> Self where Self: Sized; } impl_request_reply_ext! { - ::SendMessage + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + JsonRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest, + MultipartRequest } impl_request_link_preview_ext! { - ::SendMessage + JsonRequest, + JsonRequest } #[cfg(test)] @@ -73,6 +110,7 @@ mod tests { #[test] fn test_reply_to() { let bot = Bot::new("TOKEN"); + let real_reply_req = bot .send_message(ChatId(1234), "test") .reply_parameters(ReplyParameters::new(MessageId(1))); @@ -81,6 +119,22 @@ mod tests { assert_eq!(real_reply_req.deref(), sugar_reply_req.deref()) } + #[test] + fn test_reply_to_multipart() { + let bot = Bot::new("TOKEN"); + let document = InputFile::memory("hello world!"); + + let real_reply_req = bot + .send_document(ChatId(1234), document.clone()) + .reply_parameters(ReplyParameters::new(MessageId(1))); + let sugar_reply_req = bot.send_document(ChatId(1234), document).reply_to(MessageId(1)); + + assert_eq!( + real_reply_req.deref().reply_parameters, + sugar_reply_req.deref().reply_parameters + ) + } + #[test] fn test_disable_link_preview() { let link_preview_options = LinkPreviewOptions { @@ -91,9 +145,10 @@ mod tests { show_above_text: false, }; let bot = Bot::new("TOKEN"); + let real_link_req = bot.send_message(ChatId(1234), "test").link_preview_options(link_preview_options); - let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(); + let sugar_link_req = bot.send_message(ChatId(1234), "test").disable_link_preview(true); assert_eq!(real_link_req.deref(), sugar_link_req.deref()) } From 968fd5fbc3f7b2f685a40adc30af83ae9b5a626f Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:47:15 +0300 Subject: [PATCH 15/38] Cargo fmt --- crates/teloxide/src/sugar/bot.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index 4c8781a2..e4a0a934 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -2,8 +2,8 @@ //! //! [`Bot`]: crate::Bot use crate::{prelude::*, types::*}; -use teloxide_core::{payloads::*, requests::JsonRequest}; use std::collections::HashSet; +use teloxide_core::{payloads::*, requests::JsonRequest}; /// Adds useful manipulations with [`Message`] structs /// From 4ac9226f83b6397259011dbd44a6ca34dcfaf42e Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Fri, 30 Aug 2024 09:50:52 +0300 Subject: [PATCH 16/38] Changelog update --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916126ce..cb2bab28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `filter_boost_added` and `filter_reply_to_story` filters to `MessageFilterExt` trait - Add `filter_mention_command` filter to `HandlerExt` trait ([issue #494](https://github.com/teloxide/teloxide/issues/494)) - Add `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to update filters ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) -- Add `bot.forward`, `bot.copy` and `bot.delete` to new `crate::sugar::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) +- Add `bot.forward`, `bot.copy` and `bot.delete` to new `crate::sugar::bot::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) +- Add `.reply_to(message_id)` to new `crate::sugar::request::RequestReplyExt` trait, and `.disable_link_preview(is_disabled)` to new `crate::sugar::request::RequestLinkPreviewExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) ### Changed From 2a350a0df2f920efce4fe3d438afcd945d24de9f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 08:51:40 +0000 Subject: [PATCH 17/38] Bump the lock group with 14 updates Bumps the lock group with 14 updates: | Package | From | To | | --- | --- | --- | | [tokio](https://github.com/tokio-rs/tokio) | `1.39.3` | `1.40.0` | | [bitflags](https://github.com/bitflags/bitflags) | `1.3.2` | `2.4.2` | | [rgb](https://github.com/kornelski/rust-rgb) | `0.8.48` | `0.8.50` | | [aho-corasick](https://github.com/BurntSushi/aho-corasick) | `0.7.20` | `1.1.2` | | [syn](https://github.com/dtolnay/syn) | `1.0.109` | `2.0.52` | | [async-trait](https://github.com/dtolnay/async-trait) | `0.1.81` | `0.1.82` | | [bytemuck](https://github.com/Lokathor/bytemuck) | `1.17.0` | `1.17.1` | | [cc](https://github.com/rust-lang/cc-rs) | `1.1.14` | `1.1.15` | | [object](https://github.com/gimli-rs/object) | `0.36.3` | `0.36.4` | | [rustc_version](https://github.com/djc/rustc-version-rs) | `0.4.0` | `0.4.1` | | [rustix](https://github.com/bytecodealliance/rustix) | `0.38.34` | `0.38.35` | | [rustls-native-certs](https://github.com/rustls/rustls-native-certs) | `0.7.2` | `0.7.3` | | [rustls-webpki](https://github.com/rustls/webpki) | `0.102.6` | `0.102.7` | | [webpki-roots](https://github.com/rustls/webpki-roots) | `0.26.3` | `0.26.5` | Updates `tokio` from 1.39.3 to 1.40.0 - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.39.3...tokio-1.40.0) Updates `bitflags` from 1.3.2 to 2.4.2 - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](https://github.com/bitflags/bitflags/compare/1.3.2...2.4.2) Updates `rgb` from 0.8.48 to 0.8.50 - [Changelog](https://github.com/kornelski/rust-rgb/blob/v0.8.50/CHANGELOG.md) - [Commits](https://github.com/kornelski/rust-rgb/compare/v0.8.48...v0.8.50) Updates `aho-corasick` from 0.7.20 to 1.1.2 - [Commits](https://github.com/BurntSushi/aho-corasick/compare/0.7.20...1.1.2) Updates `syn` from 1.0.109 to 2.0.52 - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.109...2.0.52) Updates `async-trait` from 0.1.81 to 0.1.82 - [Release notes](https://github.com/dtolnay/async-trait/releases) - [Commits](https://github.com/dtolnay/async-trait/compare/0.1.81...0.1.82) Updates `bytemuck` from 1.17.0 to 1.17.1 - [Changelog](https://github.com/Lokathor/bytemuck/blob/main/changelog.md) - [Commits](https://github.com/Lokathor/bytemuck/compare/v1.17.0...v1.17.1) Updates `cc` from 1.1.14 to 1.1.15 - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.14...cc-v1.1.15) Updates `object` from 0.36.3 to 0.36.4 - [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md) - [Commits](https://github.com/gimli-rs/object/compare/0.36.3...0.36.4) Updates `rustc_version` from 0.4.0 to 0.4.1 - [Release notes](https://github.com/djc/rustc-version-rs/releases) - [Commits](https://github.com/djc/rustc-version-rs/compare/v0.4.0...v0.4.1) Updates `rustix` from 0.38.34 to 0.38.35 - [Release notes](https://github.com/bytecodealliance/rustix/releases) - [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.34...v0.38.35) Updates `rustls-native-certs` from 0.7.2 to 0.7.3 - [Release notes](https://github.com/rustls/rustls-native-certs/releases) - [Commits](https://github.com/rustls/rustls-native-certs/compare/v/0.7.2...v/0.7.3) Updates `rustls-webpki` from 0.102.6 to 0.102.7 - [Release notes](https://github.com/rustls/webpki/releases) - [Commits](https://github.com/rustls/webpki/compare/v/0.102.6...v/0.102.7) Updates `webpki-roots` from 0.26.3 to 0.26.5 - [Release notes](https://github.com/rustls/webpki-roots/releases) - [Commits](https://github.com/rustls/webpki-roots/compare/v/0.26.3...v/0.26.5) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production update-type: version-update:semver-minor dependency-group: lock - dependency-name: bitflags dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: rgb dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: aho-corasick dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: async-trait dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: bytemuck dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: cc dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: object dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustc_version dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustix dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls-native-certs dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls-webpki dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: webpki-roots dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock ... Signed-off-by: dependabot[bot] --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff7098ec..f7f14bfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,9 +84,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", @@ -237,9 +237,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" +checksum = "773d90827bc3feecfb67fab12e24de0749aad83c74b9504ecde46237b5cd24e2" [[package]] name = "byteorder" @@ -255,9 +255,9 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.1.14" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d2eb3cd3d1bf4529e31c215ee6f93ec5a3d536d9f578f93d9d33ee19562932" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" dependencies = [ "shlex", ] @@ -1262,9 +1262,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -1676,9 +1676,9 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f86ae463694029097b846d8f99fd5536740602ae00022c0c50c5600720b2f71" +checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" dependencies = [ "bytemuck", ] @@ -1724,18 +1724,18 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ "bitflags 2.4.2", "errno", @@ -1760,9 +1760,9 @@ dependencies = [ [[package]] name = "rustls-native-certs" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04182dffc9091a404e0fc069ea5cd60e5b866c3adf881eff99a32d048242dffa" +checksum = "e5bfb394eeed242e909609f56089eecfe5fda225042e8b171791b9c95f5931e5" dependencies = [ "openssl-probe", "rustls-pemfile", @@ -1789,9 +1789,9 @@ checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" -version = "0.102.6" +version = "0.102.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" dependencies = [ "ring", "rustls-pki-types", @@ -2414,9 +2414,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.39.3" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", @@ -2784,9 +2784,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.3" +version = "0.26.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" dependencies = [ "rustls-pki-types", ] From 9f7d980a702a6246c6cf6316ae62ebd4be7c7da5 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Tue, 3 Sep 2024 13:43:50 +0300 Subject: [PATCH 18/38] Removed multiple messages sugar functionality --- crates/teloxide-core/src/types/message.rs | 10 -- crates/teloxide/src/sugar.rs | 2 +- crates/teloxide/src/sugar/bot.rs | 134 +++++----------------- 3 files changed, 30 insertions(+), 116 deletions(-) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 36fec591..e1634315 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1816,16 +1816,6 @@ impl Message { } } -/// Implemented for syntax sugar, see issue -impl IntoIterator for Message { - type Item = Message; - type IntoIter = std::vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - vec![self].into_iter() - } -} - /// Implemented for syntax sugar, see issue #[allow(clippy::from_over_into)] impl Into for Message { diff --git a/crates/teloxide/src/sugar.rs b/crates/teloxide/src/sugar.rs index b6f23cc0..ae5bb627 100644 --- a/crates/teloxide/src/sugar.rs +++ b/crates/teloxide/src/sugar.rs @@ -1,4 +1,4 @@ -//! Some non-detrimental, but nice additions +//! Some syntax sugar support for TBA functionality pub mod bot; pub mod request; diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index e4a0a934..c4efed27 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -2,90 +2,55 @@ //! //! [`Bot`]: crate::Bot use crate::{prelude::*, types::*}; -use std::collections::HashSet; use teloxide_core::{payloads::*, requests::JsonRequest}; /// Adds useful manipulations with [`Message`] structs /// /// [`Message`]: crate::types::Message pub trait BotMessagesExt { - /// This function is the same as [`Bot::forward_messages`], - /// but can take in [`Message`], including just one. + /// This function is the same as [`Bot::forward_message`], + /// but can take in [`Message`] to forward it. /// - /// [`Bot::forward_messages`]: crate::Bot::forward_messages + /// [`Bot::forward_message`]: crate::Bot::forward_message /// [`Message`]: crate::types::Message - fn forward(&self, to_chat_id: C, messages: M) -> JsonRequest + fn forward(&self, to_chat_id: C, message: Message) -> JsonRequest where - C: Into, - M: IntoIterator; + C: Into; - /// This function is the same as [`Bot::copy_messages`], - /// but can take in [`Message`], including just one. + /// This function is the same as [`Bot::copy_message`], + /// but can take in [`Message`] to copy it. /// - /// [`Bot::copy_messages`]: crate::Bot::copy_messages + /// [`Bot::copy_messages`]: crate::Bot::copy_message /// [`Message`]: crate::types::Message - fn copy(&self, to_chat_id: C, messages: M) -> JsonRequest + fn copy(&self, to_chat_id: C, message: Message) -> JsonRequest where - C: Into, - M: IntoIterator; + C: Into; - /// This function is the same as [`Bot::delete_messages`], - /// but can take in [`Message`], including just one. + /// This function is the same as [`Bot::delete_message`], + /// but can take in [`Message`] to delete it. /// - /// [`Bot::delete_messages`]: crate::Bot::delete_messages + /// [`Bot::delete_message`]: crate::Bot::delete_message /// [`Message`]: crate::types::Message - fn delete(&self, messages: M) -> JsonRequest - where - M: IntoIterator; -} - -fn compress_chat_messages(messages: M) -> (ChatId, Vec) -where - M: IntoIterator, -{ - let (message_ids, unique_chat_ids): (Vec, HashSet) = - messages.into_iter().map(|m| (m.id, m.chat.id)).unzip(); - - if unique_chat_ids.is_empty() { - panic!("There needs to be at least one message!"); - } else if unique_chat_ids.len() > 1 { - panic!( - "Messages shouldn't come from different chats! Current chat ids: {:?}", - unique_chat_ids.into_iter().map(|c| c.0).collect::>() - ); - } - - // Unwrap: length is checked to be non-zero before - let chat_id = unique_chat_ids.into_iter().next().unwrap(); - - (chat_id, message_ids) + fn delete(&self, message: Message) -> JsonRequest; } impl BotMessagesExt for Bot { - fn forward(&self, to_chat_id: C, messages: M) -> JsonRequest + fn forward(&self, to_chat_id: C, message: Message) -> JsonRequest where C: Into, - M: IntoIterator, { - let (from_chat_id, message_ids) = compress_chat_messages(messages); - self.forward_messages(to_chat_id, from_chat_id, message_ids) + self.forward_message(to_chat_id, message.chat.id, message.id) } - fn copy(&self, to_chat_id: C, messages: M) -> JsonRequest + fn copy(&self, to_chat_id: C, message: Message) -> JsonRequest where C: Into, - M: IntoIterator, { - let (from_chat_id, message_ids) = compress_chat_messages(messages); - self.copy_messages(to_chat_id, from_chat_id, message_ids) + self.copy_message(to_chat_id, message.chat.id, message.id) } - fn delete(&self, messages: M) -> JsonRequest - where - M: IntoIterator, - { - let (chat_id, message_ids) = compress_chat_messages(messages); - self.delete_messages(chat_id, message_ids) + fn delete(&self, message: Message) -> JsonRequest { + self.delete_message(message.chat.id, message.id) } } @@ -170,17 +135,10 @@ pub(crate) mod tests { let to_chat_id = ChatId(12345); let from_chat_id = ChatId(6789); - let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + let message_id = MessageId(100); - let sugar_forward_req = bot.forward( - to_chat_id, - vec![ - make_message(from_chat_id, message_ids[0]), - make_message(from_chat_id, message_ids[1]), - make_message(from_chat_id, message_ids[2]), - ], - ); - let real_forward_req = bot.forward_messages(to_chat_id, from_chat_id, message_ids); + let sugar_forward_req = bot.forward(to_chat_id, make_message(from_chat_id, message_id)); + let real_forward_req = bot.forward_message(to_chat_id, from_chat_id, message_id); assert_eq!(sugar_forward_req.deref(), real_forward_req.deref()) } @@ -191,17 +149,10 @@ pub(crate) mod tests { let to_chat_id = ChatId(12345); let from_chat_id = ChatId(6789); - let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + let message_id = MessageId(100); - let sugar_copy_req = bot.copy( - to_chat_id, - vec![ - make_message(from_chat_id, message_ids[0]), - make_message(from_chat_id, message_ids[1]), - make_message(from_chat_id, message_ids[2]), - ], - ); - let real_copy_req = bot.copy_messages(to_chat_id, from_chat_id, message_ids); + let sugar_copy_req = bot.copy(to_chat_id, make_message(from_chat_id, message_id)); + let real_copy_req = bot.copy_message(to_chat_id, from_chat_id, message_id); assert_eq!(sugar_copy_req.deref(), real_copy_req.deref()) } @@ -211,41 +162,14 @@ pub(crate) mod tests { let bot = Bot::new("TOKEN"); let chat_id = ChatId(6789); - let message_ids = vec![MessageId(100), MessageId(101), MessageId(102)]; + let message_id = MessageId(100); - let sugar_delete_req = bot.delete(vec![ - make_message(chat_id, message_ids[0]), - make_message(chat_id, message_ids[1]), - make_message(chat_id, message_ids[2]), - ]); - let real_delete_req = bot.delete_messages(chat_id, message_ids); + let sugar_delete_req = bot.delete(make_message(chat_id, message_id)); + let real_delete_req = bot.delete_message(chat_id, message_id); assert_eq!(sugar_delete_req.deref(), real_delete_req.deref()) } - #[test] - #[should_panic] - fn test_forward_many_chats() { - // They all use the same validation, only one check is enough - let bot = Bot::new("TOKEN"); - - let _ = bot.forward( - ChatId(12345), - vec![ - make_message(ChatId(6789), MessageId(100)), - make_message(ChatId(6789), MessageId(101)), - make_message(ChatId(9012), MessageId(102)), - ], - ); - } - - #[test] - fn message_to_iterator() { - // Just to make sure one message still can be passed in - let message = make_message(ChatId(1), MessageId(1)); - assert_eq!(message.clone().into_iter().next(), Some(message)); - } - #[test] fn message_to_message_id() { // Just to make sure message still can be in Into From c9a0fe452de858dff609a421513e8cde159a428d Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Tue, 3 Sep 2024 14:20:44 +0300 Subject: [PATCH 19/38] Added sugar to examples --- crates/teloxide/examples/dispatching_features.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/teloxide/examples/dispatching_features.rs b/crates/teloxide/examples/dispatching_features.rs index bcc65a2e..23f127ff 100644 --- a/crates/teloxide/examples/dispatching_features.rs +++ b/crates/teloxide/examples/dispatching_features.rs @@ -6,8 +6,9 @@ use rand::Rng; use teloxide::{ dispatching::HandlerExt, prelude::*, - types::{Dice, ReplyParameters}, + types::Dice, utils::command::BotCommands, + sugar::request::RequestReplyExt, }; #[tokio::main] @@ -84,7 +85,7 @@ async fn main() { // filter only messages with dices. Message::filter_dice().endpoint(|bot: Bot, msg: Message, dice: Dice| async move { bot.send_message(msg.chat.id, format!("Dice value: {}", dice.value)) - .reply_parameters(ReplyParameters::new(msg.id)) + .reply_to(msg) .await?; Ok(()) }), From b533a85a33ee9ce9439e01fdb81fc75f23e55d01 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Tue, 3 Sep 2024 14:21:57 +0300 Subject: [PATCH 20/38] Cargo fmt --- crates/teloxide/examples/dispatching_features.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/teloxide/examples/dispatching_features.rs b/crates/teloxide/examples/dispatching_features.rs index 23f127ff..8b327b55 100644 --- a/crates/teloxide/examples/dispatching_features.rs +++ b/crates/teloxide/examples/dispatching_features.rs @@ -4,11 +4,8 @@ use rand::Rng; use teloxide::{ - dispatching::HandlerExt, - prelude::*, - types::Dice, + dispatching::HandlerExt, prelude::*, sugar::request::RequestReplyExt, types::Dice, utils::command::BotCommands, - sugar::request::RequestReplyExt, }; #[tokio::main] From aa090612a449d93819537c59206f204771fa1b47 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 20:50:49 +0000 Subject: [PATCH 21/38] Bump quinn-proto from 0.11.6 to 0.11.8 Bumps [quinn-proto](https://github.com/quinn-rs/quinn) from 0.11.6 to 0.11.8. - [Release notes](https://github.com/quinn-rs/quinn/releases) - [Commits](https://github.com/quinn-rs/quinn/compare/quinn-proto-0.11.6...quinn-proto-0.11.8) --- updated-dependencies: - dependency-name: quinn-proto dependency-type: indirect ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f14bfc..8c230550 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1480,9 +1480,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.6" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand", From 2c21479aec356712a7a1a789d17d53d84858ae1c Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Wed, 4 Sep 2024 03:19:12 +0300 Subject: [PATCH 22/38] Changed ownership to ref --- crates/teloxide/src/sugar/bot.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index c4efed27..7755cc58 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -13,7 +13,7 @@ pub trait BotMessagesExt { /// /// [`Bot::forward_message`]: crate::Bot::forward_message /// [`Message`]: crate::types::Message - fn forward(&self, to_chat_id: C, message: Message) -> JsonRequest + fn forward(&self, to_chat_id: C, message: &Message) -> JsonRequest where C: Into; @@ -22,7 +22,7 @@ pub trait BotMessagesExt { /// /// [`Bot::copy_messages`]: crate::Bot::copy_message /// [`Message`]: crate::types::Message - fn copy(&self, to_chat_id: C, message: Message) -> JsonRequest + fn copy(&self, to_chat_id: C, message: &Message) -> JsonRequest where C: Into; @@ -31,25 +31,25 @@ pub trait BotMessagesExt { /// /// [`Bot::delete_message`]: crate::Bot::delete_message /// [`Message`]: crate::types::Message - fn delete(&self, message: Message) -> JsonRequest; + fn delete(&self, message: &Message) -> JsonRequest; } impl BotMessagesExt for Bot { - fn forward(&self, to_chat_id: C, message: Message) -> JsonRequest + fn forward(&self, to_chat_id: C, message: &Message) -> JsonRequest where C: Into, { self.forward_message(to_chat_id, message.chat.id, message.id) } - fn copy(&self, to_chat_id: C, message: Message) -> JsonRequest + fn copy(&self, to_chat_id: C, message: &Message) -> JsonRequest where C: Into, { self.copy_message(to_chat_id, message.chat.id, message.id) } - fn delete(&self, message: Message) -> JsonRequest { + fn delete(&self, message: &Message) -> JsonRequest { self.delete_message(message.chat.id, message.id) } } @@ -137,7 +137,7 @@ pub(crate) mod tests { let from_chat_id = ChatId(6789); let message_id = MessageId(100); - let sugar_forward_req = bot.forward(to_chat_id, make_message(from_chat_id, message_id)); + let sugar_forward_req = bot.forward(to_chat_id, &make_message(from_chat_id, message_id)); let real_forward_req = bot.forward_message(to_chat_id, from_chat_id, message_id); assert_eq!(sugar_forward_req.deref(), real_forward_req.deref()) @@ -151,7 +151,7 @@ pub(crate) mod tests { let from_chat_id = ChatId(6789); let message_id = MessageId(100); - let sugar_copy_req = bot.copy(to_chat_id, make_message(from_chat_id, message_id)); + let sugar_copy_req = bot.copy(to_chat_id, &make_message(from_chat_id, message_id)); let real_copy_req = bot.copy_message(to_chat_id, from_chat_id, message_id); assert_eq!(sugar_copy_req.deref(), real_copy_req.deref()) @@ -164,7 +164,7 @@ pub(crate) mod tests { let chat_id = ChatId(6789); let message_id = MessageId(100); - let sugar_delete_req = bot.delete(make_message(chat_id, message_id)); + let sugar_delete_req = bot.delete(&make_message(chat_id, message_id)); let real_delete_req = bot.delete_message(chat_id, message_id); assert_eq!(sugar_delete_req.deref(), real_delete_req.deref()) From af3305cae87c5449d81ffbd1000bf44d6b8ea821 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 23 Sep 2024 01:30:28 +0300 Subject: [PATCH 23/38] Updated code with suggestions --- crates/teloxide/src/sugar.rs | 2 +- crates/teloxide/src/sugar/bot.rs | 2 +- crates/teloxide/src/sugar/request.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/teloxide/src/sugar.rs b/crates/teloxide/src/sugar.rs index ae5bb627..0e8bb856 100644 --- a/crates/teloxide/src/sugar.rs +++ b/crates/teloxide/src/sugar.rs @@ -1,4 +1,4 @@ -//! Some syntax sugar support for TBA functionality +//! Some syntax sugar support for TBA functionality. pub mod bot; pub mod request; diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index 7755cc58..7b62ba66 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -4,7 +4,7 @@ use crate::{prelude::*, types::*}; use teloxide_core::{payloads::*, requests::JsonRequest}; -/// Adds useful manipulations with [`Message`] structs +/// Syntax sugar for [`Message`] manipulations. /// /// [`Message`]: crate::types::Message pub trait BotMessagesExt { diff --git a/crates/teloxide/src/sugar/request.rs b/crates/teloxide/src/sugar/request.rs index 6c2d4f3d..59ca41b0 100644 --- a/crates/teloxide/src/sugar/request.rs +++ b/crates/teloxide/src/sugar/request.rs @@ -47,7 +47,7 @@ macro_rules! impl_request_link_preview_ext { }; } -/// Adds `.reply_to(message_id)` to requests +/// `.reply_to(msg)` syntax sugar for requests. pub trait RequestReplyExt { /// Replaces `.reply_parameters(ReplyParameters::new(msg.id))` /// with `.reply_to(msg.id)` or `.reply_to(msg)` @@ -57,7 +57,7 @@ pub trait RequestReplyExt { Self: Sized; } -/// Adds `.disable_link_preview(is_disabled)` to requests +/// `.disable_link_preview(is_disabled)` syntax sugar for requests. pub trait RequestLinkPreviewExt { /// Replaces /// `.link_preview_options(LinkPreviewOptions { @@ -68,7 +68,7 @@ pub trait RequestLinkPreviewExt { /// show_above_text: false /// };)` /// - /// With `.disable_link_preview(true)` + /// with `.disable_link_preview(true)`. fn disable_link_preview(self, is_disabled: bool) -> Self where Self: Sized; From 1f23983bfb5fda1eec39213ab14cd4b019ee2f2a Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 23 Sep 2024 01:36:07 +0300 Subject: [PATCH 24/38] Changed Into to From --- crates/teloxide-core/src/types/message.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index e1634315..2da52dcf 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1817,10 +1817,9 @@ impl Message { } /// Implemented for syntax sugar, see issue -#[allow(clippy::from_over_into)] -impl Into for Message { - fn into(self) -> MessageId { - self.id +impl From for MessageId { + fn from(message: Message) -> MessageId { + message.id } } From 3b618a7b5a2bc83a07f037d1a64673fc7a132148 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 23 Sep 2024 02:29:28 +0300 Subject: [PATCH 25/38] Added syntactic sugar to all methods with message_id and chat_id --- CHANGELOG.md | 2 +- crates/teloxide/src/sugar/bot.rs | 291 +++++++++++++++++++++++++++---- 2 files changed, 261 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb2bab28..dac415f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `filter_boost_added` and `filter_reply_to_story` filters to `MessageFilterExt` trait - Add `filter_mention_command` filter to `HandlerExt` trait ([issue #494](https://github.com/teloxide/teloxide/issues/494)) - Add `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to update filters ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) -- Add `bot.forward`, `bot.copy` and `bot.delete` to new `crate::sugar::bot::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) +- Add `bot.forward`, `bot.edit_live_location`, `bot.stop_live_location`, `bot.set_reaction`, `bot.pin`, `bot.unpin`, `bot.edit_text`, `bot.edit_caption`, `bot.edit_media`, `bot.edit_reply_markup`, `bot.stop_poll_message`, `bot.delete` and `bot.copy` to new `crate::sugar::bot::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) - Add `.reply_to(message_id)` to new `crate::sugar::request::RequestReplyExt` trait, and `.disable_link_preview(is_disabled)` to new `crate::sugar::request::RequestLinkPreviewExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) ### Changed diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index 7b62ba66..bd0242f0 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -2,7 +2,10 @@ //! //! [`Bot`]: crate::Bot use crate::{prelude::*, types::*}; -use teloxide_core::{payloads::*, requests::JsonRequest}; +use teloxide_core::{ + payloads::*, + requests::{JsonRequest, MultipartRequest}, +}; /// Syntax sugar for [`Message`] manipulations. /// @@ -17,6 +20,94 @@ pub trait BotMessagesExt { where C: Into; + /// This function is the same as [`Bot::edit_message_live_location`], + /// but can take in [`Message`] to edit it. + /// + /// [`Bot::edit_message_live_location`]: crate::Bot::edit_message_live_location + /// [`Message`]: crate::types::Message + fn edit_live_location( + &self, + message: &Message, + latitude: f64, + longitude: f64, + ) -> JsonRequest; + + /// This function is the same as [`Bot::stop_message_live_location`], + /// but can take in [`Message`] to stop the live location in it. + /// + /// [`Bot::stop_message_live_location`]: crate::Bot::stop_message_live_location + /// [`Message`]: crate::types::Message + fn stop_live_location(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::set_message_reaction`], + /// but can take in [`Message`] to set a reaction on it. + /// + /// [`Bot::set_message_reaction`]: crate::Bot::set_message_reaction + /// [`Message`]: crate::types::Message + fn set_reaction(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::pin_chat_message`], + /// but can take in [`Message`] to pin it. + /// + /// [`Bot::pin_chat_message`]: crate::Bot::pin_chat_message + /// [`Message`]: crate::types::Message + fn pin(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::unpin_chat_message`], + /// but can take in [`Message`] to unpin it. + /// + /// [`Bot::unpin_chat_message`]: crate::Bot::unpin_chat_message + /// [`Message`]: crate::types::Message + fn unpin(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::edit_message_text`], + /// but can take in [`Message`] to edit it. + /// + /// [`Bot::edit_message_text`]: crate::Bot::edit_message_text + /// [`Message`]: crate::types::Message + fn edit_text(&self, message: &Message, text: T) -> JsonRequest + where + T: Into; + + /// This function is the same as [`Bot::edit_message_caption`], + /// but can take in [`Message`] to edit it. + /// + /// [`Bot::edit_message_caption`]: crate::Bot::edit_message_caption + /// [`Message`]: crate::types::Message + fn edit_caption(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::edit_message_media`], + /// but can take in [`Message`] to edit it. + /// + /// [`Bot::edit_message_media`]: crate::Bot::edit_message_media + /// [`Message`]: crate::types::Message + fn edit_media( + &self, + message: &Message, + media: InputMedia, + ) -> MultipartRequest; + + /// This function is the same as [`Bot::edit_message_reply_markup`], + /// but can take in [`Message`] to edit it. + /// + /// [`Bot::edit_message_reply_markup`]: crate::Bot::edit_message_reply_markup + /// [`Message`]: crate::types::Message + fn edit_reply_markup(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::stop_poll`], + /// but can take in [`Message`] to stop the poll in it. + /// + /// [`Bot::stop_poll`]: crate::Bot::stop_poll + /// [`Message`]: crate::types::Message + fn stop_poll_message(&self, message: &Message) -> JsonRequest; + + /// This function is the same as [`Bot::delete_message`], + /// but can take in [`Message`] to delete it. + /// + /// [`Bot::delete_message`]: crate::Bot::delete_message + /// [`Message`]: crate::types::Message + fn delete(&self, message: &Message) -> JsonRequest; + /// This function is the same as [`Bot::copy_message`], /// but can take in [`Message`] to copy it. /// @@ -25,13 +116,6 @@ pub trait BotMessagesExt { fn copy(&self, to_chat_id: C, message: &Message) -> JsonRequest where C: Into; - - /// This function is the same as [`Bot::delete_message`], - /// but can take in [`Message`] to delete it. - /// - /// [`Bot::delete_message`]: crate::Bot::delete_message - /// [`Message`]: crate::types::Message - fn delete(&self, message: &Message) -> JsonRequest; } impl BotMessagesExt for Bot { @@ -41,6 +125,61 @@ impl BotMessagesExt for Bot { { self.forward_message(to_chat_id, message.chat.id, message.id) } + fn edit_live_location( + &self, + message: &Message, + latitude: f64, + longitude: f64, + ) -> JsonRequest { + self.edit_message_live_location(message.chat.id, message.id, latitude, longitude) + } + + fn stop_live_location(&self, message: &Message) -> JsonRequest { + self.stop_message_live_location(message.chat.id, message.id) + } + + fn set_reaction(&self, message: &Message) -> JsonRequest { + self.set_message_reaction(message.chat.id, message.id) + } + + fn pin(&self, message: &Message) -> JsonRequest { + self.pin_chat_message(message.chat.id, message.id) + } + + fn unpin(&self, message: &Message) -> JsonRequest { + self.unpin_chat_message(message.chat.id).message_id(message.id) + } + + fn edit_text(&self, message: &Message, text: T) -> JsonRequest + where + T: Into, + { + self.edit_message_text(message.chat.id, message.id, text) + } + + fn edit_caption(&self, message: &Message) -> JsonRequest { + self.edit_message_caption(message.chat.id, message.id) + } + + fn edit_media( + &self, + message: &Message, + media: InputMedia, + ) -> MultipartRequest { + self.edit_message_media(message.chat.id, message.id, media) + } + + fn edit_reply_markup(&self, message: &Message) -> JsonRequest { + self.edit_message_reply_markup(message.chat.id, message.id) + } + + fn stop_poll_message(&self, message: &Message) -> JsonRequest { + self.stop_poll(message.chat.id, message.id) + } + + fn delete(&self, message: &Message) -> JsonRequest { + self.delete_message(message.chat.id, message.id) + } fn copy(&self, to_chat_id: C, message: &Message) -> JsonRequest where @@ -48,10 +187,6 @@ impl BotMessagesExt for Bot { { self.copy_message(to_chat_id, message.chat.id, message.id) } - - fn delete(&self, message: &Message) -> JsonRequest { - self.delete_message(message.chat.id, message.id) - } } #[cfg(test)] @@ -129,45 +264,139 @@ pub(crate) mod tests { } } + const TO_CHAT_ID: ChatId = ChatId(12345); + const FROM_CHAT_ID: ChatId = ChatId(6789); + const CHAT_ID: ChatId = ChatId(12345); + const MESSAGE_ID: MessageId = MessageId(100); + #[test] fn test_forward() { let bot = Bot::new("TOKEN"); - let to_chat_id = ChatId(12345); - let from_chat_id = ChatId(6789); - let message_id = MessageId(100); + let sugar_req = bot.forward(TO_CHAT_ID, &make_message(FROM_CHAT_ID, MESSAGE_ID)); + let real_req = bot.forward_message(TO_CHAT_ID, FROM_CHAT_ID, MESSAGE_ID); - let sugar_forward_req = bot.forward(to_chat_id, &make_message(from_chat_id, message_id)); - let real_forward_req = bot.forward_message(to_chat_id, from_chat_id, message_id); - - assert_eq!(sugar_forward_req.deref(), real_forward_req.deref()) + assert_eq!(sugar_req.deref(), real_req.deref()) } #[test] - fn test_copy() { + fn test_edit_live_location() { let bot = Bot::new("TOKEN"); - let to_chat_id = ChatId(12345); - let from_chat_id = ChatId(6789); - let message_id = MessageId(100); + let longitude = 1.0; + let latitude = 1.0; - let sugar_copy_req = bot.copy(to_chat_id, &make_message(from_chat_id, message_id)); - let real_copy_req = bot.copy_message(to_chat_id, from_chat_id, message_id); + let sugar_req = + bot.edit_live_location(&make_message(CHAT_ID, MESSAGE_ID), latitude, longitude); + let real_req = bot.edit_message_live_location(CHAT_ID, MESSAGE_ID, latitude, longitude); + assert_eq!(sugar_req.deref(), real_req.deref()) + } - assert_eq!(sugar_copy_req.deref(), real_copy_req.deref()) + #[test] + fn test_stop_live_location() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.stop_live_location(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.stop_message_live_location(CHAT_ID, MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_set_reaction() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.set_reaction(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.set_message_reaction(CHAT_ID, MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_pin() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.pin(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.pin_chat_message(CHAT_ID, MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_unpin() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.unpin(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.unpin_chat_message(CHAT_ID).message_id(MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_edit_text() { + let bot = Bot::new("TOKEN"); + + let text = "text"; + + let sugar_req = bot.edit_text(&make_message(CHAT_ID, MESSAGE_ID), text); + let real_req = bot.edit_message_text(CHAT_ID, MESSAGE_ID, text); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_edit_caption() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.edit_caption(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.edit_message_caption(CHAT_ID, MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_edit_media() { + let bot = Bot::new("TOKEN"); + + let media = + InputMedia::Document(InputMediaDocument::new(InputFile::memory("Hello World!"))); + + let sugar_req = bot.edit_media(&make_message(CHAT_ID, MESSAGE_ID), media.clone()); + let real_req = bot.edit_message_media(CHAT_ID, MESSAGE_ID, media); + assert_eq!(sugar_req.deref().chat_id, real_req.deref().chat_id); + assert_eq!(sugar_req.deref().message_id, real_req.deref().message_id); + } + + #[test] + fn test_edit_reply_markup() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.edit_reply_markup(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.edit_message_reply_markup(CHAT_ID, MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) + } + + #[test] + fn test_stop_poll_message() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.stop_poll_message(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.stop_poll(CHAT_ID, MESSAGE_ID); + assert_eq!(sugar_req.deref(), real_req.deref()) } #[test] fn test_delete() { let bot = Bot::new("TOKEN"); - let chat_id = ChatId(6789); - let message_id = MessageId(100); + let sugar_req = bot.delete(&make_message(CHAT_ID, MESSAGE_ID)); + let real_req = bot.delete_message(CHAT_ID, MESSAGE_ID); - let sugar_delete_req = bot.delete(&make_message(chat_id, message_id)); - let real_delete_req = bot.delete_message(chat_id, message_id); + assert_eq!(sugar_req.deref(), real_req.deref()) + } - assert_eq!(sugar_delete_req.deref(), real_delete_req.deref()) + #[test] + fn test_copy() { + let bot = Bot::new("TOKEN"); + + let sugar_req = bot.copy(TO_CHAT_ID, &make_message(FROM_CHAT_ID, MESSAGE_ID)); + let real_req = bot.copy_message(TO_CHAT_ID, FROM_CHAT_ID, MESSAGE_ID); + + assert_eq!(sugar_req.deref(), real_req.deref()) } #[test] From 6e484382a9f422d600807f2231d631c85288cf99 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 23 Sep 2024 02:46:09 +0300 Subject: [PATCH 26/38] Added sugar to buttons.rs example --- crates/teloxide/examples/buttons.rs | 9 +++++---- crates/teloxide/src/sugar/bot.rs | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/teloxide/examples/buttons.rs b/crates/teloxide/examples/buttons.rs index daa538c2..9f188915 100644 --- a/crates/teloxide/examples/buttons.rs +++ b/crates/teloxide/examples/buttons.rs @@ -2,6 +2,7 @@ use std::error::Error; use teloxide::{ payloads::SendMessageSetters, prelude::*, + sugar::bot::BotMessagesExt, types::{ InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, InputMessageContent, InputMessageContentText, Me, @@ -107,17 +108,17 @@ async fn inline_query_handler( /// **IMPORTANT**: do not send privacy-sensitive data this way!!! /// Anyone can read data stored in the callback button. async fn callback_handler(bot: Bot, q: CallbackQuery) -> Result<(), Box> { - if let Some(version) = q.data { + if let Some(ref version) = q.data { let text = format!("You chose: {version}"); // Tell telegram that we've seen this query, to remove 🕑 icons from the // clients. You could also use `answer_callback_query`'s optional // parameters to tweak what happens on the client side. - bot.answer_callback_query(q.id).await?; + bot.answer_callback_query(&q.id).await?; // Edit text of the message to which the buttons were attached - if let Some(message) = q.message { - bot.edit_message_text(message.chat().id, message.id(), text).await?; + if let Some(message) = q.regular_message() { + bot.edit_text(message, text).await?; } else if let Some(id) = q.inline_message_id { bot.edit_message_text_inline(id, text).await?; } diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index bd0242f0..801cabe6 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -125,6 +125,7 @@ impl BotMessagesExt for Bot { { self.forward_message(to_chat_id, message.chat.id, message.id) } + fn edit_live_location( &self, message: &Message, From 2e7cd550575a378a4aa41a6e3d4f96f34d635d46 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 23 Sep 2024 11:41:07 +0300 Subject: [PATCH 27/38] Deleted unnecessary tests --- crates/teloxide/src/sugar/bot.rs | 219 ------------------------------- 1 file changed, 219 deletions(-) diff --git a/crates/teloxide/src/sugar/bot.rs b/crates/teloxide/src/sugar/bot.rs index 801cabe6..c1e4f0cd 100644 --- a/crates/teloxide/src/sugar/bot.rs +++ b/crates/teloxide/src/sugar/bot.rs @@ -189,222 +189,3 @@ impl BotMessagesExt for Bot { self.copy_message(to_chat_id, message.chat.id, message.id) } } - -#[cfg(test)] -pub(crate) mod tests { - use std::ops::Deref; - - use chrono::DateTime; - - use super::*; - - pub(crate) fn make_message(chat_id: ChatId, message_id: MessageId) -> Message { - let timestamp = 1_569_518_829; - let date = DateTime::from_timestamp(timestamp, 0).unwrap(); - Message { - via_bot: None, - id: message_id, - thread_id: None, - from: Some(User { - id: UserId(109_998_024), - is_bot: false, - first_name: String::from("Laster"), - last_name: None, - username: Some(String::from("laster_alex")), - language_code: Some(String::from("en")), - is_premium: false, - added_to_attachment_menu: false, - }), - sender_chat: None, - is_topic_message: false, - sender_business_bot: None, - date, - chat: Chat { - id: chat_id, - kind: ChatKind::Private(ChatPrivate { - username: Some(String::from("Laster")), - first_name: Some(String::from("laster_alex")), - last_name: None, - bio: None, - has_private_forwards: None, - has_restricted_voice_and_video_messages: None, - business_intro: None, - business_location: None, - business_opening_hours: None, - birthdate: None, - personal_chat: None, - }), - photo: None, - available_reactions: None, - pinned_message: None, - message_auto_delete_time: None, - has_hidden_members: false, - has_aggressive_anti_spam_enabled: false, - chat_full_info: ChatFullInfo::default(), - }, - kind: MessageKind::Common(MessageCommon { - reply_to_message: None, - forward_origin: None, - external_reply: None, - quote: None, - edit_date: None, - media_kind: MediaKind::Text(MediaText { - text: "text".to_owned(), - entities: vec![], - link_preview_options: None, - }), - reply_markup: None, - author_signature: None, - is_automatic_forward: false, - has_protected_content: false, - reply_to_story: None, - sender_boost_count: None, - is_from_offline: false, - business_connection_id: None, - }), - } - } - - const TO_CHAT_ID: ChatId = ChatId(12345); - const FROM_CHAT_ID: ChatId = ChatId(6789); - const CHAT_ID: ChatId = ChatId(12345); - const MESSAGE_ID: MessageId = MessageId(100); - - #[test] - fn test_forward() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.forward(TO_CHAT_ID, &make_message(FROM_CHAT_ID, MESSAGE_ID)); - let real_req = bot.forward_message(TO_CHAT_ID, FROM_CHAT_ID, MESSAGE_ID); - - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_edit_live_location() { - let bot = Bot::new("TOKEN"); - - let longitude = 1.0; - let latitude = 1.0; - - let sugar_req = - bot.edit_live_location(&make_message(CHAT_ID, MESSAGE_ID), latitude, longitude); - let real_req = bot.edit_message_live_location(CHAT_ID, MESSAGE_ID, latitude, longitude); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_stop_live_location() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.stop_live_location(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.stop_message_live_location(CHAT_ID, MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_set_reaction() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.set_reaction(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.set_message_reaction(CHAT_ID, MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_pin() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.pin(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.pin_chat_message(CHAT_ID, MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_unpin() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.unpin(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.unpin_chat_message(CHAT_ID).message_id(MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_edit_text() { - let bot = Bot::new("TOKEN"); - - let text = "text"; - - let sugar_req = bot.edit_text(&make_message(CHAT_ID, MESSAGE_ID), text); - let real_req = bot.edit_message_text(CHAT_ID, MESSAGE_ID, text); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_edit_caption() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.edit_caption(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.edit_message_caption(CHAT_ID, MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_edit_media() { - let bot = Bot::new("TOKEN"); - - let media = - InputMedia::Document(InputMediaDocument::new(InputFile::memory("Hello World!"))); - - let sugar_req = bot.edit_media(&make_message(CHAT_ID, MESSAGE_ID), media.clone()); - let real_req = bot.edit_message_media(CHAT_ID, MESSAGE_ID, media); - assert_eq!(sugar_req.deref().chat_id, real_req.deref().chat_id); - assert_eq!(sugar_req.deref().message_id, real_req.deref().message_id); - } - - #[test] - fn test_edit_reply_markup() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.edit_reply_markup(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.edit_message_reply_markup(CHAT_ID, MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_stop_poll_message() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.stop_poll_message(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.stop_poll(CHAT_ID, MESSAGE_ID); - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_delete() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.delete(&make_message(CHAT_ID, MESSAGE_ID)); - let real_req = bot.delete_message(CHAT_ID, MESSAGE_ID); - - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn test_copy() { - let bot = Bot::new("TOKEN"); - - let sugar_req = bot.copy(TO_CHAT_ID, &make_message(FROM_CHAT_ID, MESSAGE_ID)); - let real_req = bot.copy_message(TO_CHAT_ID, FROM_CHAT_ID, MESSAGE_ID); - - assert_eq!(sugar_req.deref(), real_req.deref()) - } - - #[test] - fn message_to_message_id() { - // Just to make sure message still can be in Into - let message = make_message(ChatId(1), MessageId(1)); - let message_id: MessageId = message.into(); - assert_eq!(message_id, MessageId(1)); - } -} From d58268558afc0c72f7c78f1b25b7e2541e3104bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 08:51:55 +0000 Subject: [PATCH 28/38] Bump the lock group across 1 directory with 45 updates Bumps the lock group with 33 updates in the / directory: | Package | From | To | | --- | --- | --- | | [serde_json](https://github.com/serde-rs/json) | `1.0.127` | `1.0.128` | | [serde](https://github.com/serde-rs/serde) | `1.0.209` | `1.0.210` | | [tokio-util](https://github.com/tokio-rs/tokio) | `0.7.11` | `0.7.12` | | [tokio-stream](https://github.com/tokio-rs/tokio) | `0.1.15` | `0.1.16` | | [bytes](https://github.com/tokio-rs/bytes) | `1.7.1` | `1.7.2` | | [thiserror](https://github.com/dtolnay/thiserror) | `1.0.63` | `1.0.64` | | [sqlx](https://github.com/launchbadge/sqlx) | `0.8.1` | `0.8.2` | | [tower](https://github.com/tower-rs/tower) | `0.5.0` | `0.5.1` | | [bitflags](https://github.com/bitflags/bitflags) | `1.3.2` | `2.4.2` | | [aho-corasick](https://github.com/BurntSushi/aho-corasick) | `0.7.20` | `1.1.2` | | [pretty_assertions](https://github.com/rust-pretty-assertions/rust-pretty-assertions) | `1.4.0` | `1.4.1` | | [syn](https://github.com/dtolnay/syn) | `1.0.109` | `2.0.52` | | [axum-core](https://github.com/tokio-rs/axum) | `0.4.3` | `0.4.4` | | [backtrace](https://github.com/rust-lang/backtrace-rs) | `0.3.73` | `0.3.74` | | [bytemuck](https://github.com/Lokathor/bytemuck) | `1.17.1` | `1.18.0` | | [cc](https://github.com/rust-lang/cc-rs) | `1.1.15` | `1.1.21` | | [cpufeatures](https://github.com/RustCrypto/utils) | `0.2.13` | `0.2.14` | | [hyper-rustls](https://github.com/rustls/hyper-rustls) | `0.27.2` | `0.27.3` | | [hyper-util](https://github.com/hyperium/hyper-util) | `0.1.7` | `0.1.8` | | [iana-time-zone](https://github.com/strawlab/iana-time-zone) | `0.1.60` | `0.1.61` | | [ipnet](https://github.com/krisprice/ipnet) | `2.9.0` | `2.10.0` | | [parking](https://github.com/smol-rs/parking) | `2.2.0` | `2.2.1` | | [quinn](https://github.com/quinn-rs/quinn) | `0.11.3` | `0.11.5` | | [quinn-udp](https://github.com/quinn-rs/quinn) | `0.5.4` | `0.5.5` | | [rustix](https://github.com/bytecodealliance/rustix) | `0.38.35` | `0.38.37` | | [rustls](https://github.com/rustls/rustls) | `0.23.12` | `0.23.13` | | [schannel](https://github.com/steffengy/schannel-rs) | `0.1.23` | `0.1.24` | | [security-framework-sys](https://github.com/kornelski/rust-security-framework) | `2.11.1` | `2.12.0` | | [sqlformat](https://github.com/shssoichiro/sqlformat-rs) | `0.2.4` | `0.2.6` | | [unicode-ident](https://github.com/dtolnay/unicode-ident) | `1.0.12` | `1.0.13` | | [unicode-normalization](https://github.com/unicode-rs/unicode-normalization) | `0.1.23` | `0.1.24` | | [webpki-roots](https://github.com/rustls/webpki-roots) | `0.26.5` | `0.26.6` | | [whoami](https://github.com/ardaku/whoami) | `1.5.1` | `1.5.2` | Updates `serde_json` from 1.0.127 to 1.0.128 - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/1.0.127...1.0.128) Updates `serde` from 1.0.209 to 1.0.210 - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.209...v1.0.210) Updates `tokio-util` from 0.7.11 to 0.7.12 - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-util-0.7.11...tokio-util-0.7.12) Updates `tokio-stream` from 0.1.15 to 0.1.16 - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-stream-0.1.15...tokio-stream-0.1.16) Updates `bytes` from 1.7.1 to 1.7.2 - [Release notes](https://github.com/tokio-rs/bytes/releases) - [Changelog](https://github.com/tokio-rs/bytes/blob/master/CHANGELOG.md) - [Commits](https://github.com/tokio-rs/bytes/compare/v1.7.1...v1.7.2) Updates `thiserror` from 1.0.63 to 1.0.64 - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](https://github.com/dtolnay/thiserror/compare/1.0.63...1.0.64) Updates `sqlx` from 0.8.1 to 0.8.2 - [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md) - [Commits](https://github.com/launchbadge/sqlx/compare/v0.8.1...v0.8.2) Updates `tower` from 0.5.0 to 0.5.1 - [Release notes](https://github.com/tower-rs/tower/releases) - [Commits](https://github.com/tower-rs/tower/compare/tower-0.5.0...tower-0.5.1) Updates `bitflags` from 1.3.2 to 2.4.2 - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](https://github.com/bitflags/bitflags/compare/1.3.2...2.4.2) Updates `aho-corasick` from 0.7.20 to 1.1.2 - [Commits](https://github.com/BurntSushi/aho-corasick/compare/0.7.20...1.1.2) Updates `pretty_assertions` from 1.4.0 to 1.4.1 - [Release notes](https://github.com/rust-pretty-assertions/rust-pretty-assertions/releases) - [Changelog](https://github.com/rust-pretty-assertions/rust-pretty-assertions/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-pretty-assertions/rust-pretty-assertions/compare/v1.4.0...v1.4.1) Updates `syn` from 1.0.109 to 2.0.52 - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.109...2.0.52) Updates `axum-core` from 0.4.3 to 0.4.4 - [Release notes](https://github.com/tokio-rs/axum/releases) - [Changelog](https://github.com/tokio-rs/axum/blob/main/CHANGELOG.md) - [Commits](https://github.com/tokio-rs/axum/compare/axum-core-v0.4.3...axum-core-v0.4.4) Updates `backtrace` from 0.3.73 to 0.3.74 - [Release notes](https://github.com/rust-lang/backtrace-rs/releases) - [Commits](https://github.com/rust-lang/backtrace-rs/compare/0.3.73...0.3.74) Updates `bytemuck` from 1.17.1 to 1.18.0 - [Changelog](https://github.com/Lokathor/bytemuck/blob/main/changelog.md) - [Commits](https://github.com/Lokathor/bytemuck/compare/v1.17.1...v1.18.0) Updates `cc` from 1.1.15 to 1.1.21 - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.15...cc-v1.1.21) Updates `cpufeatures` from 0.2.13 to 0.2.14 - [Commits](https://github.com/RustCrypto/utils/compare/cpufeatures-v0.2.13...cpufeatures-v0.2.14) Updates `gimli` from 0.29.0 to 0.31.0 - [Changelog](https://github.com/gimli-rs/gimli/blob/master/CHANGELOG.md) - [Commits](https://github.com/gimli-rs/gimli/compare/0.29.0...0.31.0) Updates `hyper-rustls` from 0.27.2 to 0.27.3 - [Release notes](https://github.com/rustls/hyper-rustls/releases) - [Commits](https://github.com/rustls/hyper-rustls/compare/v/0.27.2...v/0.27.3) Updates `hyper-util` from 0.1.7 to 0.1.8 - [Release notes](https://github.com/hyperium/hyper-util/releases) - [Changelog](https://github.com/hyperium/hyper-util/blob/master/CHANGELOG.md) - [Commits](https://github.com/hyperium/hyper-util/compare/v0.1.7...v0.1.8) Updates `iana-time-zone` from 0.1.60 to 0.1.61 - [Changelog](https://github.com/strawlab/iana-time-zone/blob/main/CHANGELOG.md) - [Commits](https://github.com/strawlab/iana-time-zone/compare/v0.1.60...v0.1.61) Updates `ipnet` from 2.9.0 to 2.10.0 - [Release notes](https://github.com/krisprice/ipnet/releases) - [Changelog](https://github.com/krisprice/ipnet/blob/master/RELEASES.md) - [Commits](https://github.com/krisprice/ipnet/compare/2.9.0...2.10.0) Updates `miniz_oxide` from 0.7.4 to 0.8.0 - [Changelog](https://github.com/Frommi/miniz_oxide/blob/master/CHANGELOG.md) - [Commits](https://github.com/Frommi/miniz_oxide/compare/0.7.4...0.8.0) Updates `parking` from 2.2.0 to 2.2.1 - [Release notes](https://github.com/smol-rs/parking/releases) - [Changelog](https://github.com/smol-rs/parking/blob/master/CHANGELOG.md) - [Commits](https://github.com/smol-rs/parking/compare/v2.2.0...v2.2.1) Updates `quinn` from 0.11.3 to 0.11.5 - [Release notes](https://github.com/quinn-rs/quinn/releases) - [Commits](https://github.com/quinn-rs/quinn/compare/quinn-0.11.3...quinn-0.11.5) Updates `quinn-udp` from 0.5.4 to 0.5.5 - [Release notes](https://github.com/quinn-rs/quinn/releases) - [Commits](https://github.com/quinn-rs/quinn/compare/quinn-udp-0.5.4...quinn-udp-0.5.5) Updates `rustix` from 0.38.35 to 0.38.37 - [Release notes](https://github.com/bytecodealliance/rustix/releases) - [Changelog](https://github.com/bytecodealliance/rustix/blob/main/CHANGELOG.md) - [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.35...v0.38.37) Updates `rustls` from 0.23.12 to 0.23.13 - [Release notes](https://github.com/rustls/rustls/releases) - [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustls/rustls/compare/v/0.23.12...v/0.23.13) Updates `rustls-webpki` from 0.102.7 to 0.102.8 - [Release notes](https://github.com/rustls/webpki/releases) - [Commits](https://github.com/rustls/webpki/compare/v/0.102.7...v/0.102.8) Updates `schannel` from 0.1.23 to 0.1.24 - [Release notes](https://github.com/steffengy/schannel-rs/releases) - [Commits](https://github.com/steffengy/schannel-rs/compare/v0.1.23...v0.1.24) Updates `security-framework-sys` from 2.11.1 to 2.12.0 - [Release notes](https://github.com/kornelski/rust-security-framework/releases) - [Commits](https://github.com/kornelski/rust-security-framework/commits) Updates `serde_derive` from 1.0.209 to 1.0.210 - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.209...v1.0.210) Updates `sqlformat` from 0.2.4 to 0.2.6 - [Release notes](https://github.com/shssoichiro/sqlformat-rs/releases) - [Changelog](https://github.com/shssoichiro/sqlformat-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/shssoichiro/sqlformat-rs/compare/v0.2.4...v0.2.6) Updates `sqlx-core` from 0.8.1 to 0.8.2 - [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md) - [Commits](https://github.com/launchbadge/sqlx/compare/v0.8.1...v0.8.2) Updates `sqlx-macros` from 0.8.1 to 0.8.2 - [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md) - [Commits](https://github.com/launchbadge/sqlx/compare/v0.8.1...v0.8.2) Updates `sqlx-macros-core` from 0.8.1 to 0.8.2 - [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md) - [Commits](https://github.com/launchbadge/sqlx/compare/v0.8.1...v0.8.2) Updates `sqlx-postgres` from 0.8.1 to 0.8.2 - [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md) - [Commits](https://github.com/launchbadge/sqlx/compare/v0.8.1...v0.8.2) Updates `sqlx-sqlite` from 0.8.1 to 0.8.2 - [Changelog](https://github.com/launchbadge/sqlx/blob/main/CHANGELOG.md) - [Commits](https://github.com/launchbadge/sqlx/compare/v0.8.1...v0.8.2) Updates `sync_wrapper` from 0.1.2 to 1.0.1 - [Commits](https://github.com/Actyx/sync_wrapper/compare/v0.1.2...v1.0.1) Updates `thiserror-impl` from 1.0.63 to 1.0.64 - [Release notes](https://github.com/dtolnay/thiserror/releases) - [Commits](https://github.com/dtolnay/thiserror/compare/1.0.63...1.0.64) Updates `unicode-ident` from 1.0.12 to 1.0.13 - [Release notes](https://github.com/dtolnay/unicode-ident/releases) - [Commits](https://github.com/dtolnay/unicode-ident/compare/1.0.12...1.0.13) Updates `unicode-normalization` from 0.1.23 to 0.1.24 - [Commits](https://github.com/unicode-rs/unicode-normalization/compare/v0.1.23...v0.1.24) Updates `webpki-roots` from 0.26.5 to 0.26.6 - [Release notes](https://github.com/rustls/webpki-roots/releases) - [Commits](https://github.com/rustls/webpki-roots/compare/v/0.26.5...v/0.26.6) Updates `whoami` from 1.5.1 to 1.5.2 - [Changelog](https://github.com/ardaku/whoami/blob/v1/CHANGELOG.md) - [Commits](https://github.com/ardaku/whoami/compare/v1.5.1...v1.5.2) Updates `yansi` from 0.5.1 to 1.0.1 - [Release notes](https://github.com/SergioBenitez/yansi/releases) - [Commits](https://github.com/SergioBenitez/yansi/commits/v1.0.1) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: tokio-util dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: tokio-stream dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: bytes dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: thiserror dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlx dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: tower dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: bitflags dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: aho-corasick dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: pretty_assertions dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: axum-core dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: backtrace dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: bytemuck dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: cc dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: cpufeatures dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: gimli dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: hyper-rustls dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: hyper-util dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: iana-time-zone dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: ipnet dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: miniz_oxide dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: parking dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: quinn dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: quinn-udp dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustix dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls-webpki dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: schannel dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: security-framework-sys dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: serde_derive dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlformat dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlx-core dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlx-macros dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlx-macros-core dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlx-postgres dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sqlx-sqlite dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: sync_wrapper dependency-type: indirect update-type: version-update:semver-major dependency-group: lock - dependency-name: thiserror-impl dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: unicode-ident dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: unicode-normalization dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: webpki-roots dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: whoami dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: yansi dependency-type: indirect update-type: version-update:semver-major dependency-group: lock ... Signed-off-by: dependabot[bot] --- Cargo.lock | 226 ++++++++++++++++++++++++++--------------------------- 1 file changed, 112 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c230550..e2c8ce76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,18 +4,18 @@ version = 3 [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "ahash" @@ -140,7 +140,7 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper", "tokio", "tower 0.4.13", "tower-layer", @@ -150,9 +150,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +checksum = "5e6b8ba012a258d63c9adfa28b9ddcf66149da6f986c5b5452e629d5ee64bf00" dependencies = [ "async-trait", "bytes", @@ -163,7 +163,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 0.1.2", + "sync_wrapper", "tower-layer", "tower-service", "tracing", @@ -171,17 +171,17 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", + "windows-targets 0.52.6", ] [[package]] @@ -237,9 +237,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773d90827bc3feecfb67fab12e24de0749aad83c74b9504ecde46237b5cd24e2" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" [[package]] name = "byteorder" @@ -249,15 +249,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.15" +version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ "shlex", ] @@ -338,9 +338,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -745,9 +745,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "h2" @@ -931,16 +931,16 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.2" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", "http", "hyper", "hyper-util", "rustls", - "rustls-native-certs", + "rustls-native-certs 0.8.0", "rustls-pki-types", "tokio", "tokio-rustls", @@ -966,9 +966,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" dependencies = [ "bytes", "futures-channel", @@ -986,9 +986,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1071,9 +1071,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" [[package]] name = "is-terminal" @@ -1195,11 +1195,11 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "adler", + "adler2", ] [[package]] @@ -1321,9 +1321,9 @@ dependencies = [ [[package]] name = "parking" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" @@ -1343,7 +1343,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.2", + "redox_syscall", "smallvec", "windows-targets 0.52.6", ] @@ -1409,9 +1409,9 @@ dependencies = [ [[package]] name = "pretty_assertions" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", "yansi", @@ -1462,9 +1462,9 @@ dependencies = [ [[package]] name = "quinn" -version = "0.11.3" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" dependencies = [ "bytes", "pin-project-lite", @@ -1497,15 +1497,15 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" dependencies = [ "libc", "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1575,15 +1575,6 @@ dependencies = [ "url", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.5.2" @@ -1652,13 +1643,13 @@ dependencies = [ "pin-project-lite", "quinn", "rustls", - "rustls-native-certs", + "rustls-native-certs 0.7.3", "rustls-pemfile", "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper", "system-configuration", "tokio", "tokio-native-tls", @@ -1733,9 +1724,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.35" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.4.2", "errno", @@ -1746,9 +1737,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "once_cell", "ring", @@ -1771,6 +1762,19 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rustls-native-certs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcaf18a4f2be7326cd874a5fa579fae794320a0f388d365dca7e480e55f83f8a" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "2.1.3" @@ -1789,9 +1793,9 @@ checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" -version = "0.102.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring", "rustls-pki-types", @@ -1812,11 +1816,11 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1840,9 +1844,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -1856,9 +1860,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -1875,9 +1879,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -1886,9 +1890,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -2005,9 +2009,9 @@ dependencies = [ [[package]] name = "sqlformat" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f895e3734318cc55f1fe66258926c9b910c124d47520339efecbb6c59cec7c1f" +checksum = "7bba3a93db0cc4f7bdece8bb09e77e2e785c20bfebf79eb8340ed80708048790" dependencies = [ "nom", "unicode_categories", @@ -2015,9 +2019,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcfa89bea9500db4a0d038513d7a060566bfc51d46d1c014847049a45cce85e8" +checksum = "93334716a037193fac19df402f8571269c84a00852f6a7066b5d2616dcd64d3e" dependencies = [ "sqlx-core", "sqlx-macros", @@ -2027,9 +2031,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06e2f2bd861719b1f3f0c7dbe1d80c30bf59e76cf019f07d9014ed7eefb8e08" +checksum = "d4d8060b456358185f7d50c55d9b5066ad956956fddec42ee2e8567134a8936e" dependencies = [ "atoi", "byteorder", @@ -2070,9 +2074,9 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f998a9defdbd48ed005a89362bd40dd2117502f15294f61c8d47034107dbbdc" +checksum = "cac0692bcc9de3b073e8d747391827297e075c7710ff6276d9f7a1f3d58c6657" dependencies = [ "proc-macro2", "quote", @@ -2083,9 +2087,9 @@ dependencies = [ [[package]] name = "sqlx-macros-core" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d100558134176a2629d46cec0c8891ba0be8910f7896abfdb75ef4ab6f4e7ce" +checksum = "1804e8a7c7865599c9c79be146dc8a9fd8cc86935fa641d3ea58e5f0688abaa5" dependencies = [ "dotenvy", "either", @@ -2108,9 +2112,9 @@ dependencies = [ [[package]] name = "sqlx-postgres" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9734dbce698c67ecf67c442f768a5e90a49b2a4d61a9f1d59f73874bd4cf0710" +checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8" dependencies = [ "atoi", "base64 0.22.1", @@ -2146,9 +2150,9 @@ dependencies = [ [[package]] name = "sqlx-sqlite" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75b419c3c1b1697833dd927bdc4c6545a620bc1bbafabd44e1efbe9afcd337e" +checksum = "d5b2cf34a45953bfd3daaf3db0f7a7878ab9b7a6b91b422d24a7a9e4c857b680" dependencies = [ "atoi", "flume", @@ -2212,12 +2216,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sync_wrapper" version = "1.0.1" @@ -2290,7 +2288,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-util", - "tower 0.5.0", + "tower 0.5.1", "tower-http", "url", ] @@ -2379,18 +2377,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -2463,9 +2461,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -2474,9 +2472,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", @@ -2503,9 +2501,9 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36b837f86b25d7c0d7988f00a54e74739be6477f2aac6201b8f429a7569991b7" +checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" dependencies = [ "tower-layer", "tower-service", @@ -2601,15 +2599,15 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] @@ -2784,20 +2782,20 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] [[package]] name = "whoami" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" +checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d" dependencies = [ - "redox_syscall 0.4.1", + "redox_syscall", "wasite", ] @@ -3014,9 +3012,9 @@ checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852" [[package]] name = "yansi" -version = "0.5.1" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" From 67cba5a1d6f3ad2f8a4f195014f3f16e0425264b Mon Sep 17 00:00:00 2001 From: Tima Kinsart Date: Mon, 23 Sep 2024 16:48:27 -0400 Subject: [PATCH 29/38] Refactor `CHANGELOG.md` --- CHANGELOG.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dac415f1..ab2c37d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,15 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Add `filter_boost_added` and `filter_reply_to_story` filters to `MessageFilterExt` trait -- Add `filter_mention_command` filter to `HandlerExt` trait ([issue #494](https://github.com/teloxide/teloxide/issues/494)) -- Add `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to update filters ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) -- Add `bot.forward`, `bot.edit_live_location`, `bot.stop_live_location`, `bot.set_reaction`, `bot.pin`, `bot.unpin`, `bot.edit_text`, `bot.edit_caption`, `bot.edit_media`, `bot.edit_reply_markup`, `bot.stop_poll_message`, `bot.delete` and `bot.copy` to new `crate::sugar::bot::BotMessagesExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) -- Add `.reply_to(message_id)` to new `crate::sugar::request::RequestReplyExt` trait, and `.disable_link_preview(is_disabled)` to new `crate::sugar::request::RequestLinkPreviewExt` trait ([issue #1143](https://github.com/teloxide/teloxide/issues/1143)) +- `filter_boost_added` and `filter_reply_to_story` filters to the `MessageFilterExt` trait ([PR 1131](https://github.com/teloxide/teloxide/pull/1131)) +- `filter_mention_command` filter to the `HandlerExt` trait ([issue 494](https://github.com/teloxide/teloxide/issues/494)) +- `filter_business_connection`, `filter_business_message`, `filter_edited_business_message`, and `filter_deleted_business_messages` filters to the `UpdateFilterExt` trait ([PR 1146](https://github.com/teloxide/teloxide/pull/1146)) +- Syntax sugar for making requests ([issue 1143](https://github.com/teloxide/teloxide/issues/1143)): + - `bot.forward`, `bot.edit_live_location`, `bot.stop_live_location`, `bot.set_reaction`, `bot.pin`, `bot.unpin`, `bot.edit_text`, `bot.edit_caption`, `bot.edit_media`, `bot.edit_reply_markup`, `bot.stop_poll_message`, `bot.delete` and `bot.copy` methods to the new `crate::sugar::bot::BotMessagesExt` trait + - `req.reply_to` method to the new `crate::sugar::request::RequestReplyExt` trait + - `req.disable_link_preview` method to the new `crate::sugar::request::RequestLinkPreviewExt` trait ### Changed -- Environment bumps: ([#1147][pr1147]) +- Environment bumps: ([PR 1147](https://github.com/teloxide/teloxide/pull/1147)) - MSRV (Minimal Supported Rust Version) was bumped from `1.70.0` to `1.80.0` - Some dependencies was bumped: `sqlx` to `0.8.1`, `tower` to `0.5.0`, `reqwest` to `0.12.7` - `tokio` version was explicitly specified as `1.39` @@ -25,8 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Now Vec in requests serializes into [number] instead of [ {message_id: number} ], `forward_messages`, `copy_messages` and `delete_messages` now work properly -[pr1147]: https://github.com/teloxide/teloxide/pull/1147 - ## 0.13.0 - 2024-08-16 ### Added From 6410417dac8a15dcab6e3304dd8efdb60ec1e54a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:10:41 +0000 Subject: [PATCH 30/38] Bump the lock group with 20 updates Bumps the lock group with 20 updates: | Package | From | To | | --- | --- | --- | | [axum](https://github.com/tokio-rs/axum) | `0.7.5` | `0.7.7` | | [once_cell](https://github.com/matklad/once_cell) | `1.19.0` | `1.20.1` | | [bitflags](https://github.com/bitflags/bitflags) | `1.3.2` | `2.4.2` | | [aho-corasick](https://github.com/BurntSushi/aho-corasick) | `0.7.20` | `1.1.2` | | [syn](https://github.com/dtolnay/syn) | `1.0.109` | `2.0.52` | | [async-trait](https://github.com/dtolnay/async-trait) | `0.1.82` | `0.1.83` | | [autocfg](https://github.com/cuviper/autocfg) | `1.3.0` | `1.4.0` | | [axum-core](https://github.com/tokio-rs/axum) | `0.4.4` | `0.4.5` | | [cc](https://github.com/rust-lang/cc-rs) | `1.1.21` | `1.1.22` | | [hyper-util](https://github.com/hyperium/hyper-util) | `0.1.8` | `0.1.9` | | [libc](https://github.com/rust-lang/libc) | `0.2.158` | `0.2.159` | | [pkg-config](https://github.com/rust-lang/pkg-config-rs) | `0.3.30` | `0.3.31` | | redox_syscall | `0.5.2` | `0.5.7` | | [regex](https://github.com/rust-lang/regex) | `1.10.6` | `1.11.0` | | [regex-automata](https://github.com/rust-lang/regex) | `0.4.7` | `0.4.8` | | [regex-syntax](https://github.com/rust-lang/regex) | `0.8.4` | `0.8.5` | | [rustls-pki-types](https://github.com/rustls/pki-types) | `1.8.0` | `1.9.0` | | [sync_wrapper](https://github.com/Actyx/sync_wrapper) | `1.0.1` | `0.1.2` | | [tempfile](https://github.com/Stebalien/tempfile) | `3.12.0` | `3.13.0` | | [wasm-streams](https://github.com/MattiasBuelens/wasm-streams) | `0.4.0` | `0.4.1` | Updates `axum` from 0.7.5 to 0.7.7 - [Release notes](https://github.com/tokio-rs/axum/releases) - [Changelog](https://github.com/tokio-rs/axum/blob/main/CHANGELOG.md) - [Commits](https://github.com/tokio-rs/axum/compare/axum-v0.7.5...axum-v0.7.7) Updates `once_cell` from 1.19.0 to 1.20.1 - [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md) - [Commits](https://github.com/matklad/once_cell/compare/v1.19.0...v1.20.1) Updates `bitflags` from 1.3.2 to 2.4.2 - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](https://github.com/bitflags/bitflags/compare/1.3.2...2.4.2) Updates `aho-corasick` from 0.7.20 to 1.1.2 - [Commits](https://github.com/BurntSushi/aho-corasick/compare/0.7.20...1.1.2) Updates `syn` from 1.0.109 to 2.0.52 - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.109...2.0.52) Updates `async-trait` from 0.1.82 to 0.1.83 - [Release notes](https://github.com/dtolnay/async-trait/releases) - [Commits](https://github.com/dtolnay/async-trait/compare/0.1.82...0.1.83) Updates `autocfg` from 1.3.0 to 1.4.0 - [Commits](https://github.com/cuviper/autocfg/compare/1.3.0...1.4.0) Updates `axum-core` from 0.4.4 to 0.4.5 - [Release notes](https://github.com/tokio-rs/axum/releases) - [Changelog](https://github.com/tokio-rs/axum/blob/main/CHANGELOG.md) - [Commits](https://github.com/tokio-rs/axum/compare/axum-core-v0.4.4...axum-core-v0.4.5) Updates `cc` from 1.1.21 to 1.1.22 - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.21...cc-v1.1.22) Updates `hyper-util` from 0.1.8 to 0.1.9 - [Release notes](https://github.com/hyperium/hyper-util/releases) - [Changelog](https://github.com/hyperium/hyper-util/blob/master/CHANGELOG.md) - [Commits](https://github.com/hyperium/hyper-util/compare/v0.1.8...v0.1.9) Updates `libc` from 0.2.158 to 0.2.159 - [Release notes](https://github.com/rust-lang/libc/releases) - [Changelog](https://github.com/rust-lang/libc/blob/0.2.159/CHANGELOG.md) - [Commits](https://github.com/rust-lang/libc/compare/0.2.158...0.2.159) Updates `pkg-config` from 0.3.30 to 0.3.31 - [Changelog](https://github.com/rust-lang/pkg-config-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/pkg-config-rs/compare/0.3.30...0.3.31) Updates `redox_syscall` from 0.5.2 to 0.5.7 Updates `regex` from 1.10.6 to 1.11.0 - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.10.6...1.11.0) Updates `regex-automata` from 0.4.7 to 0.4.8 - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/commits) Updates `regex-syntax` from 0.8.4 to 0.8.5 - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/commits) Updates `rustls-pki-types` from 1.8.0 to 1.9.0 - [Release notes](https://github.com/rustls/pki-types/releases) - [Commits](https://github.com/rustls/pki-types/compare/v/1.8.0...v/1.9.0) Updates `sync_wrapper` from 1.0.1 to 0.1.2 - [Commits](https://github.com/Actyx/sync_wrapper/compare/v1.0.1...v0.1.2) Updates `tempfile` from 3.12.0 to 3.13.0 - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](https://github.com/Stebalien/tempfile/compare/v3.12.0...v3.13.0) Updates `wasm-streams` from 0.4.0 to 0.4.1 - [Release notes](https://github.com/MattiasBuelens/wasm-streams/releases) - [Changelog](https://github.com/MattiasBuelens/wasm-streams/blob/main/CHANGELOG.md) - [Commits](https://github.com/MattiasBuelens/wasm-streams/compare/v0.4.0...v0.4.1) --- updated-dependencies: - dependency-name: axum dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: once_cell dependency-type: direct:production update-type: version-update:semver-minor dependency-group: lock - dependency-name: bitflags dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: aho-corasick dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: async-trait dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: autocfg dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: axum-core dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: cc dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: hyper-util dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: libc dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: pkg-config dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: redox_syscall dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: regex dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: regex-automata dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: regex-syntax dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls-pki-types dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: sync_wrapper dependency-type: indirect update-type: version-update:semver-major dependency-group: lock - dependency-name: tempfile dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: wasm-streams dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock ... Signed-off-by: dependabot[bot] --- Cargo.lock | 114 +++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2c8ce76..be87412e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,9 +84,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", @@ -110,15 +110,15 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axum" -version = "0.7.5" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +checksum = "504e3947307ac8326a5437504c517c4b56716c9d98fac0028c2acc7ca47d70ae" dependencies = [ "async-trait", "axum-core", @@ -140,9 +140,9 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.1", "tokio", - "tower 0.4.13", + "tower", "tower-layer", "tower-service", "tracing", @@ -150,9 +150,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6b8ba012a258d63c9adfa28b9ddcf66149da6f986c5b5452e629d5ee64bf00" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" dependencies = [ "async-trait", "bytes", @@ -163,7 +163,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper", + "sync_wrapper 1.0.1", "tower-layer", "tower-service", "tracing", @@ -255,9 +255,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.21" +version = "1.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" dependencies = [ "shlex", ] @@ -966,9 +966,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -979,7 +979,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower 0.4.13", "tower-service", "tracing", ] @@ -1112,9 +1111,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libsqlite3-sys" @@ -1271,9 +1270,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "openssl" @@ -1394,9 +1396,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "ppv-lite86" @@ -1577,18 +1585,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.2" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.4.2", ] [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick 1.1.2", "memchr", @@ -1598,9 +1606,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick 1.1.2", "memchr", @@ -1609,9 +1617,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" @@ -1649,7 +1657,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 1.0.1", "system-configuration", "tokio", "tokio-native-tls", @@ -1787,9 +1795,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-webpki" @@ -2216,6 +2224,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "sync_wrapper" version = "1.0.1" @@ -2288,7 +2302,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-util", - "tower 0.5.1", + "tower", "tower-http", "url", ] @@ -2355,9 +2369,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -2483,30 +2497,20 @@ dependencies = [ "tokio", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", - "tracing", -] - [[package]] name = "tower" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper 0.1.2", + "tokio", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -2759,9 +2763,9 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasm-streams" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129" +checksum = "4e072d4e72f700fb3443d8fe94a39315df013eef1104903cdb0a2abd322bbecd" dependencies = [ "futures-util", "js-sys", @@ -2805,7 +2809,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] From dad067da447f121df1392fe6032b0829380abfea Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 3 Oct 2024 12:35:53 +0330 Subject: [PATCH 31/38] removing useless Generic T on `selective`, adding tests --- .../src/types/reply_keyboard_markup.rs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/teloxide-core/src/types/reply_keyboard_markup.rs b/crates/teloxide-core/src/types/reply_keyboard_markup.rs index 4b38b2df..1c9c5935 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_markup.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_markup.rs @@ -125,7 +125,7 @@ impl KeyboardMarkup { /// Sets [`selective`] to `true`. /// /// [`selective`]: KeyboardMarkup::selective - pub fn selective(self) -> Self { + pub fn selective(self) -> Self { Self { selective: true, ..self } } } @@ -146,6 +146,26 @@ mod tests { "selective": false } "#; - serde_json::from_str::(data).unwrap(); + assert!(serde_json::from_str::(data).is_ok()) + } + #[test] + fn serialize() { + let keyboard = vec![ + vec![ + KeyboardButton::new("a"), + KeyboardButton::new("b"), + KeyboardButton::new("c"), + KeyboardButton::new("d"), + ] + ]; + let keyboard_markup = KeyboardMarkup::new(keyboard) + .persistent() + .resize_keyboard() + .selective() + .one_time_keyboard(); + let expected = r#"{"keyboard":[[{"text":"a"},{"text":"b"},{"text":"c"},{"text":"d"}]],"is_persistent":true,"resize_keyboard":true,"one_time_keyboard":true,"selective":true}"#; + + assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s|s.eq(expected))); + } } From 0f4ee3023a7a0ace8497f9bec5db5a5cd6500bb9 Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 3 Oct 2024 12:36:15 +0330 Subject: [PATCH 32/38] fmt --- .../src/types/reply_keyboard_markup.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/teloxide-core/src/types/reply_keyboard_markup.rs b/crates/teloxide-core/src/types/reply_keyboard_markup.rs index 1c9c5935..57da3f25 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_markup.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_markup.rs @@ -150,14 +150,12 @@ mod tests { } #[test] fn serialize() { - let keyboard = vec![ - vec![ - KeyboardButton::new("a"), - KeyboardButton::new("b"), - KeyboardButton::new("c"), - KeyboardButton::new("d"), - ] - ]; + let keyboard = vec![vec![ + KeyboardButton::new("a"), + KeyboardButton::new("b"), + KeyboardButton::new("c"), + KeyboardButton::new("d"), + ]]; let keyboard_markup = KeyboardMarkup::new(keyboard) .persistent() .resize_keyboard() @@ -165,7 +163,6 @@ mod tests { .one_time_keyboard(); let expected = r#"{"keyboard":[[{"text":"a"},{"text":"b"},{"text":"c"},{"text":"d"}]],"is_persistent":true,"resize_keyboard":true,"one_time_keyboard":true,"selective":true}"#; - assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s|s.eq(expected))); - + assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s| s.eq(expected))); } } From ebe89a637a669973eeaa2031b5021cddee40e130 Mon Sep 17 00:00:00 2001 From: Lewis Pearson Date: Sat, 5 Oct 2024 18:15:42 -0400 Subject: [PATCH 33/38] Update the `teloxide-core` changelog --- crates/teloxide-core/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 9a856377..54916b3c 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -65,11 +65,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Wrap `Public` variant of `ChatKind` in `Box` - Replaced `user_ids` with `users` in `UsersShared` struct +- Remove a useless generic type in the `KeyboardMarkup::selective` function ([#1176][pr1176]) + [pr1131]: https://github.com/teloxide/teloxide/pull/1131 [pr1134]: https://github.com/teloxide/teloxide/pull/1134 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 [pr1147]: https://github.com/teloxide/teloxide/pull/1147 [pr1151]: https://github.com/teloxide/teloxide/pull/1151 +[pr1176]: https://github.com/teloxide/teloxide/pull/1176 ### Removed From d9f0fdb31a943a05f6fa46f2858eb96ce04760e7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 08:52:22 +0000 Subject: [PATCH 34/38] Bump the lock group with 25 updates Bumps the lock group with 25 updates: | Package | From | To | | --- | --- | --- | | [pin-project](https://github.com/taiki-e/pin-project) | `1.1.5` | `1.1.6` | | [reqwest](https://github.com/seanmonstar/reqwest) | `0.12.7` | `0.12.8` | | [once_cell](https://github.com/matklad/once_cell) | `1.20.1` | `1.20.2` | | [bitflags](https://github.com/bitflags/bitflags) | `1.3.2` | `2.4.2` | | [aho-corasick](https://github.com/BurntSushi/aho-corasick) | `0.7.20` | `1.1.2` | | [syn](https://github.com/dtolnay/syn) | `1.0.109` | `2.0.52` | | [addr2line](https://github.com/gimli-rs/addr2line) | `0.24.1` | `0.24.2` | | [cc](https://github.com/rust-lang/cc-rs) | `1.1.22` | `1.1.28` | | [futures-channel](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [futures-core](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [futures-io](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [futures-sink](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [futures-task](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [futures-util](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [gimli](https://github.com/gimli-rs/gimli) | `0.31.0` | `0.31.1` | | [httparse](https://github.com/seanmonstar/httparse) | `1.9.4` | `1.9.5` | | [ipnet](https://github.com/krisprice/ipnet) | `2.10.0` | `2.10.1` | | [object](https://github.com/gimli-rs/object) | `0.36.4` | `0.36.5` | | [pin-project-internal](https://github.com/taiki-e/pin-project) | `1.1.5` | `1.1.6` | | [rustls](https://github.com/rustls/rustls) | `0.23.13` | `0.23.14` | | [rustls-native-certs](https://github.com/rustls/rustls-native-certs) | `0.7.3` | `0.8.0` | | [rustls-pemfile](https://github.com/rustls/pemfile) | `2.1.3` | `2.2.0` | | [schannel](https://github.com/steffengy/schannel-rs) | `0.1.24` | `0.1.26` | | [unicode-bidi](https://github.com/servo/unicode-bidi) | `0.3.15` | `0.3.17` | | [unicode-properties](https://github.com/unicode-rs/unicode-properties) | `0.1.2` | `0.1.3` | Updates `pin-project` from 1.1.5 to 1.1.6 - [Release notes](https://github.com/taiki-e/pin-project/releases) - [Changelog](https://github.com/taiki-e/pin-project/blob/main/CHANGELOG.md) - [Commits](https://github.com/taiki-e/pin-project/compare/v1.1.5...v1.1.6) Updates `reqwest` from 0.12.7 to 0.12.8 - [Release notes](https://github.com/seanmonstar/reqwest/releases) - [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md) - [Commits](https://github.com/seanmonstar/reqwest/compare/v0.12.7...v0.12.8) Updates `once_cell` from 1.20.1 to 1.20.2 - [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md) - [Commits](https://github.com/matklad/once_cell/compare/v1.20.1...v1.20.2) Updates `bitflags` from 1.3.2 to 2.4.2 - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](https://github.com/bitflags/bitflags/compare/1.3.2...2.4.2) Updates `aho-corasick` from 0.7.20 to 1.1.2 - [Commits](https://github.com/BurntSushi/aho-corasick/compare/0.7.20...1.1.2) Updates `syn` from 1.0.109 to 2.0.52 - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.109...2.0.52) Updates `addr2line` from 0.24.1 to 0.24.2 - [Changelog](https://github.com/gimli-rs/addr2line/blob/master/CHANGELOG.md) - [Commits](https://github.com/gimli-rs/addr2line/compare/0.24.1...0.24.2) Updates `cc` from 1.1.22 to 1.1.28 - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.22...cc-v1.1.28) Updates `futures-channel` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `futures-core` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `futures-io` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `futures-sink` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `futures-task` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `futures-util` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `gimli` from 0.31.0 to 0.31.1 - [Changelog](https://github.com/gimli-rs/gimli/blob/master/CHANGELOG.md) - [Commits](https://github.com/gimli-rs/gimli/compare/0.31.0...0.31.1) Updates `httparse` from 1.9.4 to 1.9.5 - [Release notes](https://github.com/seanmonstar/httparse/releases) - [Commits](https://github.com/seanmonstar/httparse/compare/v1.9.4...v1.9.5) Updates `ipnet` from 2.10.0 to 2.10.1 - [Release notes](https://github.com/krisprice/ipnet/releases) - [Changelog](https://github.com/krisprice/ipnet/blob/master/RELEASES.md) - [Commits](https://github.com/krisprice/ipnet/commits) Updates `object` from 0.36.4 to 0.36.5 - [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md) - [Commits](https://github.com/gimli-rs/object/compare/0.36.4...0.36.5) Updates `pin-project-internal` from 1.1.5 to 1.1.6 - [Release notes](https://github.com/taiki-e/pin-project/releases) - [Changelog](https://github.com/taiki-e/pin-project/blob/main/CHANGELOG.md) - [Commits](https://github.com/taiki-e/pin-project/compare/v1.1.5...v1.1.6) Updates `rustls` from 0.23.13 to 0.23.14 - [Release notes](https://github.com/rustls/rustls/releases) - [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustls/rustls/compare/v/0.23.13...v/0.23.14) Updates `rustls-native-certs` from 0.7.3 to 0.8.0 - [Release notes](https://github.com/rustls/rustls-native-certs/releases) - [Commits](https://github.com/rustls/rustls-native-certs/compare/v/0.7.3...v/0.8.0) Updates `rustls-pemfile` from 2.1.3 to 2.2.0 - [Release notes](https://github.com/rustls/pemfile/releases) - [Commits](https://github.com/rustls/pemfile/compare/v/2.1.3...v/2.2.0) Updates `schannel` from 0.1.24 to 0.1.26 - [Release notes](https://github.com/steffengy/schannel-rs/releases) - [Commits](https://github.com/steffengy/schannel-rs/compare/v0.1.24...v0.1.26) Updates `unicode-bidi` from 0.3.15 to 0.3.17 - [Release notes](https://github.com/servo/unicode-bidi/releases) - [Commits](https://github.com/servo/unicode-bidi/compare/v0.3.15...v0.3.17) Updates `unicode-properties` from 0.1.2 to 0.1.3 - [Commits](https://github.com/unicode-rs/unicode-properties/compare/v0.1.2...v0.1.3) --- updated-dependencies: - dependency-name: pin-project dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: reqwest dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: once_cell dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: bitflags dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: aho-corasick dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: addr2line dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: cc dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-channel dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-core dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-io dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-sink dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-task dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-util dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: gimli dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: httparse dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: ipnet dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: object dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: pin-project-internal dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: rustls-native-certs dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: rustls-pemfile dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: schannel dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: unicode-bidi dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: unicode-properties dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock ... Signed-off-by: dependabot[bot] --- Cargo.lock | 115 +++++++++++++++++++++-------------------------------- 1 file changed, 46 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be87412e..93b84dad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ "gimli", ] @@ -255,9 +255,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.22" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -639,9 +639,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -649,9 +649,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" @@ -677,15 +677,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -694,21 +694,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -745,9 +745,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.31.0" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "h2" @@ -892,9 +892,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "httpdate" @@ -940,7 +940,7 @@ dependencies = [ "hyper", "hyper-util", "rustls", - "rustls-native-certs 0.8.0", + "rustls-native-certs", "rustls-pki-types", "tokio", "tokio-rustls", @@ -1070,9 +1070,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.10.0" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" [[package]] name = "is-terminal" @@ -1261,21 +1261,18 @@ dependencies = [ [[package]] name = "object" -version = "0.36.4" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.20.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" -dependencies = [ - "portable-atomic", -] +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "openssl" @@ -1364,18 +1361,18 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" dependencies = [ "proc-macro2", "quote", @@ -1400,12 +1397,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" -[[package]] -name = "portable-atomic" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -1623,9 +1614,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64 0.22.1", "bytes", @@ -1651,7 +1642,7 @@ dependencies = [ "pin-project-lite", "quinn", "rustls", - "rustls-native-certs 0.7.3", + "rustls-native-certs", "rustls-pemfile", "rustls-pki-types", "serde", @@ -1745,9 +1736,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.13" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" dependencies = [ "once_cell", "ring", @@ -1757,19 +1748,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-native-certs" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5bfb394eeed242e909609f56089eecfe5fda225042e8b171791b9c95f5931e5" -dependencies = [ - "openssl-probe", - "rustls-pemfile", - "rustls-pki-types", - "schannel", - "security-framework", -] - [[package]] name = "rustls-native-certs" version = "0.8.0" @@ -1785,11 +1763,10 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64 0.22.1", "rustls-pki-types", ] @@ -1824,9 +1801,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ "windows-sys 0.59.0", ] @@ -2597,9 +2574,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" @@ -2618,9 +2595,9 @@ dependencies = [ [[package]] name = "unicode-properties" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" [[package]] name = "unicode_categories" From 5434639cca9ce8e2c885e94769e6310889e9d7f3 Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Sun, 13 Oct 2024 23:04:49 +0300 Subject: [PATCH 35/38] Fixed newtype serialization in multipart requests --- CHANGELOG.md | 1 + .../src/serde_multipart/serializers.rs | 22 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2c37d5..533652ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Now Vec in requests serializes into [number] instead of [ {message_id: number} ], `forward_messages`, `copy_messages` and `delete_messages` now work properly +- Now `ThreadId` is able to serialize in multipart requests ## 0.13.0 - 2024-08-16 diff --git a/crates/teloxide-core/src/serde_multipart/serializers.rs b/crates/teloxide-core/src/serde_multipart/serializers.rs index a8ded25e..66454041 100644 --- a/crates/teloxide-core/src/serde_multipart/serializers.rs +++ b/crates/teloxide-core/src/serde_multipart/serializers.rs @@ -374,6 +374,17 @@ impl Serializer for PartSerializer { Ok(JsonPartSerializer { buf: String::new(), state: PartSerializerStructState::Empty }) } + fn serialize_newtype_struct( + self, + _: &'static str, + value: &T, + ) -> Result + where + T: Serialize, + { + value.serialize(self) + } + // Unimplemented fn serialize_none(self) -> Result { @@ -391,17 +402,6 @@ impl Serializer for PartSerializer { unimplemented!() } - fn serialize_newtype_struct( - self, - _: &'static str, - _: &T, - ) -> Result - where - T: Serialize, - { - unimplemented!() - } - fn serialize_newtype_variant( self, _name: &'static str, From eb855158c54ad8d65e13745119ada2ab85300daa Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 14 Oct 2024 01:02:19 +0300 Subject: [PATCH 36/38] Linked pr --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 533652ea..ec172462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Now Vec in requests serializes into [number] instead of [ {message_id: number} ], `forward_messages`, `copy_messages` and `delete_messages` now work properly -- Now `ThreadId` is able to serialize in multipart requests +- Now `ThreadId` is able to serialize in multipart requests ([PR 1179](https://github.com/teloxide/teloxide/pull/1179)) ## 0.13.0 - 2024-08-16 From 5fa616046cb3c7e0f065afcee3bad859612f74d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:36:54 +0000 Subject: [PATCH 37/38] Bump the lock group with 12 updates Bumps the lock group with 12 updates: | Package | From | To | | --- | --- | --- | | [bitflags](https://github.com/bitflags/bitflags) | `1.3.2` | `2.4.2` | | [aho-corasick](https://github.com/BurntSushi/aho-corasick) | `0.7.20` | `1.1.2` | | [proc-macro2](https://github.com/dtolnay/proc-macro2) | `1.0.86` | `1.0.87` | | [syn](https://github.com/dtolnay/syn) | `1.0.109` | `2.0.52` | | [bytemuck](https://github.com/Lokathor/bytemuck) | `1.18.0` | `1.19.0` | | [cc](https://github.com/rust-lang/cc-rs) | `1.1.28` | `1.1.30` | | [futures-executor](https://github.com/rust-lang/futures-rs) | `0.3.30` | `0.3.31` | | [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) | `0.2.93` | `0.2.95` | | [wasm-bindgen-backend](https://github.com/rustwasm/wasm-bindgen) | `0.2.93` | `0.2.95` | | [wasm-bindgen-macro](https://github.com/rustwasm/wasm-bindgen) | `0.2.93` | `0.2.95` | | [wasm-bindgen-macro-support](https://github.com/rustwasm/wasm-bindgen) | `0.2.93` | `0.2.95` | | [wasm-bindgen-shared](https://github.com/rustwasm/wasm-bindgen) | `0.2.93` | `0.2.95` | Updates `bitflags` from 1.3.2 to 2.4.2 - [Release notes](https://github.com/bitflags/bitflags/releases) - [Changelog](https://github.com/bitflags/bitflags/blob/main/CHANGELOG.md) - [Commits](https://github.com/bitflags/bitflags/compare/1.3.2...2.4.2) Updates `aho-corasick` from 0.7.20 to 1.1.2 - [Commits](https://github.com/BurntSushi/aho-corasick/compare/0.7.20...1.1.2) Updates `proc-macro2` from 1.0.86 to 1.0.87 - [Release notes](https://github.com/dtolnay/proc-macro2/releases) - [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.86...1.0.87) Updates `syn` from 1.0.109 to 2.0.52 - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.109...2.0.52) Updates `bytemuck` from 1.18.0 to 1.19.0 - [Changelog](https://github.com/Lokathor/bytemuck/blob/main/changelog.md) - [Commits](https://github.com/Lokathor/bytemuck/compare/v1.18.0...v1.19.0) Updates `cc` from 1.1.28 to 1.1.30 - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.1.28...cc-v1.1.30) Updates `futures-executor` from 0.3.30 to 0.3.31 - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31) Updates `wasm-bindgen` from 0.2.93 to 0.2.95 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/compare/0.2.93...0.2.95) Updates `wasm-bindgen-backend` from 0.2.93 to 0.2.95 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/compare/0.2.93...0.2.95) Updates `wasm-bindgen-macro` from 0.2.93 to 0.2.95 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/compare/0.2.93...0.2.95) Updates `wasm-bindgen-macro-support` from 0.2.93 to 0.2.95 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/compare/0.2.93...0.2.95) Updates `wasm-bindgen-shared` from 0.2.93 to 0.2.95 - [Release notes](https://github.com/rustwasm/wasm-bindgen/releases) - [Changelog](https://github.com/rustwasm/wasm-bindgen/blob/main/CHANGELOG.md) - [Commits](https://github.com/rustwasm/wasm-bindgen/compare/0.2.93...0.2.95) --- updated-dependencies: - dependency-name: bitflags dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: aho-corasick dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: proc-macro2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: lock - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-major dependency-group: lock - dependency-name: bytemuck dependency-type: indirect update-type: version-update:semver-minor dependency-group: lock - dependency-name: cc dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: futures-executor dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: wasm-bindgen dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: wasm-bindgen-backend dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: wasm-bindgen-macro dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: wasm-bindgen-macro-support dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock - dependency-name: wasm-bindgen-shared dependency-type: indirect update-type: version-update:semver-patch dependency-group: lock ... Signed-off-by: dependabot[bot] --- Cargo.lock | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93b84dad..866dcc30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,9 +237,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" +checksum = "8334215b81e418a0a7bdb8ef0849474f40bb10c8b71f1c4ed315cff49f32494d" [[package]] name = "byteorder" @@ -255,9 +255,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.28" +version = "1.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" +checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" dependencies = [ "shlex", ] @@ -655,9 +655,9 @@ checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -1452,9 +1452,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -2673,9 +2673,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", "once_cell", @@ -2684,9 +2684,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", @@ -2711,9 +2711,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2721,9 +2721,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", @@ -2734,9 +2734,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasm-streams" @@ -2786,7 +2786,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] From eee0a374e4d0bdc7d48f26d01fd25036499826bf Mon Sep 17 00:00:00 2001 From: LasterAlex Date: Mon, 14 Oct 2024 21:03:00 +0300 Subject: [PATCH 38/38] Fixed InlineQueryResultsButton serialization --- CHANGELOG.md | 1 + .../src/types/inline_query_results_button.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2c37d5..707bf546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Now Vec in requests serializes into [number] instead of [ {message_id: number} ], `forward_messages`, `copy_messages` and `delete_messages` now work properly +- Now `InlineQueryResultsButton` serializes properly ([issue 1181](https://github.com/teloxide/teloxide/issues/1181)) ## 0.13.0 - 2024-08-16 diff --git a/crates/teloxide-core/src/types/inline_query_results_button.rs b/crates/teloxide-core/src/types/inline_query_results_button.rs index 3219dd0d..d0c5ecec 100644 --- a/crates/teloxide-core/src/types/inline_query_results_button.rs +++ b/crates/teloxide-core/src/types/inline_query_results_button.rs @@ -17,6 +17,7 @@ pub struct InlineQueryResultsButton { } #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] pub enum InlineQueryResultsButtonKind { /// Description of the [Web App] that will be launched when the user presses /// the button. The Web App will be able to switch back to the inline mode @@ -44,3 +45,19 @@ pub enum InlineQueryResultsButtonKind { /// [switch_inline]: https://core.telegram.org/bots/api#inlinekeyboardmarkup StartParameter(String), } + +#[cfg(test)] +mod tests { + use crate::types::{InlineQueryResultsButton, InlineQueryResultsButtonKind}; + + #[test] + fn inline_query_results_button() { + let button = InlineQueryResultsButton { + text: "test".into(), + kind: InlineQueryResultsButtonKind::StartParameter("bot".into()), + }; + let expected = r#"{"text":"test","start_parameter":"bot"}"#; + let actual = serde_json::to_string(&button).unwrap(); + assert_eq!(expected, actual); + } +}