Refactor Discord token retrieval by prioritizing environment variable and update lambda formatting in DiscordSender.
This commit is contained in:
parent
1bf08fb4fc
commit
20c89a4f8e
|
|
@ -7,11 +7,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
public class DiscordBot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String discordToken = System.getProperty("DISCORD_TOKEN");
|
||||
if (discordToken == null) {
|
||||
log.error("Discord token not found, put it in the DISCORD_TOKEN environment variable");
|
||||
System.exit(1);
|
||||
}
|
||||
DiscordBotInstance discordBotInstance = DiscordBotInstance.getInstance();
|
||||
discordBotInstance.getJda();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import net.dv8tion.jda.api.JDA;
|
|||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
public class DiscordBotInstance {
|
||||
|
||||
|
|
@ -22,8 +24,8 @@ public class DiscordBotInstance {
|
|||
|
||||
public JDA getJda() {
|
||||
if (jda == null) {
|
||||
String discordToken = System.getProperty("DISCORD_TOKEN");
|
||||
log.info("env:\n{}", System.getenv());
|
||||
String discordToken = Optional.ofNullable(System.getenv("DISCORD_TOKEN"))
|
||||
.orElse(System.getProperty("DISCORD_TOKEN"));
|
||||
if (discordToken == null) {
|
||||
log.error("Discord token not found, put it in the DISCORD_TOKEN environment variable");
|
||||
System.exit(1);
|
||||
|
|
|
|||
|
|
@ -69,9 +69,8 @@ public class DiscordSender {
|
|||
result.stream()
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.forEach(message -> {
|
||||
message.createThreadChannel(threadName).queue();
|
||||
});
|
||||
.forEach(message ->
|
||||
message.createThreadChannel(threadName).queue());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user