Skip to content

Commit

Permalink
Revert "rewriting DiscordClient"
Browse files Browse the repository at this point in the history
This reverts commit 9703fde.
  • Loading branch information
RichtXO committed Apr 5, 2024
1 parent 9703fde commit f9daf30
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions src/main/java/com/richtxo/LilMo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.track.playback.NonAllocatingAudioFrameBuffer;
import discord4j.core.DiscordClient;
import discord4j.core.DiscordClientBuilder;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
import discord4j.core.event.domain.lifecycle.ReadyEvent;
import discord4j.core.object.entity.User;
import discord4j.core.object.presence.ClientActivity;
import discord4j.core.object.presence.ClientPresence;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;

public class LilMo {
public static final Logger LOGGER = LoggerFactory.getLogger(LilMo.class);
Expand All @@ -28,28 +26,28 @@ public class LilMo {
}

public static void main(String[] args){
final DiscordClient client = DiscordClient.create(System.getenv("TOKEN"));
client.gateway().setInitialPresence(s -> ClientPresence.online(
ClientActivity.listening("/play").withState("Give me more music!")));

Mono<Void> login = client.withGateway(gatewayDiscordClient -> {
Mono<Void> printOnLogin = gatewayDiscordClient.on(ReadyEvent.class, event ->
Mono.fromRunnable(() -> {
final User self = event.getSelf();
LOGGER.debug("Logged in as {}", self.getUsername());
}))
.then();

// Adding commands
try { new CommandRegistrar(client).registerCmds(); }
catch (Exception e) { LOGGER.error("Error trying to register commands: ", e); }

Mono<Void> handleCommand = gatewayDiscordClient.on(ChatInputInteractionEvent.class, Listener::handle)
.then();

return printOnLogin.and(handleCommand);
});

login.block();
final GatewayDiscordClient client = DiscordClientBuilder.create(System.getenv("TOKEN"))
// .onClientResponse(
// ResponseFunction.retryWhen(
// RouteMatcher.any(),
// Retry.anyOf(SslHandler.class)))
.build()
.gateway()
.setInitialPresence(s -> ClientPresence.online(
ClientActivity.listening("/play").withState("Give me more music!")))
.login()
.block();

// Adding commands
try {
assert client != null;
new CommandRegistrar(client.getRestClient()).registerCmds();
} catch (Exception e) {
LOGGER.error("Error trying to register commands: ", e);
}

client.on(ChatInputInteractionEvent.class, Listener::handle)
.then(client.onDisconnect())
.block();
}
}

0 comments on commit f9daf30

Please sign in to comment.