Skip to content

Commit

Permalink
ℹ️ Merge #253: Match commands from captions and fix in UserShared
Browse files Browse the repository at this point in the history
v1.17.2
  • Loading branch information
HeySreelal authored Jun 14, 2024
2 parents 14f7949 + 481a462 commit a0556b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 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.2

- Added `considerCaption` parameter in `Bot.command` mehtod to match commands in the caption of video/photo messages.
- 🐞 Fixed: JSON parsing bug in `UsersShared` causing the `users` field to be null and resulting in crashes.

# 1.17.1

- ‼️ Strict typing for `ctx.editMessageMedia` and `ctx.editMessageReplyMarkup`
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/users_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UsersShared {
factory UsersShared.fromJson(Map<String, dynamic> json) {
return UsersShared(
requestId: json['request_id']!,
users: (json['user_ids'] as List<dynamic>)
users: (json['users'] as List<dynamic>)
.map((e) => SharedUser.fromJson(e))
.toList(),
);
Expand All @@ -30,7 +30,7 @@ class UsersShared {
Map<String, dynamic> toJson() {
return {
'request_id': requestId,
'user_ids': users.map((user) => user.toJson()).toList(),
'users': users.map((user) => user.toJson()).toList(),
};
}
}
16 changes: 12 additions & 4 deletions lib/src/televerse/bot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ class Bot {
Pattern command,
Handler callback, {
ScopeOptions? options,
bool considerCaption = false,
}) {
if (initialized) {
final scope = HandlerScope(
Expand All @@ -481,12 +482,18 @@ class Bot {
handler: callback,
types: UpdateType.messages(),
predicate: (ctx) {
if (ctx.msg?.text == null) return false;
String? text;
if (considerCaption) {
text = ctx.msg?.caption;
}
text ??= ctx.msg?.text;

if (text == null) return false;
if (command is RegExp) {
return command.hasMatch(ctx.msg?.text ?? "");
return command.hasMatch(text);
} else if (command is String) {
final firstTerm = ctx.msg?.text!.split(' ').first;
final suffix = me.username != null ? '@${me.username}' : '';
final firstTerm = text.split(' ').first;
final suffix = '@${me.username}';
return firstTerm == '/$command' || firstTerm == '/$command$suffix';
}
return false;
Expand All @@ -503,6 +510,7 @@ class Bot {
params: [command, callback],
namedParams: {
#options: options,
#considerCaption: considerCaption,
},
),
);
Expand Down
2 changes: 1 addition & 1 deletion 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.4!
version: 1.17.1
version: 1.17.2
homepage: https://github.com/HeySreelal/televerse
topics:
- telegram
Expand Down

0 comments on commit a0556b8

Please sign in to comment.