-
-
Notifications
You must be signed in to change notification settings - Fork 747
Add support for components V2 #2809
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
Add support for components V2 #2809
Conversation
e3ed5e3
to
cf0c7ef
Compare
7166b9d
to
c4790ff
Compare
src/main/java/net/dv8tion/jda/api/components/container/ContainerChildComponentUnion.java
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/attribute/IDisableable.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/button/Button.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/attribute/IDisableable.java
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/interactions/components/LayoutComponent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/entities/channel/middleman/MessageChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/entities/channel/middleman/MessageChannel.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/interactions/modals/ModalInteraction.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/utils/messages/MessageEditData.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/internal/components/actionrow/ActionRowImpl.java
Outdated
Show resolved
Hide resolved
@Override | ||
public DataObject toData() | ||
{ | ||
final String fileName = Helpers.getLastPathSegment(media.getUrl()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes a NullPointerException when creating a message that has a media gallery item
jda-ktx
calls MediaGalleryItem.fromUrl(url)
, which that calls the MediaGalleryItemImpl(String url)
constructor, and the media
parameter is set to null
final String mediaUrl;
if (this.media != null) {
final String fileName = Helpers.getLastPathSegment(media.getUrl());
mediaUrl = "attachment://" + fileName;
} else {
mediaUrl = this.url;
}
return DataObject.empty()
.put("media", DataObject.empty().put("url", mediaUrl))
.put("description", description)
.put("spoiler", spoiler);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that there is also other NPE related to the media.getUrl()
change, here's another stacktrace
java.lang.NullPointerException: Cannot invoke "net.dv8tion.jda.api.components.ResolvedMedia.getUrl()" because "this.media" is null
at net.dv8tion.jda.internal.components.mediagallery.MediaGalleryItemImpl.getFiles(MediaGalleryItemImpl.java:98)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1939)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at net.dv8tion.jda.api.utils.messages.MessageEditData.getAdditionalFiles(MessageEditData.java:373)
at net.dv8tion.jda.api.utils.messages.MessageEditData.toData(MessageEditData.java:339)
at net.dv8tion.jda.internal.requests.restaction.WebhookMessageEditActionImpl.finalizeData(WebhookMessageEditActionImpl.java:56)
at net.dv8tion.jda.internal.requests.RestActionImpl.submit(RestActionImpl.java:212)
at net.dv8tion.jda.internal.requests.restaction.TriggerRestAction.submit(TriggerRestAction.java:123)
at net.dv8tion.jda.api.requests.RestAction.submit(RestAction.java:703)
at net.perfectdreams.loritta.morenitta.utils.extensions.JDAExtensionsKt.await(JDAExtensions.kt:34)
at net.perfectdreams.loritta.morenitta.interactions.UnleashedHook$InteractionHook.editOriginal(UnleashedHook.kt:12)
at net.perfectdreams.loritta.morenitta.interactions.UnleashedHook$InteractionHook.editOriginal(UnleashedHook.kt:15)
at net.perfectdreams.loritta.morenitta.interactions.vanilla.fun.GiveawayBuilderScreen$Appearance$render$editGiveawayImageButton$1.invokeSuspend(GiveawayBuilderScreen.kt:477)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith$$$capture(ContinuationImpl.kt:33)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
```
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
src/main/java/net/dv8tion/jda/api/components/ComponentUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/ComponentUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/actionrow/ActionRowChildComponentUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/filedisplay/FileDisplay.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/filedisplay/FileDisplay.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/replacer/ComponentReplacer.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/components/replacer/ComponentReplacer.java
Show resolved
Hide resolved
So it can be immutable later
Removes unnecessary Modal.Builder#addComponents
Override when children needs to be inspected
ActionRow also got isValid, getActionComponents and getButtons
src/main/java/net/dv8tion/jda/api/interactions/modals/ModalTopLevelComponentUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/utils/messages/MessageEditData.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/utils/messages/MessageRequest.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/utils/messages/MessageRequest.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/internal/components/thumbnail/ThumbnailFileUpload.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/internal/components/utils/ComponentsUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/internal/components/utils/ComponentsUtil.java
Outdated
Show resolved
Hide resolved
src/test/java/net/dv8tion/jda/test/compliance/ComponentConsistencyComplianceTest.java
Outdated
Show resolved
Hide resolved
src/test/java/net/dv8tion/jda/test/components/ContainerTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: MinnDevelopment <[email protected]>
Co-authored-by: MinnDevelopment <[email protected]>
Asking for unions is unnecessary, they will be cast anyway
- Ensure no empty list is passed - Add each component in the currently built row
Co-authored-by: MinnDevelopment <[email protected]>
This reverts commit 325c55d.
Co-authored-by: MinnDevelopment <[email protected]>
Pull Request Etiquette
Changes
Closes Issue: NaN
Description
This adds the new component system (aka Components V2).
API docs:
Examples: ComponentsV2Example.java
Make sure to give your opinion on the JDA dev thread.
Supersedes #2806.
Installation (Preview)
You can use the "Using new features" guide from the JDA wiki.
Alternatively, you can get the newest version for your favorite tool, by using the
/jitpack pr
command in the JDA Discord server. You can use theUpdate PR
button to merge the latest changes if necessary (note that it may not update it if there are conflicts).Migration (Preview)
I've written an OpenRewrite recipe to update most (if not all) breaking changes.
Requirements
net.dv8tion
)Usage
As with any migration tool, it is highly recommended to commit/push your changes before doing anything.
Note: Kotlin 2.X is not supported by OpenRewrite yet, however 1.X should work.
(Kotlin) Gradle
Checking changes (dry run)
Run the
rewriteDryRun
task, this can be done by pressing CTRL twice on IntelliJ then runninggradle rewriteDryRun
.This will generate a diff file at
build/reports/rewrite/rewrite.patch
, you can check the possible changes there.Applying changes
Run the
rewriteRun
task.Maven
Checking changes (dry run)
Run the
rewrite:dryRun
goal, this can be done by pressing CTRL twice on IntelliJ then runningmvn rewrite:dryRun
.This will generate a diff file at
target/site/rewrite/rewrite.patch
, you can check the possible changes there.Applying changes
Run the
rewrite:run
goal.You can then set the JDA dependency, as JDA 6.0.0 is not released.
It is recommended to optimize imports (
Code | Optimize imports
in IntelliJ) after migrating.