Skip to content

Commit

Permalink
Merge pull request #150 from nyxx-discord/bug/chat-group-autocompletion
Browse files Browse the repository at this point in the history
Fix autocompletion in commands in chat groups; Release 6.0.2
  • Loading branch information
l7ssha authored Nov 27, 2023
2 parents 0bcfc0e + 6a33ed3 commit 8b59c2a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 0 additions & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions lib/src/context/context_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ class ContextManager {
Member? member = interaction.member;
User user = member?.user ?? interaction.user!;

Iterable<InteractionOption> expandOptions(List<InteractionOption> 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(),
Expand All @@ -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(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8b59c2a

Please sign in to comment.