Skip to content

Commit

Permalink
Merge pull request #55 from nyxx-discord/main
Browse files Browse the repository at this point in the history
Main
  • Loading branch information
abitofevrything authored Apr 30, 2022
2 parents defaf78 + 919c9fc commit a878331
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 4.1.2
__Bug fixes__:
- Fixes an issue where slash commands nested within text-only commands would not be registered

## 4.1.1
__Bug fixes__:
- Correctly export the `@AUtocomplete(...)` annotation.

## 4.1.0
__New features__:
- Support for autocompletion has been added. See `Converter.autocompleteCallback` and the `@Autocomplete(...)` annotation for more.
Expand Down
1 change: 1 addition & 0 deletions lib/nyxx_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export 'src/errors.dart'
export 'src/options.dart' show CommandsOptions;
export 'src/util/util.dart'
show
Autocomplete,
Choices,
Description,
Name,
Expand Down
24 changes: 15 additions & 9 deletions lib/src/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,8 @@ class CommandsPlugin extends BasePlugin implements ICommandGroup<IContext> {
const Snowflake zeroSnowflake = Snowflake.zero();

for (final command in children) {
if (command is IChatCommandComponent) {
if (command is ChatCommand && command.resolvedType == CommandType.textOnly) {
continue;
}

if (!command.hasSlashCommand && command is! ChatCommand) {
continue;
}
if (!_shouldGnerateBuildersFor(command)) {
continue;
}

Iterable<CommandPermissionBuilderAbstract> permissions = await _getPermissions(command);
Expand Down Expand Up @@ -561,7 +555,7 @@ class CommandsPlugin extends BasePlugin implements ICommandGroup<IContext> {
type: SlashCommandType.chat,
);

if (command is ChatCommand) {
if (command is ChatCommand && command.resolvedType != CommandType.textOnly) {
builder.registerHandler((interaction) => _processChatInteraction(interaction, command));

_processAutocompleteHandlerRegistration(builder.options, command);
Expand Down Expand Up @@ -608,6 +602,18 @@ class CommandsPlugin extends BasePlugin implements ICommandGroup<IContext> {
return builders;
}

bool _shouldGnerateBuildersFor(ICommandRegisterable<IContext> child) {
if (child is IChatCommandComponent) {
if (child.hasSlashCommand) {
return true;
}

return child is ChatCommand && child.type != CommandType.textOnly;
}

return true;
}

Future<Iterable<CommandPermissionBuilderAbstract>> _getPermissions(IChecked command) async {
Map<Snowflake, CommandPermissionBuilderAbstract> uniquePermissions = {};

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: 4.1.0
version: 4.1.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 a878331

Please sign in to comment.