Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy 6.0.1 #148

Merged
merged 5 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class CommandsPlugin extends NyxxPlugin<NyxxGateway> implements CommandGroup<Com
throw CommandsError('Cannot have more than one GuildCheck per command');
}

final guilds = guildChecks.singleOrNull?.guildIds ?? [null];
final guilds = guildChecks.singleOrNull?.guildIds ?? [guild];
for (final id in guilds) {
(result[id] ??= []).add(builder);
}
Expand Down
47 changes: 28 additions & 19 deletions lib/src/util/mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ mixin InteractiveMixin implements InteractiveContext, ContextData {
return _parent!._nearestCommandContext;
}

Future<Message> _updateMessage(
InteractiveContext context,
Message message,
MessageUpdateBuilder builder,
) async {
return switch (context) {
InteractionContextData(:MessageResponse<dynamic> interaction) =>
interaction.updateFollowup(message.id, builder),
_ => message.update(builder),
};
}

@override
Future<ButtonComponentContext> awaitButtonPress(ComponentId componentId) async {
if (delegate != null) {
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -462,6 +472,7 @@ mixin InteractiveMixin implements InteractiveContext, ContextData {

SelectMenuBuilder? menu;
Message? message;
InteractiveContext? responseContext;

try {
do {
Expand Down Expand Up @@ -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<ActionRowBuilder> rows = builder.components!;
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -645,6 +658,8 @@ mixin InteractionRespondMixin

@override
Future<Message> respond(MessageBuilder builder, {ResponseLevel? level}) async {
builder = MessageCreateUpdateBuilder.fromMessageBuilder(builder);

await _acknowledgeLock;

if (_delegate != null) {
Expand All @@ -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();
}

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.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
Expand Down
Loading