Skip to content

Commit

Permalink
Adding log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
RichtXO committed Apr 5, 2024
1 parent f9daf30 commit 0cad5be
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/main/java/com/richtxo/LilMo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
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.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 @@ -26,28 +28,32 @@ public class LilMo {
}

public static void main(String[] args){
final GatewayDiscordClient client = DiscordClientBuilder.create(System.getenv("TOKEN"))
// .onClientResponse(
// ResponseFunction.retryWhen(
// RouteMatcher.any(),
// Retry.anyOf(SslHandler.class)))
.build()
// Checking if all env variables are present
if (System.getenv("TOKEN") == null) {
LOGGER.error("Discord Token not set!");
return;
}
if (System.getenv("SPOTIFY_CLIENT_ID") == null || System.getenv("SPOTIFY_SECRET") == null) {
LOGGER.error("Spotify credentials not set!");
return;
}

final GatewayDiscordClient client = DiscordClientBuilder.create(System.getenv("TOKEN")).build()
.gateway()
.setInitialPresence(s -> ClientPresence.online(
ClientActivity.listening("/play").withState("Give me more music!")))
.login()
.block();
.login().block();

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

client.on(ChatInputInteractionEvent.class, Listener::handle)
.then(client.onDisconnect())
.block();
Mono.when(client.on(ReadyEvent.class).doOnNext(readyEvent -> LOGGER.info("Logged in as {}",
readyEvent.getSelf().getUsername())),
client.on(ChatInputInteractionEvent.class, Listener::handle),
client.onDisconnect().doOnTerminate(() -> LOGGER.info("Disconnected!")))
.block();
}
}

0 comments on commit 0cad5be

Please sign in to comment.