diff --git a/src/main/java/dk/promofacie/wallet_verification/DiscordApiDI.java b/src/main/java/dk/promofacie/wallet_verification/DiscordApiDI.java index 39d579f..afe2822 100644 --- a/src/main/java/dk/promofacie/wallet_verification/DiscordApiDI.java +++ b/src/main/java/dk/promofacie/wallet_verification/DiscordApiDI.java @@ -1,6 +1,8 @@ package dk.promofacie.wallet_verification; import io.smallrye.common.annotation.Blocking; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; import jakarta.inject.Singleton; import jakarta.ws.rs.Produces; import net.dv8tion.jda.api.JDA; @@ -13,27 +15,40 @@ import net.dv8tion.jda.api.utils.ChunkingFilter; import net.dv8tion.jda.api.utils.MemberCachePolicy; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.context.ManagedExecutor; +import java.util.concurrent.CompletionStage; + +@ApplicationScoped public class DiscordApiDI { + @Inject + ManagedExecutor executor; + @ConfigProperty(name = "discord_api_key") String apiKey; @Produces @Singleton - public JDA discordAPI() { - try { - SlashCommandData verifyCommand = Commands.slash("verify", "Verify your address") - .addOption(OptionType.STRING, "address", "Your address", true); - - JDA jda = JDABuilder.create(apiKey, GatewayIntent.GUILD_MEMBERS).setChunkingFilter(ChunkingFilter.ALL).setEventPassthrough(true).setMemberCachePolicy(MemberCachePolicy.ALL).setActivity(Activity.playing("Wallet verifier")) - .build() - .awaitReady(); - jda.updateCommands().addCommands(verifyCommand).queue(); - return jda; - } catch (InterruptedException e) { - throw new RuntimeException(e.getMessage()); - } + public CompletionStage discordAPI() { + return executor.supplyAsync(() -> { + try { + SlashCommandData verifyCommand = Commands.slash("verify", "Verify your address") + .addOption(OptionType.STRING, "address", "Your address", true); + + JDA jda = JDABuilder.create(apiKey, GatewayIntent.GUILD_MEMBERS) + .setChunkingFilter(ChunkingFilter.ALL) + .setEventPassthrough(true) + .setMemberCachePolicy(MemberCachePolicy.ALL) + .setActivity(Activity.playing("Wallet verifier")) + .build() + .awaitReady(); + jda.updateCommands().addCommands(verifyCommand).queue(); + return jda; + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage()); + } + }); } }