Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.17.1 #252

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
43 changes: 31 additions & 12 deletions lib/src/televerse/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1749,47 +1749,66 @@ class Context {

/// Edit the message media
/// Use this method to edit animation, audio, document, photo, or video messages.
Future<bool> 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<MessageOrBool> editMessageMedia<MessageOrBool>(
InputMedia media, {
InlineKeyboardMarkup? replyMarkup,
}) async {
if (MessageOrBool != Message && MessageOrBool != bool) {
throw TeleverseException.typeParameterRequired(
"editMessageMedia",
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
/// Use this method to edit only the reply markup of messages.
Future<bool> editMessageReplyMarkup({
Future<MessageOrBool> editMessageReplyMarkup<MessageOrBool>({
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
Expand Down
2 changes: 1 addition & 1 deletion lib/src/televerse/models/chat_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/src/televerse/models/televerse_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,21 @@ class TeleverseException implements Exception {
type: TeleverseExceptionType.timeoutException,
);
}

/// Exception thrown when the timeout exception occurs.
static TeleverseException typeParameterRequired(
String method,
Type type,
List<Type> 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 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<bool>(...)` for inline messages or `ctx.$method<Message>(...)` otherwise.",
type: TeleverseExceptionType.invalidParameter,
);
}
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading