Add a delayed log method
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-08-25 22:37:32 +02:00
parent 4853e7e07c
commit 188eafa2ee
2 changed files with 26 additions and 5 deletions

View File

@ -31,20 +31,24 @@ public class HidekoBot
try
{
// try to create the bot object and authenticate it with discord.
jdaBuilder = JDABuilder.createDefault(botToken);
jdaBuilder.setActivity(Activity.playing("the piano"));
jda = jdaBuilder.build();
} catch (LoginException e)
{
logger.log(e.getMessage());
return;
logger.log(e.getMessage()); // print the error message, omit the stack trace.
return; // if we failed connecting and authenticating, then quit.
}
// find the bot's user id and generate an invite-link.
botUserId = jda.getSelfUser().getId();
standardInviteLink = standardInviteLink.replace("%userid%", botUserId);
logger.log("Bot User ID: " + botUserId);
logger.log("Invite Link: " + standardInviteLink);
// log the invite-link to console so noob users can just click on it.
logger.log("Bot User ID: " + botUserId, 10);
logger.log("Invite Link: " + standardInviteLink, 10);
}

View File

@ -2,6 +2,9 @@ package wtf.beatrice.hidekobot.utils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Logger
{
@ -28,4 +31,18 @@ public class Logger
.replace("%class%", className)
.replace("%message%", message));
}
// log a message to console after delaying it (in seconds).
public void log(String message, int delay)
{
Executors.newSingleThreadScheduledExecutor().schedule(new Runnable()
{
@Override
public void run()
{
log(message);
}
}, delay, TimeUnit.SECONDS);
}
}