Skip to content

Commit

Permalink
init#4
Browse files Browse the repository at this point in the history
  • Loading branch information
Panos Karampis committed Sep 21, 2024
1 parent 9aedf7f commit 25333c0
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/main/java/dk/promofacie/wallet_verification/DiscordApiDI.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<JDA> 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());
}
});
}

}

0 comments on commit 25333c0

Please sign in to comment.