diff --git a/lib/nyxx_commands.dart b/lib/nyxx_commands.dart index 05ee515..e651cc7 100644 --- a/lib/nyxx_commands.dart +++ b/lib/nyxx_commands.dart @@ -91,4 +91,4 @@ export 'src/util/util.dart' mentionOr; export 'src/util/view.dart' show StringView; -export 'src/plugin/http_interaction.dart' show HttpInteractionsPlugin; \ No newline at end of file +export 'src/plugin/http_interaction.dart' show HttpInteractionsPlugin; diff --git a/lib/src/commands.dart b/lib/src/commands.dart index 7a032a4..8b1aa12 100644 --- a/lib/src/commands.dart +++ b/lib/src/commands.dart @@ -56,7 +56,7 @@ final Logger logger = Logger('Commands'); /// - [addCommand], for adding commands to your bot; /// - [check], for adding checks to your bot; /// - [MessageCommand] and [UserCommand], for creating Message and User Commands respectively. -class CommandsPlugin extends NyxxPlugin implements CommandGroup { +class CommandsPlugin extends NyxxPlugin implements CommandGroup { /// A function called to determine the prefix for a specific message. /// /// This function should return a [Pattern] that should match the start of the message content if @@ -150,7 +150,7 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup registeredCommands = []; - final Set _attachedClients = {}; + final Set _attachedClients = {}; /// Create a new [CommandsPlugin]. CommandsPlugin({ @@ -168,23 +168,31 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup afterConnect(NyxxGateway client) async { + Future afterConnect(NyxxRest client) async { _attachedClients.add(client); - var onMessageComponentInteraction = - client.onMessageComponentInteraction.map((event) => event.interaction); - var onApplicationCommandInteraction = - client.onApplicationCommandInteraction.map((event) => event.interaction); - var onApplicationCommandAutocompleteInteraction = - client.onApplicationCommandAutocompleteInteraction.map((event) => event.interaction); + late Stream onMessageComponentInteraction; + late Stream onApplicationCommandInteraction; + late Stream + onApplicationCommandAutocompleteInteraction; final httpInteractionsPlugin = client.options.plugins.whereType().firstOrNull; + if (httpInteractionsPlugin != null) { onMessageComponentInteraction = httpInteractionsPlugin.onMessageComponentInteraction; onApplicationCommandInteraction = httpInteractionsPlugin.onApplicationCommandInteraction; onApplicationCommandAutocompleteInteraction = httpInteractionsPlugin.onApplicationCommandAutocompleteInteraction; + } else if (client is NyxxGateway) { + onMessageComponentInteraction = + client.onMessageComponentInteraction.map((event) => event.interaction); + onApplicationCommandInteraction = + client.onApplicationCommandInteraction.map((event) => event.interaction); + onApplicationCommandAutocompleteInteraction = + client.onApplicationCommandAutocompleteInteraction.map((event) => event.interaction); + } else { + throw ArgumentError(); } onMessageComponentInteraction @@ -268,7 +276,7 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup implements CommandGroup command.manager.client == client); _attachedClients.remove(client); } - Future _syncCommands(NyxxGateway client) async { + Future _syncCommands(NyxxRest client) async { final builders = await _buildCommands(); final commands = await Future.wait(builders.entries.map(