diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e5cce8..747b233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 6.0.1 +__Bug fixes__ +- Fixed ephemeral response levels breaking component helpers. +- Fixed `getMultiSelection` not working. +- `CommandsPlugin.guild` is not longer ignored. + ## 6.0.0 __Breaking changes__ - Update nyxx to version 6.0.0. diff --git a/example/example.dart b/example/example.dart index 5be18e5..62668db 100644 --- a/example/example.dart +++ b/example/example.dart @@ -113,6 +113,7 @@ 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/lib/src/commands.dart b/lib/src/commands.dart index cd62c03..082704f 100644 --- a/lib/src/commands.dart +++ b/lib/src/commands.dart @@ -362,7 +362,7 @@ class CommandsPlugin extends NyxxPlugin implements CommandGroup _updateMessage( + InteractiveContext context, + Message message, + MessageUpdateBuilder builder, + ) async { + return switch (context) { + InteractionContextData(:MessageResponse interaction) => + interaction.updateFollowup(message.id, builder), + _ => message.update(builder), + }; + } + @override Future awaitButtonPress(ComponentId componentId) async { if (delegate != null) { @@ -372,9 +384,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { commands.eventManager.stopListeningFor(id); } - await message.update( - MessageUpdateBuilder(components: disabledComponentRows), - ); + await _updateMessage(this, message, MessageUpdateBuilder(components: disabledComponentRows)); } } @@ -462,6 +472,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { SelectMenuBuilder? menu; Message? message; + InteractiveContext? responseContext; try { do { @@ -494,6 +505,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { (builder.components ??= []).add(row); message = await respond(builder, level: level); + responseContext = this; } else { // On later iterations, replace the last row with our newly created one. List rows = builder.components!; @@ -505,6 +517,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { level: (level ?? _nearestCommandContext.command.resolvedOptions.defaultResponseLevel)! .copyWith(preserveComponentMessages: false), ); + responseContext = context; } context = await commands.eventManager.nextSelectMenuEvent(menuId); @@ -537,9 +550,9 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { _nearestCommandContext, )..stackTrace = s; } finally { - if (menu != null && message != null) { + if (menu != null && message != null && responseContext != null) { menu.isDisabled = true; - await message.edit(MessageCreateUpdateBuilder.fromMessageBuilder(builder)); + await _updateMessage(this, message, MessageCreateUpdateBuilder.fromMessageBuilder(builder)); } } } @@ -594,7 +607,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { type: MessageComponentType.stringSelect, customId: menuId.toString(), options: options, - minValues: choices.length, + maxValues: choices.length, ); ActionRowBuilder row = ActionRowBuilder(components: [menu]); @@ -628,7 +641,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData { )..stackTrace = s; } finally { menu.isDisabled = true; - await message.edit(MessageCreateUpdateBuilder.fromMessageBuilder(builder)); + await _updateMessage(this, message, MessageCreateUpdateBuilder.fromMessageBuilder(builder)); } } } @@ -645,6 +658,8 @@ mixin InteractionRespondMixin @override Future respond(MessageBuilder builder, {ResponseLevel? level}) async { + builder = MessageCreateUpdateBuilder.fromMessageBuilder(builder); + await _acknowledgeLock; if (_delegate != null) { @@ -671,24 +686,18 @@ mixin InteractionRespondMixin return interaction.createFollowup(builder, isEphemeral: level.hideInteraction); } - // If we want to preserve the original message a component is attached to, we can just send a - // followup instead of a response. - // Also, if we are requested to hide interactions, also send a followup, or - // components will just edit the original message (making it public). - if (level.hideInteraction) { - await interaction.respond(builder, isEphemeral: level.hideInteraction); - return interaction.fetchOriginalResponse(); - } - - if (interaction is MessageComponentInteraction) { + // Only update the message if we don't want to preserve it and the message's ephemerality + // matches whether we want the response to be ephemeral or not. + if (interaction is MessageComponentInteraction && + !level.preserveComponentMessages && + interaction.message?.flags.isEphemeral == level.hideInteraction) { // Using interactionEvent.respond is actually the same as editing a message in the case where // the interaction is a message component. In those cases, leaving `componentRows` as `null` // would leave the existing components on the message - which likely isn't what our users // expect. Instead, we override them and set the builder to have no components. builder.components ??= []; - await (interaction as MessageComponentInteraction) - .respond(builder, updateMessage: !level.preserveComponentMessages); + await (interaction as MessageComponentInteraction).respond(builder, updateMessage: true); return interaction.fetchOriginalResponse(); } diff --git a/pubspec.yaml b/pubspec.yaml index 1bf4023..0faace5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: nyxx_commands -version: 6.0.0 +version: 6.0.1 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