Skip to content

Commit

Permalink
Merge #252: Televerse v1.17.1
Browse files Browse the repository at this point in the history
v1.17.1
  • Loading branch information
HeySreelal authored Jun 11, 2024
2 parents bf347b9 + feb1b7f commit 14f7949
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
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

0 comments on commit 14f7949

Please sign in to comment.