diff --git a/build.gradle b/build.gradle index 007a845..176d5c7 100644 --- a/build.gradle +++ b/build.gradle @@ -31,5 +31,6 @@ repositories { } dependencies { + implementation 'com.discord4j:discord4j-core:3.1.1' implementation 'ch.qos.logback:logback-classic:1.2.3' } \ No newline at end of file diff --git a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java index 2c7448f..6c74513 100644 --- a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java +++ b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java @@ -1,19 +1,37 @@ package xyz.vallat.louis; +import discord4j.core.DiscordClientBuilder; +import discord4j.core.GatewayDiscordClient; +import discord4j.core.event.domain.lifecycle.ReadyEvent; +import discord4j.core.event.domain.message.MessageCreateEvent; +import discord4j.core.object.entity.Message; +import discord4j.core.object.entity.User; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MovieQuoteBot { - private static final Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName()); public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN"; + private static final Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName()); public static void main(String[] args) { if (System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null && args.length == 0) { logger.error("Missing token. Exiting."); System.exit(1); } - logger.debug("Hello World!"); + + GatewayDiscordClient client = DiscordClientBuilder.create( + System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null ? args[0] : System.getenv(DISCORD_TOKEN_ENVIRONMENT) + ).build().login().block(); + + assert client != null; + client.getEventDispatcher().on(ReadyEvent.class) + .subscribe(event -> { + User self = event.getSelf(); + logger.info("Logged in as {}#{}.", self.getUsername(), self.getDiscriminator()); + }); + + client.onDisconnect().block(); } } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 160c928..2319ec6 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -16,7 +16,7 @@ - logs/d4j.%d{yyyy-MM-dd}.%i.log + logs/mqb.%d{yyyy-MM-dd}.%i.log 100MB 90 @@ -35,7 +35,7 @@ - +