feat: delete-all button and language dropdown for multi-message code blocks#550
feat: delete-all button and language dropdown for multi-message code blocks#550Neil-Tomar wants to merge 1 commit into
Conversation
…ching Delete-all button removes every message of a block; ephemeral language dropdown re-colors every chunk. Only the bot's own messages are touched.
| @AutoDetectableComponentHandler(FormatCodeInteractionHandler.COMPONENT_ID) | ||
| @RequiredArgsConstructor | ||
| public class FormatCodeInteractionHandler implements ButtonHandler, StringSelectMenuHandler { | ||
| static final String COMPONENT_ID = "format-code-delete"; |
There was a problem hiding this comment.
The select menu isn't about deleting hence the id format-code-delete isn't appropriate.
| * @return the delete-all button | ||
| */ | ||
| public static Button createDeleteAllButton(long requesterID, int total){ | ||
| return Button.secondary(ComponentIdBuilder.build(COMPONENT_ID,requesterID,total),"\uD83D\uDDD1️"); |
There was a problem hiding this comment.
I am not sure why such a special 1 character is used by InteractionUtils but it would be good if you could change it to use a normal 1 instead of it.
| } | ||
|
|
||
| @Override | ||
| public void handleStringSelectMenu(@NonNull StringSelectInteractionEvent event, @NonNull List<String> values) { |
There was a problem hiding this comment.
The indentation is messed up here.
| } | ||
|
|
||
| event.deferEdit().queue(); | ||
| var channel = event.getChannel(); |
There was a problem hiding this comment.
Could you please use the proper type here? I assume it's a MessageChannel?
| Language language = Language.fromString(values.getFirst()); | ||
| event.deferEdit().queue(); | ||
|
|
||
| LinkedMessages.resolveForward(event.getChannel(), event.getMessage(), Integer.parseInt(id[2]), |
There was a problem hiding this comment.
Is the channel argument really needed here? Can't you derive it from the message?
| * @param total the number of messages in the block | ||
| * @param onResolved receives the bot's messages that make up the block | ||
| */ | ||
| static void resolve(MessageChannel channel, Message triggerMessage, int total, Consumer<List<Message>> onResolved) { |
There was a problem hiding this comment.
I think you don't need the channel argument as you can use triggerMessage.getChannel() instead?
| * @param total the number of messages in the block | ||
| * @param onResolved receives the bot's messages that make up the block | ||
| */ | ||
| static void resolveForward(MessageChannel channel, Message anchorMessage, int total, Consumer<List<Message>> onResolved) { |
There was a problem hiding this comment.
I think you don't need the channel argument as you can use anchorMessage.getChannel() instead?
| event.deferEdit().queue(); | ||
| var channel = event.getChannel(); | ||
| LinkedMessages.resolve(channel, event.getMessage(), Integer.parseInt(id[2]), | ||
| messages -> messages.forEach(message -> message.delete().queue())); |
There was a problem hiding this comment.
Could you please use the purgeMessages method here instead? https://javadoc.io/static/net.dv8tion/JDA/5.0.0-alpha.5/net/dv8tion/jda/api/entities/MessageChannel.html#purgeMessages(java.util.List)
| */ | ||
| static void resolveForward(MessageChannel channel, Message anchorMessage, int total, Consumer<List<Message>> onResolved) { | ||
| channel.getHistoryAfter(anchorMessage.getIdLong(), total).queue(history -> | ||
| onResolved.accept(onlyOwn(channel, history.getRetrievedHistory()))); |
There was a problem hiding this comment.
Please also perform the same message check/error handling approach here as well.
| onResolved.accept(onlyOwn(channel, history.getRetrievedHistory()))); | ||
| } | ||
|
|
||
| private static List<Message> onlyOwn(MessageChannel channel, List<Message> messages) { |
There was a problem hiding this comment.
I think the channel argument isn't used here?
What
Multi-message formatted code blocks now have two interactions, backed by a small message-linking helper:
How
Open questions