-
-
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
base: master
Are you sure you want to change the base?
Add support for components V2 #2809
Conversation
e3ed5e3
to
cf0c7ef
Compare
- Remove generic from the ComponentReplacer parameter; I don't think it's possible to get the correct type - Refactor the replacing logic, move to IReplacerAware
Also add mutators, add to JSON
Co-authored-by: MinnDevelopment <[email protected]>
Co-authored-by: MinnDevelopment <[email protected]>
Co-authored-by: MinnDevelopment <[email protected]>
Co-authored-by: MinnDevelopment <[email protected]>
Co-authored-by: MinnDevelopment <[email protected]>
- `button` -> `buttons` - `selects` -> `selections`
@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)
```
As !isEnabled != isDisabled
Also removes LayoutComponent#updateComponent methods as they will fail
It's unnecessary to document those on WebhookClient's send methods, as the CV2 flag is not taken into account when deferring
You're saying you have an issue but didn't describe what the issue is |
Pull Request Etiquette
Changes
Closes Issue: NaN
Description
This adds the new component system (aka Components V2).
API docs: discord/discord-api-docs#7487
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.
Maintainers note
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.It is recommended to optimize imports (
Code | Optimize imports
in IntelliJ) after migrating.