diff --git a/lib/src/commands.dart b/lib/src/commands.dart index 082704f..edd7554 100644 --- a/lib/src/commands.dart +++ b/lib/src/commands.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:nyxx/nyxx.dart'; +import 'package:nyxx_commands/src/plugin/HttpInteractions.dart'; import 'checks/checks.dart'; import 'checks/guild.dart'; @@ -170,8 +171,23 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup afterConnect(NyxxGateway client) async { _attachedClients.add(client); - client.onMessageComponentInteraction - .map((event) => event.interaction) + var onMessageComponentInteraction = + client.onMessageComponentInteraction.map((event) => event.interaction); + var onApplicationCommandInteraction = + client.onApplicationCommandInteraction.map((event) => event.interaction); + var onApplicationCommandAutocompleteInteraction = + client.onApplicationCommandAutocompleteInteraction.map((event) => event.interaction); + + final httpInteractionsPlugin = + client.options.plugins.whereType().firstOrNull; + if (httpInteractionsPlugin != null) { + onMessageComponentInteraction = httpInteractionsPlugin.onMessageComponentInteraction; + onApplicationCommandInteraction = httpInteractionsPlugin.onApplicationCommandInteraction; + onApplicationCommandAutocompleteInteraction = + httpInteractionsPlugin.onApplicationCommandAutocompleteInteraction; + } + + onMessageComponentInteraction .where((interaction) => interaction.data.type == MessageComponentType.button) .listen( (interaction) async { @@ -183,8 +199,7 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup event.interaction) + onMessageComponentInteraction .where((interaction) => interaction.data.type == MessageComponentType.stringSelect) .listen( (interaction) async { @@ -196,15 +211,7 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup event.interaction).listen( + onApplicationCommandInteraction.listen( (interaction) async { try { final applicationCommand = registeredCommands.singleWhere( @@ -236,9 +243,7 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup event.interaction) - .listen((interaction) async { + onApplicationCommandAutocompleteInteraction.listen((interaction) async { try { final applicationCommand = registeredCommands.singleWhere( (command) => command.id == interaction.data.id, @@ -263,6 +268,14 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup { + Stream> get onInteractionCreate; + + /// A [Stream] of [ApplicationCommandInteraction]s received by this client. + Stream get onApplicationCommandInteraction => + onInteractionCreate.whereType(); + + /// A [Stream] of [MessageComponentInteraction]s received by this client. + Stream get onMessageComponentInteraction => + onInteractionCreate.whereType(); + + /// A [Stream] of [ModalSubmitInteraction]s received by this client. + Stream get onModalSubmitInteraction => + onInteractionCreate.whereType(); + + /// A [Stream] of [ApplicationCommandAutocompleteInteraction]s received by this client. + Stream + get onApplicationCommandAutocompleteInteraction => + onInteractionCreate.whereType(); +} diff --git a/lib/src/util/mixins.dart b/lib/src/util/mixins.dart index 2a5d963..23b597a 100644 --- a/lib/src/util/mixins.dart +++ b/lib/src/util/mixins.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:math'; import 'package:nyxx/nyxx.dart'; +import 'package:nyxx_commands/src/plugin/HttpInteractions.dart'; import '../checks/checks.dart'; import '../commands.dart'; @@ -742,8 +743,14 @@ mixin InteractionRespondMixin return (_delegate as InteractionInteractiveContext).awaitModal(customId, timeout: timeout); } - Future event = client.onModalSubmitInteraction - .map((e) => e.interaction) + var onModalSubmitInteraction = client.onModalSubmitInteraction.map((e) => e.interaction); + final httpInteractionsPlugin = + client.options.plugins.whereType().firstOrNull; + if (httpInteractionsPlugin != null) { + onModalSubmitInteraction = httpInteractionsPlugin.onModalSubmitInteraction; + } + + Future event = onModalSubmitInteraction .where( (event) => event.data.customId == customId, )