Update JDA back to upstream

This commit is contained in:
Vankka 2023-10-23 23:29:11 +03:00
parent 7a69a805a3
commit 671c006af3
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
3 changed files with 26 additions and 6 deletions

View File

@ -30,6 +30,8 @@ import net.dv8tion.jda.api.entities.WebhookClient;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.requests.RestAction; import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.api.utils.messages.MessageCreateRequest; import net.dv8tion.jda.api.utils.messages.MessageCreateRequest;
import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.api.utils.messages.MessageEditData;
@ -78,6 +80,10 @@ public abstract class AbstractDiscordGuildMessageChannel<T extends GuildMessageC
return sendInternal(message); return sendInternal(message);
} }
protected <R> WebhookMessageCreateAction<R> mapAction(WebhookMessageCreateAction<R> action) {
return action;
}
@SuppressWarnings("unchecked") // Generics @SuppressWarnings("unchecked") // Generics
private <R extends MessageCreateRequest<? extends MessageCreateRequest<?>> & RestAction<Message>> CompletableFuture<ReceivedDiscordMessage> sendInternal(SendableDiscordMessage message) { private <R extends MessageCreateRequest<? extends MessageCreateRequest<?>> & RestAction<Message>> CompletableFuture<ReceivedDiscordMessage> sendInternal(SendableDiscordMessage message) {
MessageCreateData createData = SendableDiscordMessageUtil.toJDASend(message); MessageCreateData createData = SendableDiscordMessageUtil.toJDASend(message);
@ -85,7 +91,7 @@ public abstract class AbstractDiscordGuildMessageChannel<T extends GuildMessageC
CompletableFuture<R> createRequest; CompletableFuture<R> createRequest;
if (message.isWebhookMessage()) { if (message.isWebhookMessage()) {
createRequest = queryWebhookClient() createRequest = queryWebhookClient()
.thenApply(client -> (R) client.sendMessage(createData) .thenApply(client -> (R) mapAction(client.sendMessage(createData))
.setUsername(message.getWebhookUsername()) .setUsername(message.getWebhookUsername())
.setAvatarUrl(message.getWebhookAvatarUrl()) .setAvatarUrl(message.getWebhookAvatarUrl())
); );
@ -114,6 +120,10 @@ public abstract class AbstractDiscordGuildMessageChannel<T extends GuildMessageC
return editInternal(id, message); return editInternal(id, message);
} }
protected <R> WebhookMessageEditAction<R> mapAction(WebhookMessageEditAction<R> action) {
return action;
}
@SuppressWarnings("unchecked") // Generics @SuppressWarnings("unchecked") // Generics
private <R extends MessageEditRequest<? extends MessageEditRequest<?>> & RestAction<Message>> CompletableFuture<ReceivedDiscordMessage> editInternal( private <R extends MessageEditRequest<? extends MessageEditRequest<?>> & RestAction<Message>> CompletableFuture<ReceivedDiscordMessage> editInternal(
long id, long id,
@ -123,7 +133,7 @@ public abstract class AbstractDiscordGuildMessageChannel<T extends GuildMessageC
CompletableFuture<R> editRequest; CompletableFuture<R> editRequest;
if (message.isWebhookMessage()) { if (message.isWebhookMessage()) {
editRequest = queryWebhookClient().thenApply(client -> (R) client.editMessageById(id, editData)); editRequest = queryWebhookClient().thenApply(client -> (R) mapAction(client.editMessageById(id, editData)));
} else { } else {
editRequest = CompletableFuture.completedFuture(((R) channel.editMessageById(id, editData))); editRequest = CompletableFuture.completedFuture(((R) channel.editMessageById(id, editData)));
} }

View File

@ -28,7 +28,8 @@ import net.dv8tion.jda.api.entities.WebhookClient;
import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer;
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
import net.dv8tion.jda.internal.requests.IncomingWebhookClient; import net.dv8tion.jda.api.requests.restaction.WebhookMessageCreateAction;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -49,8 +50,17 @@ public class DiscordThreadChannelImpl extends AbstractDiscordGuildMessageChannel
@Override @Override
public CompletableFuture<WebhookClient<Message>> queryWebhookClient() { public CompletableFuture<WebhookClient<Message>> queryWebhookClient() {
return discordSRV.discordAPI() return discordSRV.discordAPI()
.queryWebhookClient(getParentChannel().getId()) .queryWebhookClient(getParentChannel().getId());
.thenApply(client -> ((IncomingWebhookClient) client).withThreadId(Long.toUnsignedString(getId()))); }
@Override
protected <R> WebhookMessageCreateAction<R> mapAction(WebhookMessageCreateAction<R> action) {
return super.mapAction(action).setThreadId(getId());
}
@Override
protected <R> WebhookMessageEditAction<R> mapAction(WebhookMessageEditAction<R> action) {
return super.mapAction(action).setThreadId(getId());
} }
@Override @Override

View File

@ -56,7 +56,7 @@ dependencyResolutionManagement {
library('findbugs-annotations', 'com.google.code.findbugs', 'jsr305').version('3.0.2') library('findbugs-annotations', 'com.google.code.findbugs', 'jsr305').version('3.0.2')
// JDA // JDA
library('jda', 'net.dv8tion', 'JDA').version('5.0.0-beta.10.webhooks_2') library('jda', 'net.dv8tion', 'JDA').version('5.0.0-beta.16')
// OkHTTP // OkHTTP
library('okhttp', 'com.squareup.okhttp3', 'okhttp').version('4.11.0') library('okhttp', 'com.squareup.okhttp3', 'okhttp').version('4.11.0')