mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-26 17:18:29 +01:00
Fix webhook support
This commit is contained in:
parent
d6a21b6fca
commit
3d6c7f72de
@ -53,7 +53,8 @@ subprojects {
|
|||||||
includeGroup 'me.scarsz'
|
includeGroup 'me.scarsz'
|
||||||
includeGroup 'me.minecraftauth'
|
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 {
|
maven {
|
||||||
|
@ -56,6 +56,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -523,10 +524,11 @@ public class DiscordAPIImpl implements DiscordAPI {
|
|||||||
|
|
||||||
return textChannel.createWebhook("DSRV").submit();
|
return textChannel.createWebhook("DSRV").submit();
|
||||||
}).thenApply(webhook ->
|
}).thenApply(webhook ->
|
||||||
WebhookClientBuilder.fromJDA(webhook)
|
WebhookClient.createClient(
|
||||||
.setHttpClient(jda.getHttpClient())
|
webhook.getJDA(),
|
||||||
.setExecutorService(discordSRV.scheduler().scheduledExecutorService())
|
webhook.getId(),
|
||||||
.build()
|
Objects.requireNonNull(webhook.getToken())
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,11 @@ public abstract class AbstractDiscordGuildMessageChannel<T extends GuildMessageC
|
|||||||
|
|
||||||
CompletableFuture<R> createRequest;
|
CompletableFuture<R> createRequest;
|
||||||
if (message.isWebhookMessage()) {
|
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 {
|
} else {
|
||||||
createRequest = CompletableFuture.completedFuture(((R) channel.sendMessage(createData)));
|
createRequest = CompletableFuture.completedFuture(((R) channel.sendMessage(createData)));
|
||||||
}
|
}
|
||||||
|
@ -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.attribute.IThreadContainer;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
|
||||||
|
import net.dv8tion.jda.internal.requests.IncomingWebhookClient;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@ -52,7 +53,7 @@ public class DiscordThreadChannelImpl extends AbstractDiscordGuildMessageChannel
|
|||||||
public CompletableFuture<WebhookClient<Message>> queryWebhookClient() {
|
public CompletableFuture<WebhookClient<Message>> queryWebhookClient() {
|
||||||
return discordSRV.discordAPI()
|
return discordSRV.discordAPI()
|
||||||
.queryWebhookClient(getParentChannel().getId())
|
.queryWebhookClient(getParentChannel().getId())
|
||||||
.thenApply(client -> null/* client.onThread(getId())*/); // TODO
|
.thenApply(client -> ((IncomingWebhookClient) client).withThreadId(Long.toUnsignedString(getId())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -76,7 +76,7 @@ public class ReceivedDiscordMessageImpl implements ReceivedDiscordMessage {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (clientFuture != null) {
|
if (clientFuture != null) {
|
||||||
long clientId = clientFuture.join().getId(); // TODO
|
long clientId = clientFuture.join().getIdLong();
|
||||||
self = clientId == user.getId();
|
self = clientId == user.getId();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -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')
|
library('jda', 'net.dv8tion', 'JDA').version('5.0.0-beta.10.webhooks_2')
|
||||||
library('okhttp', 'com.squareup.okhttp3', 'okhttp').version {
|
library('okhttp', 'com.squareup.okhttp3', 'okhttp').version {
|
||||||
prefer '3.14.9'
|
prefer '3.14.9'
|
||||||
reject '[4,)' // Kotlin
|
reject '[4,)' // Kotlin
|
||||||
|
Loading…
Reference in New Issue
Block a user