Added basic login
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
70a075660b
commit
c9e25131a5
@ -31,5 +31,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.discord4j:discord4j-core:3.1.1'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.3'
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
<!-- Log to a file as well, including size and time based rolling -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>logs/d4j.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<fileNamePattern>logs/mqb.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<maxHistory>90</maxHistory>
|
||||
</rollingPolicy>
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
<!-- Here you can set the base logger level. If DEBUG is too chatty for you, you can use INFO -->
|
||||
<!-- Possible options are: ALL, TRACE, DEBUG, INFO, WARN, ERROR, OFF -->
|
||||
<root level="ALL">
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
|
Loading…
Reference in New Issue
Block a user