Changed to new logging, static implementation for now which is not ideal, but it's not worth spending the time to fix it right now

This commit is contained in:
2023-05-21 21:54:59 +02:00
parent 0ae96bd6e5
commit 94f1d566ac
39 changed files with 164 additions and 217 deletions
@@ -30,7 +30,7 @@ public class AuctionScheduler {
instance = this;
auctions = QueriesAuction.getAuctions();
if (auctions == null) {
Logger.severe("Unable to retrieve auctions");
Logger.altitudeLogs.error("Unable to retrieve auctions");
instance = null;
return;
}
@@ -41,10 +41,7 @@ public class AuctionScheduler {
private void setNextAuction() {
Optional<Auction> first = auctions.values().stream().sorted().findFirst();
if (first.isEmpty())
nextAuction = null;
else
nextAuction = first.get();
nextAuction = first.orElse(null);
}
public static AuctionScheduler getInstance() {
@@ -55,7 +52,7 @@ public class AuctionScheduler {
public synchronized void addAuction(Auction auction) {
if (!QueriesAuction.saveAuction(auction))
Logger.warning("Unable to save auction %", auction.getMessageId() + "");
Logger.altitudeLogs.warning("Unable to save auction " + auction.getMessageId());
auctions.put(auction.getMessageId(), auction);
setNextAuction();
}
@@ -69,7 +66,7 @@ public class AuctionScheduler {
auctions.remove(auction.getMessageId());
setNextAuction();
if (!QueriesAuction.removeAuction(auction))
Logger.warning("Unable to remove auction %", auction.getMessageId() + "");
Logger.altitudeLogs.warning("Unable to remove auction " + auction.getMessageId());
}
public Auction getAuction(long messageId) {
@@ -80,17 +77,17 @@ public class AuctionScheduler {
auction.updateMessage(success -> {
List<MessageEmbed> embeds = success.getEmbeds();
if (embeds.isEmpty()) {
Logger.warning("Received auction with no embed contents");
Logger.altitudeLogs.warning("Received auction with no embed contents");
return;
}
GuildChannel outputChannel = CommandOutputChannels.getOutputChannel(success.getGuild(), OutputType.AUCTION_LOG);
if (outputChannel != null) {
if (!(outputChannel instanceof GuildMessageChannel channel)) {
Logger.warning("Error" + outputChannel.getType().name() + " is not a valid crate auction log channel type");
Logger.altitudeLogs.warning("Error" + outputChannel.getType().name() + " is not a valid crate auction log channel type");
return;
}
if (!channel.canTalk()) {
Logger.warning("Error can't talk in auction log channel");
Logger.altitudeLogs.warning("Error can't talk in auction log channel");
return;
}
if (sendEmbed(embeds.get(0), channel, instaBuy))
@@ -129,7 +126,7 @@ public class AuctionScheduler {
embedBuilder.setColor(Color.GREEN);
else
embedBuilder.setColor(Color.RED);
textChannel.sendMessageEmbeds(embedBuilder.build()).queue(Util::ignoreSuccess, failure -> Logger.warning("Failed to log auction result"));
textChannel.sendMessageEmbeds(embedBuilder.build()).queue(Util::ignoreSuccess, failure -> Logger.altitudeLogs.warning("Failed to log auction result"));
return true;
}
private class AuctionRun implements Runnable {
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -37,7 +36,7 @@ public class ReminderScheduler {
this.jda = jda;
reminders = QueriesReminders.getReminders();
if (reminders == null) {
Logger.severe("Unable to retrieve reminders");
Logger.altitudeLogs.error("Unable to retrieve reminders");
instance = null;
return;
}
@@ -58,12 +57,14 @@ public class ReminderScheduler {
}
public synchronized void addReminder(Reminder reminder) {
Logger.altitudeLogs.debug("Adding reminder with messageId: " + reminder.messageId());
reminders.add(reminder);
reminders.sort(Comparator.comparingLong(Reminder::remindDate));
nextReminder = reminders.get(0);
}
public synchronized void removeReminder(Reminder reminder, boolean removeFromDatabase) {
Logger.altitudeLogs.debug("Removing reminder with messageId: " + reminder.messageId());
reminders.remove(reminder);
if (reminders.size() == 0)
nextReminder = null;
@@ -74,6 +75,7 @@ public class ReminderScheduler {
}
public synchronized void removeReminder(long messageId) {
Logger.altitudeLogs.debug("Attempting to remove reminder with messageId: " + messageId);
reminders.stream()
.filter(reminder -> reminder.messageId() == messageId)
.findAny()
@@ -88,7 +90,7 @@ public class ReminderScheduler {
while (nextReminder != null && time > nextReminder.remindDate()) {
Channel channel = nextReminder.getChannel(jda);
if (channel == null) {
Logger.warning("Couldn't find channel, unable to run reminder: " + nextReminder.id() +
Logger.altitudeLogs.warning("Couldn't find channel, unable to run reminder: " + nextReminder.id() +
"\ntitle: [" + nextReminder.title() +
"]\ndescription: [" + nextReminder.description() + "]");
return;
@@ -143,9 +145,7 @@ public class ReminderScheduler {
return threadChannel.sendMessageEmbeds(embedBuilder.build());
}
}
default -> {
Logger.warning("Received unexpected channel type " + channel.getType() + " can't send reminder...");
}
default -> Logger.altitudeLogs.warning("Received unexpected channel type " + channel.getType() + " can't send reminder...");
}
return null;
}