Skip to content

Commit

Permalink
feat(followup): fixed followup action and files
Browse files Browse the repository at this point in the history
  • Loading branch information
seailz committed Sep 23, 2023
1 parent 5fccdcf commit 25fca2d
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.seailz.discordjar.action.interaction.followup;

import com.seailz.discordjar.DiscordJar;
import com.seailz.discordjar.action.interaction.MessageInteractionCallbackAction;
import com.seailz.discordjar.model.component.DisplayComponent;
import com.seailz.discordjar.model.embed.Embeder;
import com.seailz.discordjar.model.interaction.callback.InteractionHandler;
Expand All @@ -12,6 +13,7 @@
import com.seailz.discordjar.utils.rest.Response;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.File;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -139,14 +141,29 @@ public InteractionFollowupAction addEmbed(Embeder embed) {
return this;
}

public InteractionFollowupAction addFile(File file) {
this.getReply().addFile(file);
return this;
}

public InteractionFollowupAction addFiles(File... files) {
this.getReply().addFiles(files);
return this;
}

public InteractionFollowupAction addFiles(List<File> files) {
this.getReply().addFiles(files);
return this;
}

public InteractionMessageResponse getReply() {
return reply;
}

public Response<InteractionHandler> run() {
Response<InteractionHandler> response = new Response<>();
try {
new DiscordRequest(
DiscordRequest req = new DiscordRequest(
getReply().compile(),
new HashMap<>(),
URLS.POST.INTERACTIONS.FOLLOWUP
Expand All @@ -155,7 +172,16 @@ public Response<InteractionHandler> run() {
discordJar,
URLS.POST.INTERACTIONS.FOLLOWUP,
RequestMethod.POST
).invoke();
);

if (getReply().useFiles()) {
List<File> files = getReply().getFiles();
File[] filesArray = new File[files.size()];
filesArray = files.toArray(filesArray);
req.invokeWithFiles(filesArray);
} else {
req.invoke();
}
response.complete(InteractionHandler.from(token, id, discordJar));
} catch (DiscordRequest.UnhandledDiscordAPIErrorException e) {
response.completeError(new Response.Error(e.getCode(), e.getMessage(), e.getBody()));
Expand Down

0 comments on commit 25fca2d

Please sign in to comment.