Fix webhook support

This commit is contained in:
Vankka 2023-06-18 14:00:02 +03:00
parent d6a21b6fca
commit 3d6c7f72de
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
6 changed files with 17 additions and 9 deletions

View File

@ -53,7 +53,8 @@ subprojects {
includeGroup 'me.scarsz'
includeGroup 'me.minecraftauth'
includeGroup 'org.spongepowered' // Configurate yamlbranch
includeGroup 'org.spongepowered' // SpongePowered/Configurate feature/yaml-improvements branch
includeGroup 'net.dv8tion' // DiscordSRV/JDA v5-webhooks branch
}
}
maven {

View File

@ -56,6 +56,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.*;
import java.util.function.BiConsumer;
@ -523,10 +524,11 @@ public class DiscordAPIImpl implements DiscordAPI {
return textChannel.createWebhook("DSRV").submit();
}).thenApply(webhook ->
WebhookClientBuilder.fromJDA(webhook)
.setHttpClient(jda.getHttpClient())
.setExecutorService(discordSRV.scheduler().scheduledExecutorService())
.build()
WebhookClient.createClient(
webhook.getJDA(),
webhook.getId(),
Objects.requireNonNull(webhook.getToken())
)
);
}
}

View File

@ -91,7 +91,11 @@ public abstract class AbstractDiscordGuildMessageChannel<T extends GuildMessageC
CompletableFuture<R> createRequest;
if (message.isWebhookMessage()) {
createRequest = queryWebhookClient().thenApply(client -> (R) client.sendMessage(createData));
createRequest = queryWebhookClient()
.thenApply(client -> (R) client.sendMessage(createData)
.setUsername(message.getWebhookUsername())
.setAvatarUrl(message.getWebhookAvatarUrl())
);
} else {
createRequest = CompletableFuture.completedFuture(((R) channel.sendMessage(createData)));
}

View File

@ -29,6 +29,7 @@ import net.dv8tion.jda.api.entities.channel.ChannelType;
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.middleman.MessageChannel;
import net.dv8tion.jda.internal.requests.IncomingWebhookClient;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
@ -52,7 +53,7 @@ public class DiscordThreadChannelImpl extends AbstractDiscordGuildMessageChannel
public CompletableFuture<WebhookClient<Message>> queryWebhookClient() {
return discordSRV.discordAPI()
.queryWebhookClient(getParentChannel().getId())
.thenApply(client -> null/* client.onThread(getId())*/); // TODO
.thenApply(client -> ((IncomingWebhookClient) client).withThreadId(Long.toUnsignedString(getId())));
}
@Override

View File

@ -76,7 +76,7 @@ public class ReceivedDiscordMessageImpl implements ReceivedDiscordMessage {
);
if (clientFuture != null) {
long clientId = clientFuture.join().getId(); // TODO
long clientId = clientFuture.join().getIdLong();
self = clientId == user.getId();
}
} else {

View File

@ -56,7 +56,7 @@ dependencyResolutionManagement {
library('findbugs-annotations', 'com.google.code.findbugs', 'jsr305').version('3.0.2')
// JDA
library('jda', 'net.dv8tion', 'JDA').version('5.0.0-beta.10')
library('jda', 'net.dv8tion', 'JDA').version('5.0.0-beta.10.webhooks_2')
library('okhttp', 'com.squareup.okhttp3', 'okhttp').version {
prefer '3.14.9'
reject '[4,)' // Kotlin