Skip to content

Commit

Permalink
added new event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Apr 5, 2024
1 parent aad98c0 commit 9d295fd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
19 changes: 17 additions & 2 deletions lib/src/teledart/event/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class Event {
final StreamController<Message> _editedMessageStreamController;
final StreamController<Message> _channelPostStreamController;
final StreamController<Message> _editedChannelPostStreamController;
final StreamController<MessageReactionUpdated> _messageReactionStreamController;
final StreamController<MessageReactionCountUpdated> _messageReactionCountStreamController;
final StreamController<InlineQuery> _inlineQueryStreamController;
final StreamController<ChosenInlineResult>
_chosenInlineResultStreamController;
final StreamController<ChosenInlineResult> _chosenInlineResultStreamController;
final StreamController<CallbackQuery> _callbackQueryStreamController;
final StreamController<ShippingQuery> _shippingQueryStreamController;
final StreamController<PreCheckoutQuery> _preCheckoutQueryStreamController;
Expand All @@ -51,6 +52,8 @@ class Event {
_channelPostStreamController = StreamController.broadcast(sync: sync),
_editedChannelPostStreamController =
StreamController.broadcast(sync: sync),
_messageReactionStreamController = StreamController.broadcast(sync: sync),
_messageReactionCountStreamController = StreamController.broadcast(sync: sync),
_inlineQueryStreamController = StreamController.broadcast(sync: sync),
_chosenInlineResultStreamController =
StreamController.broadcast(sync: sync),
Expand All @@ -75,6 +78,10 @@ class Event {
_channelPostStreamController.add(update.channelPost!);
} else if (update.editedChannelPost != null) {
_editedChannelPostStreamController.add(update.editedChannelPost!);
} else if (update.messageReaction != null) {
_messageReactionStreamController.add(update.messageReaction!);
} else if (update.messageReactionCount != null) {
_messageReactionCountStreamController.add(update.messageReactionCount!);
} else if (update.inlineQuery != null) {
_inlineQueryStreamController.add(update.inlineQuery!);
} else if (update.chosenInlineResult != null) {
Expand Down Expand Up @@ -196,6 +203,14 @@ class Event {
Stream<Message> onEditedChannelPost() =>
_editedChannelPostStreamController.stream;

/// Listens to message reaction updated events
Stream<MessageReactionUpdated> onMessageReactionUpdated() =>
_messageReactionStreamController.stream;

/// Listens to message reaction count updated events
Stream<MessageReactionCountUpdated> onMessageReactionCountUpdated() =>
_messageReactionCountStreamController.stream;

/// Listens to inline query events
Stream<InlineQuery> onInlineQuery() => _inlineQueryStreamController.stream;

Expand Down
4 changes: 4 additions & 0 deletions lib/src/teledart/fetch/long_polling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class LongPolling extends AbstractUpdateFetcher {
Duration retryDelay = Duration(seconds: 5);

/// Setup long polling
///
/// Setting [allowedUpdates] to empty **List** to receive all update types
/// except **chat_member**, **message_reaction**, and **message_reaction_count**
/// If not specified, the previous setting will be used.
///
/// Throws [LongPollingException] if [limit] is less than 1 or greater than 100
/// or [timeout] is greater than 50.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/teledart/fetch/webhook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Webhook extends AbstractUpdateFetcher {
///
/// Default [port] is `443`, Telegram API supports `443`, `80`, `88`, `8443`.
/// Provide [privateKey] and [certificate] pair for HTTPS configuration
///
/// Setting [allowedUpdates] to empty **List** to receive all update types
/// except **chat_member**, **message_reaction**, and **message_reaction_count**
/// If not specified, the previous setting will be used.
///
/// Throws [WebhookException] if [port] is not supported by Telegram
/// or [maxConnections] is less than 1 or greater than 100.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/teledart/model/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ class TeleDartMessage extends Message {
/// change the chosen reactions on a message
///
/// A wrapper around [TeleDart.setMessageReaction].
/// On success, returns the sent *True*.
/// On success, returns the sent **True**.
///
/// It takes some optional parameters to customise the reaction
///
Expand Down
8 changes: 8 additions & 0 deletions lib/src/teledart/teledart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ class TeleDart extends Telegram {
/// Listen to edited channel post events
Stream<TeleDartMessage> onEditedChannelPost() =>
_event.onEditedChannelPost().map(_messageStreamMapper);

/// Listen to edited reaction updated events
Stream<MessageReactionUpdated> onMessageReactionUpdated() =>
_event.onMessageReactionUpdated();

/// Listen to edited reaction count updated events
Stream<MessageReactionCountUpdated> onMessageReactionCountUpdated() =>
_event.onMessageReactionCountUpdated();

/// Listen to inline query events
///
Expand Down
2 changes: 1 addition & 1 deletion lib/src/telegram/telegram.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ class Telegram {
/// Use this method to change the chosen reactions on a message. Service messages can't be reacted to.
/// Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
///
/// Returns *True* on success.
/// Returns **True** on success.
///
/// https://core.telegram.org/bots/api#setmessagereaction
Future<bool> setMessageReaction(dynamic chatId, int messageId,
Expand Down

0 comments on commit 9d295fd

Please sign in to comment.