From b928ed525dbd9c20e3bb902335137b1868ab9107 Mon Sep 17 00:00:00 2001 From: Abitofevrything Date: Mon, 27 Nov 2023 11:15:09 +0100 Subject: [PATCH 1/2] Fix autocompletion not finding focused options in commands in chat groups --- lib/src/context/context_manager.dart | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/context/context_manager.dart b/lib/src/context/context_manager.dart index fbabfb6..25beaaf 100644 --- a/lib/src/context/context_manager.dart +++ b/lib/src/context/context_manager.dart @@ -175,6 +175,18 @@ class ContextManager { Member? member = interaction.member; User user = member?.user ?? interaction.user!; + Iterable expandOptions(List options) sync* { + for (final option in options) { + yield option; + if (option.options case final nestedOptions?) { + yield* expandOptions(nestedOptions); + } + } + } + + final focusedOption = expandOptions(interaction.data.options!) + .singleWhere((element) => element.isFocused == true); + return AutocompleteContext( commands: commands, guild: await interaction.guild?.get(), @@ -184,11 +196,8 @@ class ContextManager { command: command, client: interaction.manager.client as NyxxGateway, interaction: interaction, - option: interaction.data.options!.singleWhere((element) => element.isFocused == true), - currentValue: interaction.data.options! - .singleWhere((element) => element.isFocused == true) - .value - .toString(), + option: focusedOption, + currentValue: focusedOption.value.toString(), ); } From 6a33ed3e8079f5edb4e4e79f11ab4d7f41e9741c Mon Sep 17 00:00:00 2001 From: Abitofevrything Date: Mon, 27 Nov 2023 11:17:03 +0100 Subject: [PATCH 2/2] Release 6.0.3 --- CHANGELOG.md | 4 ++++ example/example.dart | 1 - pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 747b233..6876a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.2 +__Bug fixes__ +- Fixed autocompletion in commands in chat groups + ## 6.0.1 __Bug fixes__ - Fixed ephemeral response levels breaking component helpers. diff --git a/example/example.dart b/example/example.dart index 62668db..5be18e5 100644 --- a/example/example.dart +++ b/example/example.dart @@ -113,7 +113,6 @@ void main() async { // // Since a ping command doesn't have any other arguments, we don't add any other parameters to // the function. - options: CommandOptions(defaultResponseLevel: ResponseLevel.hint), id('ping', (ChatContext context) { // For a ping command, all we need to do is respond with `pong`. // To do that, we can use the `IChatContext`'s `respond` method which responds to the command with diff --git a/pubspec.yaml b/pubspec.yaml index 0faace5..a23c14e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: nyxx_commands -version: 6.0.1 +version: 6.0.2 description: A framework for easily creating slash commands and text commands for Discord using the nyxx library. homepage: https://github.com/nyxx-discord/nyxx_commands/blob/main/README.md