From 67dd005f4aadf4035c6a49010c59d74f14d5ba9e Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Fri, 31 May 2024 22:46:44 +0530 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=A4=98=20Meta=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 3c6ee2fd..b0664f45 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: televerse -description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.3! -version: 1.17.0 +description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.4! +version: 1.17.1 homepage: https://github.com/HeySreelal/televerse topics: - telegram From c43998f9d67a1a36010848f726191d1d0d336099 Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Fri, 31 May 2024 23:15:39 +0530 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=85=20Strict=20typing=20for=20`ctx?= =?UTF-8?q?.editMessageMedia`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/televerse/context/context.dart | 24 ++++++++++++++----- .../televerse/models/televerse_exception.dart | 16 +++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/src/televerse/context/context.dart b/lib/src/televerse/context/context.dart index ac773409..f20232a9 100644 --- a/lib/src/televerse/context/context.dart +++ b/lib/src/televerse/context/context.dart @@ -1749,26 +1749,38 @@ class Context { /// Edit the message media /// Use this method to edit animation, audio, document, photo, or video messages. - Future editMessageMedia( + /// + /// Make sure to pass the type parameter for correct typing. If the message to be edited is an + /// inline message, the type parameter should be `bool`, otherwise `Message` should be passed. + /// + /// Since Televerse don't deal with `dynamic` types on the public interface, if you do not pass + /// type parameter, this method will throw a `TeleverseException`. + Future editMessageMedia( InputMedia media, { InlineKeyboardMarkup? replyMarkup, }) async { + if (MessageOrBool != Message && MessageOrBool != bool) { + throw TeleverseException.typeParameterRequired( + MessageOrBool, + [Message, bool], + ); + } + if (_isInline()) { - await api.editInlineMessageMedia( + return await api.editInlineMessageMedia( _inlineMsgId!, media, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } else { _verifyInfo([_chatId, _msgId], APIMethod.editMessageMedia); - await api.editMessageMedia( + return await api.editMessageMedia( id, _msgId!, media, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } - return true; } /// Edit the message reply markup diff --git a/lib/src/televerse/models/televerse_exception.dart b/lib/src/televerse/models/televerse_exception.dart index 8e52da7d..b5b52da2 100644 --- a/lib/src/televerse/models/televerse_exception.dart +++ b/lib/src/televerse/models/televerse_exception.dart @@ -94,4 +94,20 @@ class TeleverseException implements Exception { type: TeleverseExceptionType.timeoutException, ); } + + /// Exception thrown when the timeout exception occurs. + static TeleverseException typeParameterRequired( + Type type, + List expected, + ) { + return TeleverseException( + "Type Parameter Required.", + description: + "Televerse is a strictly typed library and does not allows usage of dynamic types. This exception is thrown either\n" + " 1. when you do not mention type parameter when it is required\n" + " 2. when you passed the type [$type] where types [${expected.join(', ')}] are expected.\n\n" + "If you are using the `Context.editMessageMedia` method, try `ctx.editMessageMedia` for inline messages or `editMessageMedia` otherwise.", + type: TeleverseExceptionType.invalidParameter, + ); + } } From a94203b79ae9e2d10a97ca932119d37cedbaa94a Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Sat, 1 Jun 2024 00:07:50 +0530 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=91=A8=F0=9F=8F=BB=E2=80=8D?= =?UTF-8?q?=F0=9F=8F=AB=20Strict=20typing=20for=20`ctx.editMessageReplyMar?= =?UTF-8?q?kup`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/televerse/context/context.dart | 19 +++++++++++++------ .../televerse/models/televerse_exception.dart | 7 ++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/src/televerse/context/context.dart b/lib/src/televerse/context/context.dart index f20232a9..d68a966b 100644 --- a/lib/src/televerse/context/context.dart +++ b/lib/src/televerse/context/context.dart @@ -1761,6 +1761,7 @@ class Context { }) async { if (MessageOrBool != Message && MessageOrBool != bool) { throw TeleverseException.typeParameterRequired( + "editMessageMedia", MessageOrBool, [Message, bool], ); @@ -1785,23 +1786,29 @@ class Context { /// Edit the message reply markup /// Use this method to edit only the reply markup of messages. - Future editMessageReplyMarkup({ + Future editMessageReplyMarkup({ InlineKeyboardMarkup? replyMarkup, }) async { + if (MessageOrBool != Message && MessageOrBool != bool) { + throw TeleverseException.typeParameterRequired( + "editMessageReplyMarkup", + MessageOrBool, + [Message, bool], + ); + } if (_isInline()) { - await api.editInlineMessageReplyMarkup( + return await api.editInlineMessageReplyMarkup( _inlineMsgId!, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } else { _verifyInfo([_chatId, _msgId], APIMethod.editMessageReplyMarkup); - await api.editMessageReplyMarkup( + return await api.editMessageReplyMarkup( id, _msgId!, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } - return true; } /// Answer inline query diff --git a/lib/src/televerse/models/televerse_exception.dart b/lib/src/televerse/models/televerse_exception.dart index b5b52da2..81b6b478 100644 --- a/lib/src/televerse/models/televerse_exception.dart +++ b/lib/src/televerse/models/televerse_exception.dart @@ -97,6 +97,7 @@ class TeleverseException implements Exception { /// Exception thrown when the timeout exception occurs. static TeleverseException typeParameterRequired( + String method, Type type, List expected, ) { @@ -104,9 +105,9 @@ class TeleverseException implements Exception { "Type Parameter Required.", description: "Televerse is a strictly typed library and does not allows usage of dynamic types. This exception is thrown either\n" - " 1. when you do not mention type parameter when it is required\n" - " 2. when you passed the type [$type] where types [${expected.join(', ')}] are expected.\n\n" - "If you are using the `Context.editMessageMedia` method, try `ctx.editMessageMedia` for inline messages or `editMessageMedia` otherwise.", + " 1. when you do not mention type parameter when it is required or\n" + " 2. when you've passed the type [$type] where types [${expected.join(', ')}] are expected.\n\n" + "If you are using the `Context.$method` method, try `ctx.$method(...)` for inline messages or `ctx.$method(...)` otherwise.", type: TeleverseExceptionType.invalidParameter, ); } From 8e2bfce6d6ea57c7a95fee744223c95ab652f719 Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Sat, 1 Jun 2024 23:59:35 +0530 Subject: [PATCH 4/5] Fix: `ChatID` constructor --- lib/src/televerse/models/chat_id.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/televerse/models/chat_id.dart b/lib/src/televerse/models/chat_id.dart index 21e7e37f..d0d8ac28 100644 --- a/lib/src/televerse/models/chat_id.dart +++ b/lib/src/televerse/models/chat_id.dart @@ -87,7 +87,7 @@ class ChatID extends ID { /// // Print the chat's title. /// print(chat.title); /// ``` - const ChatID(super.id); + const ChatID(int super.id); /// The ID getter, returns the actual integer value @override From feb1b7f15e8c494099bcfb27bd000939d6db01e6 Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Tue, 11 Jun 2024 14:50:00 +0530 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Changelog=20v1.17.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ad81e7..1c83e16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.17.1 + +- ‼️ Strict typing for `ctx.editMessageMedia` and `ctx.editMessageReplyMarkup` +- Fix: `ChatID` constuctor accepted `dynamic` + # 1.17.0 - 🤖 Bot API 7.4 (May 28, 2024)