Skip to content

Commit

Permalink
Merge #241: v1.15.11
Browse files Browse the repository at this point in the history
Patch release
  • Loading branch information
HeySreelal authored Apr 16, 2024
2 parents 076497b + ce6e17b commit b1ddffc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.15.11

- Minor fix in update processing
- Added `businessConnectionId` to Context aware methods.

# 1.15.10

- Added `Bot.fromAPI` constructor for creating Bot instance from `RawAPI` instance.
Expand Down
7 changes: 3 additions & 4 deletions lib/src/televerse/bot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class Bot {
/// Handler Scopes and proceeds to process the update.
void _onUpdate(Update update) async {
// Gets the sublist of Handler Scopes that is apt for the recieved Update
final sub = _handlerScopes.reversed.where((scope) {
List<HandlerScope> sub = _handlerScopes.reversed.where((scope) {
return scope.types.contains(update.type);
}).toList();

Expand All @@ -349,12 +349,13 @@ class Bot {
if (!passing) continue;
_preProcess(sub[forks[i]], context);
await _processUpdate(sub[forks[i]], context);
sub[forks[i]].executed();
sub.removeAt(forks[i]);
}

// Finds and processes the handler scopes.
for (int i = 0; i < sub.length; i++) {
final passing = sub[i].predicate(context);

if (sub[i].hasCustomPredicate) {
try {
final customPass =
Expand All @@ -374,13 +375,11 @@ class Bot {
}

if (sub[i].handler == null) continue;
if (sub[i].isExecuted) continue;

_preProcess(sub[i], context);

if (passing) {
await _processUpdate(sub[i], context);
sub[i].executed();
break;
}
}
Expand Down
34 changes: 34 additions & 0 deletions lib/src/televerse/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendMessage);
return api.sendMessage(
Expand All @@ -232,6 +233,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -255,6 +257,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendPhoto);
return api.sendPhoto(
Expand All @@ -268,6 +271,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -289,6 +293,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendAudio);
return api.sendAudio(
Expand All @@ -306,6 +311,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -325,6 +331,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendDocument);
return api.sendDocument(
Expand All @@ -340,6 +347,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -363,6 +371,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendVideo);
return api.sendVideo(
Expand All @@ -382,6 +391,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -399,6 +409,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendVideoNote);
return api.sendVideoNote(
Expand All @@ -412,6 +423,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -430,6 +442,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendVoice);
return api.sendVoice(
Expand All @@ -444,6 +457,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -457,6 +471,7 @@ class Context {
bool? disableNotification,
bool? protectContent,
ReplyParameters? replyParameters,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendMediaGroup);
return api.sendMediaGroup(
Expand All @@ -466,6 +481,7 @@ class Context {
disableNotification: disableNotification,
protectContent: protectContent,
replyParameters: replyParameters,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -484,6 +500,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendLocation);
return api.sendLocation(
Expand All @@ -499,6 +516,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -519,6 +537,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendVenue);
return api.sendVenue(
Expand All @@ -536,6 +555,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -552,6 +572,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendContact);
return api.sendContact(
Expand All @@ -565,6 +586,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -589,6 +611,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
return api.sendPoll(
id,
Expand All @@ -609,6 +632,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -622,6 +646,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendDice);
return api.sendDice(
Expand All @@ -632,6 +657,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -641,12 +667,14 @@ class Context {
Future<bool> replyWithChatAction(
ChatAction action, {
int? messageThreadId,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendChatAction);
return api.sendChatAction(
id,
action,
messageThreadId: _threadId(messageThreadId),
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -660,6 +688,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendGame);
return api.sendGame(
Expand All @@ -670,6 +699,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -691,6 +721,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendAnimation);
return api.sendAnimation(
Expand All @@ -709,6 +740,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand All @@ -722,6 +754,7 @@ class Context {
bool? protectContent,
ReplyParameters? replyParameters,
InlineKeyboardMarkup? replyMarkup,
String? businessConnectionId,
}) async {
_verifyInfo([_chatId], APIMethod.sendSticker);
return api.sendSticker(
Expand All @@ -732,6 +765,7 @@ class Context {
protectContent: protectContent,
replyParameters: replyParameters,
replyMarkup: replyMarkup,
businessConnectionId: businessConnectionId,
);
}

Expand Down
9 changes: 0 additions & 9 deletions lib/src/televerse/models/handler_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class HandlerScope {
/// Scope Options - Additional parameters for the scope.
final ScopeOptions? options;

/// Flag whether already executed
bool isExecuted;

/// Creates a new [HandlerScope].
HandlerScope({
this.handler,
Expand All @@ -45,7 +42,6 @@ class HandlerScope {
this.isConversation = false,
this.chatId,
this.options,
this.isExecuted = false,
}) : assert(handler != null || isConversation);

/// Whether the scope is forked or not.
Expand All @@ -54,11 +50,6 @@ class HandlerScope {
/// Name of the scope
String? get name => options?.name;

/// Sets executiion status to true.
void executed() {
isExecuted = true;
}

/// Whether the scope has a custom predicate
bool get hasCustomPredicate => options?.customPredicate != null;
}
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.2!
version: 1.15.10
version: 1.15.11
homepage: https://github.com/HeySreelal/televerse
topics:
- telegram
Expand Down

0 comments on commit b1ddffc

Please sign in to comment.